1 # Try to find the ns-3 library.
3 # The user can hint a path using the NS3_HINT option.
5 # Once done, the following will be defined:
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)
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
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
19 set(SIMGRID_HAVE_NS3 0)
20 set(NS3_HINT ${ns3_path} CACHE PATH "Path to search for NS3 lib and include")
22 set(NS3_KNOWN_VERSIONS "3.22" "3.23" "3.24" "3.25" "3.26" "3.27" "3.28" "3.29" "3.30" "3.31" "3.32" "3.33" "3.34" "3.35" "3.36" "3.37" "3.38" "3.39" "3.40")
24 foreach (_ns3_ver ${NS3_KNOWN_VERSIONS})
25 list(APPEND _ns3_LIB_SEARCH_DIRS "ns${_ns3_ver}-core" "ns${_ns3_ver}-core-optimized" "ns${_ns3_ver}-core-debug")
26 list(APPEND _ns3_INCLUDE_SEARCH_DIRS "include/ns${_ns3_ver}")
29 find_library(NS3_LIBRARIES
31 ${_ns3_LIB_SEARCH_DIRS}
32 PATH_SUFFIXES lib64 lib ns3/lib
37 find_path(NS3_INCLUDE_DIR
38 NAME ns3/core-module.h
39 PATH_SUFFIXES include ns3/include
40 ${_ns3_INCLUDE_SEARCH_DIRS}
46 message(STATUS "Looking for ns3/core-module.h - found")
48 message(STATUS "Looking for ns3/core-module.h - not found")
50 mark_as_advanced(NS3_INCLUDE_DIR)
52 message(STATUS "Looking for lib ns3-core")
54 message(STATUS "Looking for lib ns3-core - found")
56 message(STATUS "Looking for lib ns3-core - not found")
58 mark_as_advanced(NS3_LIBRARIES)
62 set(SIMGRID_HAVE_NS3 1)
63 if(NS3_LIBRARIES MATCHES "-optimized")
64 set (NS3_SUFFIX "-optimized")
65 elseif(NS3_LIBRARIES MATCHES "-debug")
66 set (NS3_SUFFIX "-debug")
71 string(REGEX REPLACE ".*ns([.0-9]+)-core.*" "\\1" NS3_VERSION "${NS3_LIBRARIES}")
72 string(REGEX REPLACE "3.([.0-9]+)" "\\1" NS3_MINOR_VERSION "${NS3_VERSION}")
73 get_filename_component(NS3_LIBRARY_PATH "${NS3_LIBRARIES}" PATH)
76 string(REGEX REPLACE "(.*)/lib" "\\1" NS3_PATH "${NS3_LIBRARY_PATH}")
78 message(STATUS "ns-3 found (v${NS3_VERSION}; incl:${NS3_INCLUDE_DIR}; lib: ${NS3_LIBRARY_PATH}).")
80 if (NOT NS3_LIBRARY_PATH STREQUAL "/usr/lib")
81 string(REGEX MATCH "${NS3_LIBRARY_PATH}" MatchResult "$ENV{LD_LIBRARY_PATH}")
83 message(STATUS "Warning: NS3 not installed in system path, and not listed in LD_LIBRARY_PATH."
84 " You want to: export LD_LIBRARY_PATH=${NS3_LIBRARY_PATH}\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}")
89 mark_as_advanced(NS3_LIBRARY_PATH)
92 link_directories(${NS3_LIBRARY_PATH})
93 include_directories(${NS3_INCLUDE_DIR})
95 message(STATUS "Warning: Please install ns-3 (version 3.22 or higher -- http://www.nsnam.org/releases/) or disable this feature.")