| 1 |
# - Try to find Gecode |
| 2 |
# Once done this will define |
| 3 |
# GECODE_FOUND - System has Gecode |
| 4 |
# GECODE_INCLUDE_DIRS - The Gecode include directories |
| 5 |
# GECODE_LIBRARIES - The libraries needed to use Gecode |
| 6 |
# GECODE_TARGETS - The names of imported targets created for gecode |
| 7 |
# User can set Gecode_ROOT to the preferred installation prefix |
| 8 |
|
| 9 |
find_path(GECODE_INCLUDE gecode/kernel.hh |
| 10 |
HINTS ${PROJECT_SOURCE_DIR}/vendor/gecode |
| 11 |
PATH_SUFFIXES include) |
| 12 |
|
| 13 |
find_file(GECODE_CONFIG_LOC gecode/support/config.hpp |
| 14 |
HINTS ${GECODE_INCLUDE} ${PROJECT_SOURCE_DIR}/vendor/gecode |
| 15 |
PATH_SUFFIXES include) |
| 16 |
|
| 17 |
if(NOT "${GECODE_CONFIG_LOC}" STREQUAL "GECODE_CONFIG_LOC-NOTFOUND") |
| 18 |
file(READ "${GECODE_CONFIG_LOC}" GECODE_CONFIG) |
| 19 |
string(REGEX MATCH "\#define GECODE_VERSION \"([0-9]+.[0-9]+.[0-9]+)\"" _ "${GECODE_CONFIG}") |
| 20 |
set(GECODE_VERSION "${CMAKE_MATCH_1}") |
| 21 |
string(REGEX MATCH "\#define GECODE_LIBRARY_VERSION \"([0-9]+-[0-9]+-[0-9]+)\"" _ "${GECODE_CONFIG}") |
| 22 |
set(GECODE_LIBRARY_VERSION "${CMAKE_MATCH_1}") |
| 23 |
string(REGEX MATCH "\#define GECODE_STATIC_LIBS ([0-9]+)" _ "${GECODE_CONFIG}") |
| 24 |
set(GECODE_STATIC_LIBS "${CMAKE_MATCH_1}") |
| 25 |
string(REGEX MATCH "\#define GECODE_HAS_GIST" GECODE_HAS_GIST "${GECODE_CONFIG}") |
| 26 |
string(REGEX MATCH "\#define GECODE_HAS_MPFR" GECODE_HAS_MPFR "${GECODE_CONFIG}") |
| 27 |
unset(GECODE_CONFIG) |
| 28 |
endif() |
| 29 |
unset(GECODE_CONFIG_LOC) |
| 30 |
|
| 31 |
set(GECODE_COMPONENTS Driver Flatzinc Float Int Kernel Minimodel Search Set Support) |
| 32 |
if(GECODE_HAS_GIST) |
| 33 |
list(APPEND GECODE_COMPONENTS Gist) |
| 34 |
endif() |
| 35 |
|
| 36 |
foreach(GECODE_COMP ${GECODE_COMPONENTS}) |
| 37 |
# Try to find gecode library |
| 38 |
string(TOLOWER "gecode${GECODE_COMP}" GECODE_LIB) |
| 39 |
set(GECODE_LIB_LOC "GECODE_LIB_LOC-NOTFOUND") |
| 40 |
find_library(GECODE_LIB_LOC NAMES ${GECODE_LIB} lib${GECODE_LIB} ${GECODE_LIB}-${GECODE_LIBRARY_VERSION}-r-x64 ${GECODE_LIB}-${GECODE_LIBRARY_VERSION}-d-x64 |
| 41 |
HINTS ${GECODE_INCLUDE} ${PROJECT_SOURCE_DIR}/vendor/gecode |
| 42 |
PATH_SUFFIXES lib) |
| 43 |
if(NOT "${GECODE_LIB_LOC}" STREQUAL "GECODE_LIB_LOC-NOTFOUND") |
| 44 |
list(APPEND GECODE_LIBRARY ${GECODE_LIB_LOC}) |
| 45 |
add_library(Gecode::${GECODE_COMP} UNKNOWN IMPORTED) |
| 46 |
set_target_properties(Gecode::${GECODE_COMP} PROPERTIES |
| 47 |
IMPORTED_LOCATION ${GECODE_LIB_LOC} |
| 48 |
INTERFACE_INCLUDE_DIRECTORIES ${GECODE_INCLUDE}) |
| 49 |
set(Gecode_FIND_REQUIRED_${GECODE_COMP} TRUE) |
| 50 |
set(Gecode_${GECODE_COMP}_FOUND TRUE) |
| 51 |
endif() |
| 52 |
endforeach(GECODE_COMP) |
| 53 |
|
| 54 |
if(GECODE_HAS_MPFR) |
| 55 |
find_package(MPFR) |
| 56 |
set_target_properties(Gecode::Float PROPERTIES |
| 57 |
INTERFACE_LINK_LIBRARIES ${MPFR_LIBRARIES}) |
| 58 |
list(APPEND GECODE_LIBRARY ${MPFR_LIBRARIES}) |
| 59 |
list(APPEND GECODE_TARGETS ${MPFR_LIBRARIES}) |
| 60 |
endif() |
| 61 |
|
| 62 |
if(WIN32 AND GECODE_HAS_GIST AND GECODE_STATIC_LIBS) |
| 63 |
find_package(Qt5 QUIET COMPONENTS Core Gui Widgets PrintSupport) |
| 64 |
set_target_properties(Gecode::Gist PROPERTIES |
| 65 |
INTERFACE_LINK_LIBRARIES "Qt5::Core;Qt5::Gui;Qt5::Widgets;Qt5::PrintSupport") |
| 66 |
endif() |
| 67 |
|
| 68 |
unset(GECODE_LIB_LOC) |
| 69 |
|
| 70 |
include(FindPackageHandleStandardArgs) |
| 71 |
# handle the QUIETLY and REQUIRED arguments and set GECODE_FOUND to TRUE |
| 72 |
# if all listed variables are TRUE |
| 73 |
find_package_handle_standard_args( |
| 74 |
Gecode |
| 75 |
REQUIRED_VARS GECODE_INCLUDE GECODE_LIBRARY |
| 76 |
VERSION_VAR GECODE_VERSION |
| 77 |
HANDLE_COMPONENTS |
| 78 |
FAIL_MESSAGE "Could NOT find Gecode, use Gecode_ROOT to hint its location" |
| 79 |
) |
| 80 |
|
| 81 |
mark_as_advanced(GECODE_INCLUDE GECODE_LIBRARY) |
| 82 |
|
| 83 |
set(GECODE_LIBRARIES ${GECODE_LIBRARY}) |
| 84 |
set(GECODE_INCLUDE_DIRS ${GECODE_INCLUDE}) |