Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
attempt of a function searching all zones of a given type
[simgrid.git] / FindSimGrid.cmake
index a5d247f..8a79cdf 100644 (file)
@@ -1,77 +1,60 @@
-#IF YOU HAVE INSTALL SIMGRID LIBRARIES AND SIMGRID BINARIES IN A SPECIAL DIRECTORY
-#YOU CAN SPECIFY SIMGRID_LIBRARY_PAT AND SIMGRID_BIN_PATH OR SIMPLY LD_LIBRARY_PATH
-
-# TO CALL THIS FILE USE
-       #set(CMAKE_MODULE_PATH 
-       #${CMAKE_MODULE_PATH}
-       #${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Modules
-       #)
-
-message("SIMGRID_LIBRARY_PATH  = $ENV{SIMGRID_LIBRARY_PATH}")
-message("SIMGRID_BIN_PATH      = $ENV{SIMGRID_BIN_PATH}")
-message("LD_LIBRARY_PATH       = $ENV{LD_LIBRARY_PATH}")
-
-find_library(HAVE_SIMGRID_LIB
-    NAME simgrid
-    HINTS
-    $ENV{LIBRARIES}
-    $ENV{LD_LIBRARY_PATH}
-    $ENV{SIMGRID_LIBRARY_PATH}
-    PATH_SUFFIXES lib64 lib simgrid/lib64 simgrid/lib
-    PATHS
-    /opt
-    /opt/local
-    /opt/csw
-    /sw
-    /usr
+# Cmake macro to search for the SimGrid library. 
+
+# Copyright (c) 2016. The SimGrid Team (version 20161210).
+#
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the license (GNU LGPL) which comes with this package.
+
+# The user can hint a path using the SimGrid_PATH option.
+#
+# Once done, the following will be defined:
+#  
+#  SimGrid_INCLUDE_DIR - the SimGrid include directories
+#  SimGrid_LIBRARY - link your simulator against it to use SimGrid
+#
+# Afterward, you should probably do the following:
+#
+#  include_directories("${SimGrid_INCLUDE_DIR}" SYSTEM)
+#  target_link_libraries(your-simulator ${SimGrid_LIBRARY})
+#
+# This could be improved in many ways (patches welcome):
+#  - Not finding SimGrid is fatal. But who would want to 
+#    overcome such a desperate situation anyway? ;)
+#  - No way to specify a minimal version
+#  - No proper find_package() integration
+
+set(SimGrid_PATH ${SimGrid_PATH} CACHE PATH "Path to SimGrid library and include")
+find_path(SimGrid_INCLUDE_DIR
+  NAMES simgrid_config.h
+  HINTS ${SimGrid_PATH}/include /usr/include /usr/local/include /opt/simgrid/include
 )
-
-find_path(HAVE_GRAS_H gras.h
-    HINTS
-    $ENV{INCLUDES}
-    $ENV{LD_LIBRARY_PATH}
-    $ENV{SIMGRID_LIBRARY_PATH}
-    PATH_SUFFIXES include simgrid/include
-    PATHS
-    /opt
-    /opt/local
-    /opt/csw
-    /sw
-    /usr
+find_library(SimGrid_LIBRARY
+  NAMES simgrid
+  HINTS ${SimGrid_PATH}/lib /usr/lib /usr/local/lib /opt/simgrid/lib
 )
+mark_as_advanced(SimGrid_INCLUDE_DIR)
+mark_as_advanced(SimGrid_LIBRARY)
 
-string(REPLACE "/include" "/bin" OPTIONAL_BIN_PATH "HAVE_GRAS_H")
+if (NOT EXISTS "${SimGrid_INCLUDE_DIR}")
+  message(FATAL_ERROR "Unable to find SimGrid header file. Please point the SimGrid_PATH variable to the installation directory.")
+endif ()
+if (NOT EXISTS "${SimGrid_LIBRARY}")
+  message(FATAL_ERROR "Unable to find SimGrid library. Please point the SimGrid_PATH variable to the installation directory.")
+endif ()
 
-find_program(HAVE_TESH
-NAMES tesh
-HINTS
-$ENV{SIMGRID_BIN_PATH}
-$ENV{LD_LIBRARY_PATH}
-PATH_SUFFIXES bin simgrid/bin
-PATHS
-${OPTIONAL_BIN_PATH}
-/opt
-/opt/local
-/opt/csw
-/sw
-/usr
-)
+# Extract the actual path
+if (NOT "$SimGrid_INCLUDE_DIR" STREQUAL "${SimGrid_PATH}/include")
+      string(REGEX REPLACE "(.*)/include" "\\1" SimGrid_PATH "${SimGrid_INCLUDE_DIR}")
+endif()
+
+# Extract the actual version number
+file(READ "${SimGrid_INCLUDE_DIR}/simgrid_config.h" _SimGrid_CONFIG_H_CONTENTS)
+set(_SimGrid_VERSION_REGEX ".*#define SIMGRID_VERSION_STRING \"SimGrid version ([^\"]*)\".*")
+if ("${_SimGrid_CONFIG_H_CONTENTS}" MATCHES "${_SimGrid_VERSION_REGEX}")
+      string(REGEX REPLACE "${_SimGrid_VERSION_REGEX}" "\\1" SimGrid_VERSION "${_SimGrid_CONFIG_H_CONTENTS}")
+endif ("${_SimGrid_CONFIG_H_CONTENTS}" MATCHES "${_SimGrid_VERSION_REGEX}")
+  
+
+message(STATUS "SimGrid found in ${SimGrid_PATH} (version ${SimGrid_VERSION})")
 
-find_program(HAVE_GRAS_STUB
-NAMES gras_stub_generator
-HINTS
-$ENV{SIMGRID_BIN_PATH}
-$ENV{LD_LIBRARY_PATH}
-PATH_SUFFIXES bin simgrid/bin
-PATHS
-/opt
-/opt/local
-/opt/csw
-/sw
-/usr
-)
 
-message("HAVE_SIMGRID_LIB      = ${HAVE_SIMGRID_LIB}")
-message("HAVE_GRAS_H           = ${HAVE_GRAS_H}")
-message("HAVE_TESH             = ${HAVE_TESH}")
-message("HAVE_GRAS_STUB                = ${HAVE_GRAS_STUB}")
\ No newline at end of file