Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Channel: the S4U name of msg_mailbox_t
[simgrid.git] / buildtools / Cmake / Modules / FindGTnets.cmake
1 find_library(HAVE_GTNETS_LIB
2   NAME gtsim
3   PATHS ${gtnets_path} ${gtnets_path}/lib
4   )
5   
6 if (HAVE_GTNETS_LIB)
7   message(STATUS "Looking for GTNetS library - found")
8 else()
9   message(STATUS "Looking for GTNetS library - no found (search path: ${gtnets_path})")
10   message(STATUS "  library file name must be libgtsim.so (not gtnets.so, not libgtsim-opt.so)")
11 endif()
12
13 find_path(HAVE_SIMULATOR_H
14   NAME simulator.h
15   PATH_SUFFIXES include include/gtnets
16   PATHS
17   ${gtnets_path}
18   )
19 if (HAVE_GTNETS_LIB)
20   message(STATUS "Looking for GTNetS header simulator.h - found")
21 else()
22   message(STATUS "Looking for GTNetS header simulator.h - no found")
23 endif()
24
25 string(REPLACE "/libgtnets.${LIB_EXE}" ""  GTNETS_LIB_PATH "${HAVE_GTNETS_LIB}")
26
27 if(HAVE_GTNETS_LIB AND HAVE_SIMULATOR_H)
28
29   execute_process(COMMAND ${CMAKE_CXX_COMPILER} -I${HAVE_SIMULATOR_H} -lgtsim -L${GTNETS_LIB_PATH} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_gtnets.cpp
30     OUTPUT_VARIABLE COMPILE_GTNETS_VAR)
31   if(COMPILE_GTNETS_VAR)
32     SET(HAVE_GTNETS 0)
33   else()
34     SET(HAVE_GTNETS 1)
35
36     string(REGEX MATCH "-L${GTNETS_LIB_PATH} " operation "${CMAKE_C_FLAGS}")
37     if(NOT operation)
38       SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-L${GTNETS_LIB_PATH} ")
39     endif()
40
41     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_SIMULATOR_H} -L${GTNETS_LIB_PATH} ")
42
43     string(REGEX MATCH "${GTNETS_LIB_PATH}" operation "$ENV{LD_LIBRARY_PATH}")
44     if(NOT operation)
45       message(FATAL_ERROR "\nGTNetS library found but unusable. Did you set LD_LIBRARY_PATH?\n\texport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${GTNETS_LIB_PATH}\n\n")
46     endif()
47
48   endif()
49
50 else()
51   if(NOT HAVE_GTNETS_LIB)
52     message(STATUS "Gtnets is enabled but can't find it.")
53   endif()
54   if(NOT HAVE_SIMULATOR_H)
55     message(STATUS "Gtnets needs simulator.h")
56   endif()
57 endif()
58
59 message(STATUS "Looking for lib gtnets patch")
60 if(HAVE_GTNETS)
61   message(STATUS "Looking for lib gtnets patch - found")
62 else()
63   message(STATUS "Looking for lib gtnets patch - not found")
64 endif()
65
66 mark_as_advanced(HAVE_GTNETS_LIB)
67 mark_as_advanced(HAVE_SIMULATOR_H)