Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2fc3f7688bed82c30e672379b0805e030404372e
[simgrid.git] / tools / 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 ## ADDING A NS3 VERSION.
16 #   - Add ns3.${version}-core 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(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 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 ns3.25-core ns3.26-core ns3.26-core-optimized ns3.26-core-debug ns3.27-core ns3.27-core-optimized ns3.27-core-debug ns3.28-core ns3.28-core-optimized ns3.28-core-debug
24   PATH_SUFFIXES lib64 lib ns3/lib
25   PATHS
26   ${NS3_HINT}
27   )
28
29 find_path(NS3_INCLUDE_DIR
30   NAME ns3/core-module.h
31   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 include/ns3.25 include/ns3.26 include/ns3.27 include/ns3.28
32   PATHS
33   ${NS3_HINT}
34   )
35
36 if(NS3_INCLUDE_DIR)
37   message(STATUS "Looking for ns3/core-module.h - found")
38 else()
39   message(STATUS "Looking for ns3/core-module.h - not found")
40 endif()
41 mark_as_advanced(NS3_INCLUDE_DIR)
42
43 message(STATUS "Looking for lib ns3-core")
44 if(NS3_LIBRARIES)
45   message(STATUS "Looking for lib ns3-core - found")
46 else()
47   message(STATUS "Looking for lib ns3-core - not found")
48 endif()
49 mark_as_advanced(NS3_LIBRARIES)
50
51 if(NS3_INCLUDE_DIR)
52   if(NS3_LIBRARIES)
53     set(HAVE_NS3 1)
54     if(NS3_LIBRARIES MATCHES "-optimized")
55       set (NS3_SUFFIX "-optimized")
56     elseif(NS3_LIBRARIES MATCHES "-debug")
57       set (NS3_SUFFIX "-debug")
58     else()
59       set (NS3_SUFFIX "")
60     endif()
61
62     string(REGEX REPLACE ".*ns([.0-9]+)-core.*" "\\1" NS3_VERSION "${NS3_LIBRARIES}")
63     get_filename_component(NS3_LIBRARY_PATH "${NS3_LIBRARIES}" PATH)
64
65     # Compute NS3_PATH
66     string(REGEX REPLACE "(.*)/lib" "\\1" NS3_PATH "${NS3_LIBRARY_PATH}")
67     
68     message(STATUS "NS-3 found (v3.${NS3_VERSION} in ${NS3_PATH}).")
69
70     if (NOT NS3_LIBRARY_PATH STREQUAL "/usr/lib") 
71       string(REGEX MATCH "${NS3_LIBRARY_PATH}" MatchResult "$ENV{LD_LIBRARY_PATH}")
72       if(NOT MatchResult)
73         message(STATUS "Warning: NS3 not installed in system path, and not listed in LD_LIBRARY_PATH." 
74                        "         You want to: export LD_LIBRARY_PATH=${NS3_LIBRARY_PATH}\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}")
75       endif()
76     endif()
77   endif()
78 endif()
79 mark_as_advanced(NS3_LIBRARY_PATH)
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()