Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't search for RngStream.h but specific file simulator.h
[simgrid.git] / buildtools / Cmake / Modules / FindGTnets.cmake
index 9bb9e48..44eb7a8 100644 (file)
@@ -1,20 +1,24 @@
-find_path(HAVE_RNGSTREAM_H RngStream.h
+find_library(HAVE_GTNETS_LIB
+    NAME gtnets
     HINTS
     $ENV{LD_LIBRARY_PATH}
-    PATH_SUFFIXES include include/gtnets
+    $ENV{HOME}
+    PATH_SUFFIXES lib64 lib lib64/gtnets lib/gtnets
     PATHS
     /opt
     /opt/local
     /opt/csw
     /sw
     /usr
+    ${gtnets_path}
 )
 
-find_library(HAVE_GTNETS_LIB
-    NAME gtnets
+find_path(HAVE_SIMULATOR_H
+       NAME simulator.h
     HINTS
-    $ENV{LD_LIBRARY_PATH}
-    PATH_SUFFIXES lib64 lib lib64/gtnets lib/gtnets
+    $ENV{HOME}
+    $ENV{GTNETS_ROOT}
+    PATH_SUFFIXES include include/gtnets
     PATHS
     /opt
     /opt/local
@@ -25,35 +29,44 @@ find_library(HAVE_GTNETS_LIB
 
 string(REPLACE "/libgtnets.${LIB_EXE}" ""  GTNETS_LIB_PATH "${HAVE_GTNETS_LIB}")
 
-exec_program("${CMAKE_CXX_COMPILER} -I${HAVE_RNGSTREAM_H} -lgtnets -L${GTNETS_LIB_PATH} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_gtnets.cpp " OUTPUT_VARIABLE COMPILE_GTNETS_VAR)       
-if(COMPILE_GTNETS_VAR)
-       SET(HAVE_GTNETS 0)
-else(COMPILE_GTNETS_VAR)
-       SET(HAVE_GTNETS 1)
-endif(COMPILE_GTNETS_VAR)
+if(HAVE_GTNETS_LIB AND HAVE_SIMULATOR_H)
 
+       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
+                                       OUTPUT_VARIABLE COMPILE_GTNETS_VAR)     
+       if(COMPILE_GTNETS_VAR)
+               SET(HAVE_GTNETS 0)
+       else(COMPILE_GTNETS_VAR)
+               SET(HAVE_GTNETS 1)      
+               
+               string(REGEX MATCH "-L${GTNETS_LIB_PATH} " operation "${CMAKE_C_FLAGS}")
+               if(NOT operation)
+                       SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-L${GTNETS_LIB_PATH} ")
+               endif(NOT operation)
+               
+               SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_SIMULATOR_H} -L${GTNETS_LIB_PATH} ")
+               
+               string(REGEX MATCH "${GTNETS_LIB_PATH}" operation "$ENV{LD_LIBRARY_PATH}")
+               if(NOT operation)
+                       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")
+               endif(NOT operation)
+               
+       endif(COMPILE_GTNETS_VAR)
 
-message(STATUS "Looking for RngStream.h")
-if(HAVE_RNGSTREAM_H)
-message(STATUS "Looking for RngStream.h - found")
-else(HAVE_RNGSTREAM_H)
-message(STATUS "Looking for RngStream.h - not found")
-endif(HAVE_RNGSTREAM_H)
+else(HAVE_GTNETS_LIB AND HAVE_SIMULATOR_H)
+       if(NOT HAVE_GTNETS_LIB)
+       message(STATUS "Gtnets is enabled but can't find it.")
+       endif(NOT HAVE_GTNETS_LIB)
+       if(NOT HAVE_SIMULATOR_H)
+       message(STATUS "Gtnets needs simulator.h")
+       endif(NOT HAVE_SIMULATOR_H)
+endif(HAVE_GTNETS_LIB AND HAVE_SIMULATOR_H)
 
 message(STATUS "Looking for lib gtnets patch")
-if(HAVE_GTNETS_LIB AND HAVE_GTNETS)
+if(HAVE_GTNETS)
 message(STATUS "Looking for lib gtnets patch - found")
-else(HAVE_GTNETS_LIB AND HAVE_GTNETS)
+else(HAVE_GTNETS)
 message(STATUS "Looking for lib gtnets patch - not found")
-endif(HAVE_GTNETS_LIB AND HAVE_GTNETS)
-
-#TODO NEED TO TEST IF PATHS ARE ALREADY SET BY CMAKE
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${HAVE_RNGSTREAM_H} -L${GTNETS_LIB_PATH} ")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_RNGSTREAM_H} -L${GTNETS_LIB_PATH} ")
-string(REGEX MATCH "${GTNETS_LIB_PATH}" operation "$ENV{LD_LIBRARY_PATH}")
-if(NOT operation)
-       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")
-endif(NOT operation)
+endif(HAVE_GTNETS)
 
 mark_as_advanced(HAVE_GTNETS_LIB)
-mark_as_advanced(HAVE_RNGSTREAM_H)
\ No newline at end of file
+mark_as_advanced(HAVE_SIMULATOR_H)
\ No newline at end of file