Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add FindNS3 module to cmake.
[simgrid.git] / buildtools / Cmake / Modules / FindGTnets.cmake
1 find_library(HAVE_GTNETS_LIB
2     NAME gtnets
3     HINTS
4     $ENV{LD_LIBRARY_PATH}
5     $ENV{HOME}
6     PATH_SUFFIXES lib64 lib lib64/gtnets lib/gtnets
7     PATHS
8     /opt
9     /opt/local
10     /opt/csw
11     /sw
12     /usr
13     ${gtnets_path}
14 )
15
16 find_path(HAVE_SIMULATOR_H
17         NAME simulator.h
18     HINTS
19     $ENV{HOME}
20     $ENV{GTNETS_ROOT}
21     PATH_SUFFIXES include include/gtnets
22     PATHS
23     /opt
24     /opt/local
25     /opt/csw
26     /sw
27     /usr
28     ${gtnets_path}
29 )
30
31 string(REPLACE "/libgtnets.${LIB_EXE}" ""  GTNETS_LIB_PATH "${HAVE_GTNETS_LIB}")
32
33 if(HAVE_GTNETS_LIB AND HAVE_SIMULATOR_H)
34
35         execute_process(COMMAND ${CMAKE_CXX_COMPILER} -I${HAVE_SIMULATOR_H} -lgtnets -L${GTNETS_LIB_PATH} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_gtnets.cpp
36                                         OUTPUT_VARIABLE COMPILE_GTNETS_VAR)     
37         if(COMPILE_GTNETS_VAR)
38                 SET(HAVE_GTNETS 0)
39         else(COMPILE_GTNETS_VAR)
40                 SET(HAVE_GTNETS 1)      
41                 
42                 string(REGEX MATCH "-L${GTNETS_LIB_PATH} " operation "${CMAKE_C_FLAGS}")
43                 if(NOT operation)
44                         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-L${GTNETS_LIB_PATH} ")
45                 endif(NOT operation)
46                 
47                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_SIMULATOR_H} -L${GTNETS_LIB_PATH} ")
48                 
49                 string(REGEX MATCH "${GTNETS_LIB_PATH}" operation "$ENV{LD_LIBRARY_PATH}")
50                 if(NOT operation)
51                         message(FATAL_ERROR "\n\nTo use GTNETS don't forget to set LD_LIBRARY_PATH with \n\texport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${GTNETS_LIB_PATH}\n\n")
52                 endif(NOT operation)
53                 
54         endif(COMPILE_GTNETS_VAR)
55
56 else(HAVE_GTNETS_LIB AND HAVE_SIMULATOR_H)
57         if(NOT HAVE_GTNETS_LIB)
58         message(STATUS "Gtnets is enabled but can't find it.")
59         endif(NOT HAVE_GTNETS_LIB)
60         if(NOT HAVE_SIMULATOR_H)
61         message(STATUS "Gtnets needs simulator.h")
62         endif(NOT HAVE_SIMULATOR_H)
63 endif(HAVE_GTNETS_LIB AND HAVE_SIMULATOR_H)
64
65 message(STATUS "Looking for lib gtnets patch")
66 if(HAVE_GTNETS)
67 message(STATUS "Looking for lib gtnets patch - found")
68 else(HAVE_GTNETS)
69 message(STATUS "Looking for lib gtnets patch - not found")
70 endif(HAVE_GTNETS)
71
72 mark_as_advanced(HAVE_GTNETS_LIB)
73 mark_as_advanced(HAVE_SIMULATOR_H)