1 # Cmake macro to search for the SimGrid library.
3 # Copyright (c) 2016. The SimGrid Team (version 20161210).
5 # This file is free software; you can redistribute it and/or modify it
6 # under the terms of the license (GNU LGPL) which comes with this package.
8 # The user can hint a path using the SimGrid_PATH option.
10 # Once done, the following will be defined:
12 # SimGrid_INCLUDE_DIR - the SimGrid include directories
13 # SimGrid_LIBRARY - link your simulator against it to use SimGrid
15 # Afterward, you should probably do the following:
17 # include_directories("${SimGrid_INCLUDE_DIR}" SYSTEM)
18 # target_link_libraries(your-simulator ${SimGrid_LIBRARY})
20 # This could be improved in many ways (patches welcome):
21 # - Not finding SimGrid is fatal. But who would want to
22 # overcome such a desperate situation anyway? ;)
23 # - No way to specify a minimal version
24 # - No proper find_package() integration
26 set(SimGrid_PATH ${SimGrid_PATH} CACHE PATH "Path to SimGrid library and include")
27 find_path(SimGrid_INCLUDE_DIR
28 NAMES simgrid_config.h
29 HINTS ${SimGrid_PATH}/include /usr/include /usr/local/include /opt/simgrid/include
31 find_library(SimGrid_LIBRARY
33 HINTS ${SimGrid_PATH}/lib /usr/lib /usr/local/lib /opt/simgrid/lib
35 mark_as_advanced(SimGrid_INCLUDE_DIR)
36 mark_as_advanced(SimGrid_LIBRARY)
38 if (NOT EXISTS "${SimGrid_INCLUDE_DIR}")
39 message(FATAL_ERROR "Unable to find SimGrid header file. Please point the SimGrid_PATH variable to the installation directory.")
41 if (NOT EXISTS "${SimGrid_LIBRARY}")
42 message(FATAL_ERROR "Unable to find SimGrid library. Please point the SimGrid_PATH variable to the installation directory.")
45 # Extract the actual path
46 if (NOT "$SimGrid_INCLUDE_DIR" STREQUAL "${SimGrid_PATH}/include")
47 string(REGEX REPLACE "(.*)/include" "\\1" SimGrid_PATH "${SimGrid_INCLUDE_DIR}")
50 # Extract the actual version number
51 file(READ "${SimGrid_INCLUDE_DIR}/simgrid_config.h" _SimGrid_CONFIG_H_CONTENTS)
52 set(_SimGrid_VERSION_REGEX ".*#define SIMGRID_VERSION_STRING \"SimGrid version ([^\"]*)\".*")
53 if ("${_SimGrid_CONFIG_H_CONTENTS}" MATCHES "${_SimGrid_VERSION_REGEX}")
54 string(REGEX REPLACE "${_SimGrid_VERSION_REGEX}" "\\1" SimGrid_VERSION "${_SimGrid_CONFIG_H_CONTENTS}")
55 endif ("${_SimGrid_CONFIG_H_CONTENTS}" MATCHES "${_SimGrid_VERSION_REGEX}")
58 message("-- SimGrid found in ${SimGrid_PATH} (version ${SimGrid_VERSION})")