Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
91adb367fbf8e5a82cdbb8d3a6f93dcf764b3a60
[simgrid.git] / buildtools / Cmake / Modules / FindNS3.cmake
1 # Try to find the NS3 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 NS3 include directories
8 #  NS3_LIBRARY_PATH - path to the libs
9 #  NS3_LIBRARIES - link these to use NS3 (full path to libs)
10 #
11 # This could be improved in many ways (patches welcome):
12 #  - No way to specify a minimal version (v3.10 is hardcoded).
13 #  - No proper find_package() integration
14
15
16 ## ADDING A NS3 VERSION.
17 #   - Add ns3.${version}-core to the NAME line of the find_library below
18 #   - Add include/ns3{version} to the PATH_SUFFIXES line of the find_path below
19
20 set(HAVE_NS3 0)
21 set(NS3_HINT ${ns3_path} CACHE PATH "Path to search for NS3 lib and include")
22
23 find_library(NS3_LIBRARIES
24   NAME ns3-core ns3.14-core ns3.15-core ns3.16-core ns3.17-core ns3.18-core ns3.19-core ns3.20-core ns3.21-core ns3.22-core
25   PATH_SUFFIXES lib64 lib ns3/lib
26   PATHS
27   ${NS3_HINT}
28   )
29
30 find_path(NS3_INCLUDE_DIR
31   NAME ns3/core-module.h
32   PATH_SUFFIXES include ns3/include include/ns3.14 include/ns3.15 include/ns3.16 include/ns3.17 include/ns3.18 include/ns3.19 include/ns3.20 include/ns3.21 include/ns3.22
33   PATHS
34   ${NS3_HINT}
35   )
36
37
38
39 if(NS3_INCLUDE_DIR)
40   message(STATUS "Looking for ns3/core-module.h - found")
41 else()
42   message(STATUS "Looking for ns3/core-module.h - not found")
43 endif()
44 mark_as_advanced(NS3_INCLUDE_DIR)
45
46 message(STATUS "Looking for lib ns3-core")
47 if(NS3_LIBRARIES)
48   message(STATUS "Looking for lib ns3-core - found")
49 else()
50   message(STATUS "Looking for lib ns3-core - not found")
51 endif()
52 mark_as_advanced(NS3_LIBRARIES)
53
54
55 if(NS3_INCLUDE_DIR)
56   if(NS3_LIBRARIES)
57     set(HAVE_NS3 1)
58     
59     string(REGEX REPLACE ".*ns([.0-9]+)-core.*" "\\1" NS3_VERSION "${NS3_LIBRARIES}")
60     get_filename_component(NS3_LIBRARY_PATH "${NS3_LIBRARIES}" PATH)
61
62     # Compute NS3_PATH
63     string(REGEX REPLACE "(.*)/lib" "\\1" NS3_PATH "${NS3_LIBRARY_PATH}")
64     
65     message(STATUS "NS-3 found (v3.${NS3_VERSION} in ${NS3_PATH}).")
66
67     if (NOT NS3_LIBRARY_PATH STREQUAL "/usr/lib") 
68       string(REGEX MATCH "${NS3_LIBRARY_PATH}" MatchResult "$ENV{LD_LIBRARY_PATH}")
69       if(NOT MatchResult)
70         message(STATUS "Warning: NS3 not installed in system path, and not listed in LD_LIBRARY_PATH." 
71                        "         You want to: export LD_LIBRARY_PATH=${NS3_LIBRARY_PATH}\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}")
72       endif()
73     endif()
74   endif()
75 endif()
76 mark_as_advanced(NS3_LIBRARY_PATH)
77
78 message("NS3_VERSION: ${NS3_VERSION}")
79 message("NS3_LIBRARIES: ${NS3_LIBRARIES}")
80
81 if(HAVE_NS3)
82   link_directories(${NS3_LIBRARY_PATH})
83   include_directories(${NS3_INCLUDE_DIR})
84 else()
85   message(STATUS "Warning: To use NS-3 Please install ns3 at least version 3.10 (http://www.nsnam.org/releases/)")
86 endif()