Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
71d1b32d08fbcee662b87b2d2ebbddf3ab041741
[simgrid.git] / tools / cmake / Modules / FindNS3.cmake
1 # Try to find the ns-3 library.
2 #
3 # The user can hint a path using the NS3_HINT option.
4 #
5 # Once done, the following will be defined:
6 #
7 #  NS3_INCLUDE_DIRS - the ns-3 include directories
8 #  NS3_LIBRARY_PATH - path to the libs
9 #  NS3_LIBRARIES - link these to use ns-3 (full path to libs)
10 #
11 # This could be improved in many ways (patches welcome):
12 #  - No way to specify a minimal version (v3.26 is hardcoded).
13 #  - No proper find_package() integration
14
15 ## ADDING A ns-3 VERSION.
16 #   - Add "ns3.${version}-core ns3.${version}-core-debug ns3.${version}-core-optimized" to the NAME line of the find_library below
17 #   - Add "include/ns3{version}" to the PATH_SUFFIXES line of the find_path below
18
19 set(SIMGRID_HAVE_NS3 0)
20 set(NS3_HINT ${ns3_path} CACHE PATH "Path to search for NS3 lib and include")
21
22 find_library(NS3_LIBRARIES
23   NAME ns3-core
24        ns3.22-core ns3.22-core-optimized ns3.22-core-debug
25        ns3.23-core ns3.23-core-optimized ns3.23-core-debug
26        ns3.24-core ns3.24-core-optimized ns3.24-core-debug
27        ns3.25-core ns3.25-core-optimized ns3.25-core-debug
28        ns3.26-core ns3.26-core-optimized ns3.26-core-debug
29        ns3.27-core ns3.27-core-optimized ns3.27-core-debug
30        ns3.28-core ns3.28-core-optimized ns3.28-core-debug
31        ns3.29-core ns3.29-core-optimized ns3.29-core-debug
32        ns3.30-core ns3.30-core-optimized ns3.30-core-debug
33        ns3.31-core ns3.31-core-optimized ns3.31-core-debug
34        ns3.32-core ns3.32-core-optimized ns3.32-core-debug
35        ns3.33-core ns3.33-core-optimized ns3.33-core-debug
36        ns3.34-core ns3.34-core-optimized ns3.34-core-debug
37        ns3.35-core ns3.35-core-optimized ns3.35-core-debug
38        ns3.36-core ns3.36-core-optimized ns3.36-core-debug
39        ns3.37-core ns3.37-core-optimized ns3.37-core-debug
40        ns3.38-core ns3.38-core-optimized ns3.38-core-debug
41        ns3.39-core ns3.39-core-optimized ns3.39-core-debug
42        ns3.40-core ns3.40-core-optimized ns3.40-core-debug
43   PATH_SUFFIXES lib64 lib ns3/lib
44   PATHS
45   ${NS3_HINT}
46   )
47
48 find_path(NS3_INCLUDE_DIR
49   NAME ns3/core-module.h
50   PATH_SUFFIXES include ns3/include
51                 include/ns3.22 include/ns3.23 include/ns3.24 include/ns3.25 include/ns3.26 include/ns3.27 include/ns3.28 include/ns3.29 include/ns3.30
52                 include/ns3.31 include/ns3.32 include/ns3.33 include/ns3.34 include/ns3.35 include/ns3.36 include/ns3.37 include/ns3.38 include/ns3.39 include/ns3.40
53   PATHS
54   ${NS3_HINT}
55   )
56
57 if(NS3_INCLUDE_DIR)
58   message(STATUS "Looking for ns3/core-module.h - found")
59 else()
60   message(STATUS "Looking for ns3/core-module.h - not found")
61 endif()
62 mark_as_advanced(NS3_INCLUDE_DIR)
63
64 message(STATUS "Looking for lib ns3-core")
65 if(NS3_LIBRARIES)
66   message(STATUS "Looking for lib ns3-core - found")
67 else()
68   message(STATUS "Looking for lib ns3-core - not found")
69 endif()
70 mark_as_advanced(NS3_LIBRARIES)
71
72 if(NS3_INCLUDE_DIR)
73   if(NS3_LIBRARIES)
74     set(SIMGRID_HAVE_NS3 1)
75     if(NS3_LIBRARIES MATCHES "-optimized")
76       set (NS3_SUFFIX "-optimized")
77     elseif(NS3_LIBRARIES MATCHES "-debug")
78       set (NS3_SUFFIX "-debug")
79     else()
80       set (NS3_SUFFIX "")
81     endif()
82
83     string(REGEX REPLACE ".*ns([.0-9]+)-core.*" "\\1" NS3_VERSION "${NS3_LIBRARIES}")
84     string(REGEX REPLACE "3.([.0-9]+)" "\\1" NS3_MINOR_VERSION "${NS3_VERSION}")
85     get_filename_component(NS3_LIBRARY_PATH "${NS3_LIBRARIES}" PATH)
86
87     # Compute NS3_PATH
88     string(REGEX REPLACE "(.*)/lib" "\\1" NS3_PATH "${NS3_LIBRARY_PATH}")
89
90     message(STATUS "ns-3 found (v${NS3_VERSION}; incl:${NS3_INCLUDE_DIR}; lib: ${NS3_LIBRARY_PATH}).")
91
92     if (NOT NS3_LIBRARY_PATH STREQUAL "/usr/lib")
93       string(REGEX MATCH "${NS3_LIBRARY_PATH}" MatchResult "$ENV{LD_LIBRARY_PATH}")
94       if(NOT MatchResult)
95         message(STATUS "Warning: NS3 not installed in system path, and not listed in LD_LIBRARY_PATH."
96                        "         You want to: export LD_LIBRARY_PATH=${NS3_LIBRARY_PATH}\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}")
97       endif()
98     endif()
99   endif()
100 endif()
101 mark_as_advanced(NS3_LIBRARY_PATH)
102
103 if(SIMGRID_HAVE_NS3)
104   link_directories(${NS3_LIBRARY_PATH})
105   include_directories(${NS3_INCLUDE_DIR})
106 else()
107   message(STATUS "Warning: Please install ns-3 (version 3.22 or higher -- http://www.nsnam.org/releases/) or disable this feature.")
108 endif()