| 1 |
# - Try to find CBC |
| 2 |
# Once done this will define |
| 3 |
# OSICBC_FOUND - System has CBC |
| 4 |
# OSICBC_INCLUDE_DIRS - The CBC include directories |
| 5 |
# OSICBC_LIBRARIES - The libraries needed to use CBC |
| 6 |
# GOSICBC_TARGETS - The names of imported targets created for CBC |
| 7 |
# User can set OsiCBC_ROOT to the preferred installation prefix |
| 8 |
|
| 9 |
set(OSICBC_FIND_FILES coin/CbcSolver.hpp coin/CglPreProcess.hpp coin/ClpConfig.h coin/CoinSignal.hpp coin/OsiClpSolverInterface.hpp coin/OsiSolverInterface.hpp) |
| 10 |
|
| 11 |
foreach(OSICBC_FILE ${OSICBC_FIND_FILES}) |
| 12 |
set(OSICBC_FILE_LOC "OSICBC_LIB_LOC-NOTFOUND") |
| 13 |
find_path(OSICBC_FILE_LOC ${OSICBC_FILE} |
| 14 |
HINTS ${PROJECT_SOURCE_DIR}/vendor/cbc |
| 15 |
PATH_SUFFIXES cbc cgl clp coinutils osi include) |
| 16 |
if("${OSICBC_FILE_LOC}" STREQUAL "OSICBC_FILE_LOC-NOTFOUND") |
| 17 |
# message(STATUS "OsiCBC: Could not find file `${OSICBC_FILE}`") |
| 18 |
set(OSICBC_INCLUDE "") |
| 19 |
break() |
| 20 |
endif() |
| 21 |
list(APPEND OSICBC_INCLUDE ${OSICBC_FILE_LOC}) |
| 22 |
# Add "/coin" for CBC internal dependencies |
| 23 |
list(APPEND OSICBC_INCLUDE ${OSICBC_FILE_LOC}/coin) |
| 24 |
endforeach(OSICBC_FILE) |
| 25 |
|
| 26 |
list(REMOVE_DUPLICATES OSICBC_INCLUDE) |
| 27 |
unset(OSICBC_FIND_FILES) |
| 28 |
unset(OSICBC_FILE_LOC) |
| 29 |
|
| 30 |
find_file(CBC_CONFIG_LOC NAMES coin/config_cbc_default.h coin/CbcConfig.h |
| 31 |
HINTS ${OSICBC_INCLUDE} ${PROJECT_SOURCE_DIR}/vendor/cbc |
| 32 |
PATH_SUFFIXES cbc |
| 33 |
) |
| 34 |
|
| 35 |
if(NOT "${CBC_CONFIG_LOC}" STREQUAL "CBC_CONFIG_LOC-NOTFOUND") |
| 36 |
file(READ "${CBC_CONFIG_LOC}" CBC_CONFIG) |
| 37 |
string(REGEX MATCH "\#define +CBC_VERSION +\"([0-9]+.[0-9]+)\"" _ "${CBC_CONFIG}") |
| 38 |
set(OSICBC_VERSION "${CMAKE_MATCH_1}") |
| 39 |
unset(CBC_CONFIG) |
| 40 |
endif() |
| 41 |
unset(CBC_CONFIG_LOC) |
| 42 |
|
| 43 |
if(WIN32 AND NOT UNIX) |
| 44 |
set(OSICBC_REQ_LIBS Osi OsiClp OsiCbc Clp Cgl Cbc CbcSolver CoinUtils) |
| 45 |
else() |
| 46 |
set(OSICBC_REQ_LIBS CbcSolver Cbc Cgl OsiClp Clp Osi CoinUtils) |
| 47 |
endif() |
| 48 |
|
| 49 |
foreach(OSICBC_LIB ${OSICBC_REQ_LIBS}) |
| 50 |
set(OSICBC_LIB_LOC "OSICBC_LIB_LOC-NOTFOUND") |
| 51 |
find_library(OSICBC_LIB_LOC NAMES ${OSICBC_LIB} lib${OSICBC_LIB} |
| 52 |
HINTS ${OSICBC_INCLUDE} ${PROJECT_SOURCE_DIR}/vendor/cbc |
| 53 |
PATH_SUFFIXES lib) |
| 54 |
if("${OSICBC_LIB_LOC}" STREQUAL "OSICBC_LIB_LOC-NOTFOUND") |
| 55 |
# message(STATUS "OsiCBC: Could not find library `${OSICBC_LIB}`") |
| 56 |
set(OSICBC_LIBRARY "") |
| 57 |
break() |
| 58 |
endif() |
| 59 |
list(APPEND OSICBC_LIBRARY ${OSICBC_LIB_LOC}) |
| 60 |
add_library(${OSICBC_LIB} UNKNOWN IMPORTED) |
| 61 |
set_target_properties(${OSICBC_LIB} PROPERTIES |
| 62 |
IMPORTED_LOCATION ${OSICBC_LIB_LOC} |
| 63 |
INTERFACE_INCLUDE_DIRECTORIES "${OSICBC_INCLUDE}") |
| 64 |
list(APPEND OSICBC_TARGETS ${OSICBC_LIB}) |
| 65 |
endforeach(OSICBC_LIB) |
| 66 |
|
| 67 |
unset(OSICBC_REQ_LIBS) |
| 68 |
unset(OSICBC_LIB_LOC) |
| 69 |
|
| 70 |
if(UNIX AND NOT WIN32 AND NOT DEFINED EMSCRIPTEN) |
| 71 |
find_package(ZLIB) |
| 72 |
if(NOT ZLIB_FOUND) |
| 73 |
message(STATUS "OsiCBC: Missing dependency `Zlib`") |
| 74 |
set(OSICBC_LIBRARY "") |
| 75 |
else() |
| 76 |
list(APPEND OSICBC_LIBRARY ${ZLIB_LIBRARIES}) |
| 77 |
list(APPEND OSICBC_TARGETS ZLIB::ZLIB) |
| 78 |
endif() |
| 79 |
endif() |
| 80 |
|
| 81 |
include(FindPackageHandleStandardArgs) |
| 82 |
# handle the QUIETLY and REQUIRED arguments and set CBC_FOUND to TRUE |
| 83 |
# if all listed variables are TRUE |
| 84 |
find_package_handle_standard_args(OsiCBC |
| 85 |
FOUND_VAR OSICBC_FOUND |
| 86 |
REQUIRED_VARS OSICBC_INCLUDE OSICBC_LIBRARY |
| 87 |
VERSION_VAR OSICBC_VERSION |
| 88 |
FAIL_MESSAGE "Could NOT find OsiCBC, use OsiCBC_ROOT to hint its location" |
| 89 |
) |
| 90 |
|
| 91 |
mark_as_advanced(OSICBC_INCLUDE OSICBC_LIBRARY) |
| 92 |
|
| 93 |
set(OSICBC_LIBRARIES ${OSICBC_LIBRARY}) |
| 94 |
set(OSICBC_INCLUDE_DIRS ${OSICBC_INCLUDE}) |