* Fix CMake package config file There are currently a few issues with how the COIN-OR dependencies are resolved when using `find_package(ortools CONFIG)` to add or-tools to an external CMake project. * With CMake >=3.9.6, we try to find the Clp and Cbc packages using the CONFIG mode of `find_package`. This always fails since neither library provides a CMake config file. * If we address the above issue by instead using the MODULE mode of `find_package`, then we need to add `FindCbc.cmake` and `FindCpl.cmake` scripts to the CMAKE_MODULE_PATH in order to teach CMake how to find these dependencies. I propose that or-tools should install these scripts alongside its config file so that they're available to external CMake projects. * Finally, the `FindCbc.cmake` script included with or-tools defines the variable `CBC_FOUND` when it's successful, rather than `Cbc_FOUND` as expected (CMake variables are case-sensitive). The `FindCpl.cmake` script has a similar issue. As a result, even when the above two points are addressed, `find_package(ortools CONFIG)` will still fail because CMake erroneously thinks that these two dependencies weren't succesfully found. This commit attempts to address the above issues with the following changes: * The or-tools CMake config file is modified to allow searching for Cbc and Cpl using the MODULE mode of `find_package`. * `FindCbc.cmake` and `FindCpl.cmake` are installed with the CMake package config files and are added to the CMAKE_MODULE_PATH if `USE_COINOR` was truthy. * The `FindCbc.cmake` and `FindCpl.cmake` files are modified to change the case of variables they export. * Only install FindXXX.cmake modules if COIN-OR support was enabled
55 lines
1.3 KiB
CMake
55 lines
1.3 KiB
CMake
## ortools CMake configuration file
|
|
|
|
set(@PACKAGE_PREFIX@_VERSION @PROJECT_VERSION@)
|
|
|
|
@PACKAGE_INIT@
|
|
|
|
include(CMakeFindDependencyMacro)
|
|
# Kitware CMake provide a FindZLIB.cmake module
|
|
if(NOT ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)
|
|
find_dependency(ZLIB REQUIRED)
|
|
endif()
|
|
|
|
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.9.6")
|
|
set(CONFIG_FLAG CONFIG)
|
|
endif()
|
|
|
|
if(NOT absl_FOUND)
|
|
find_dependency(absl REQUIRED ${CONFIG_FLAG})
|
|
endif()
|
|
|
|
if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND AND NOT TARGET protobuf::libprotobuf)
|
|
find_dependency(Protobuf REQUIRED ${CONFIG_FLAG})
|
|
endif()
|
|
|
|
if(@BUILD_LP_PARSER@)
|
|
if(NOT re2_FOUND AND NOT TARGET re2::re2)
|
|
find_dependency(re2 REQUIRED ${CONFIG_FLAG})
|
|
endif()
|
|
endif()
|
|
|
|
if(@USE_COINOR@)
|
|
# COIN-OR packages don't provide CMake config files
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules")
|
|
if(NOT Clp_FOUND AND NOT TARGET Coin::ClpSolver)
|
|
find_dependency(Clp REQUIRED)
|
|
endif()
|
|
if(NOT Cbc_FOUND AND NOT TARGET Coin::CbcSolver)
|
|
find_dependency(Cbc REQUIRED)
|
|
endif()
|
|
endif()
|
|
|
|
if(@USE_GLPK@)
|
|
if(NOT GLPK_FOUND AND NOT TARGET GLPK::GLPK)
|
|
find_dependency(GLPK REQUIRED ${CONFIG_FLAG})
|
|
endif()
|
|
endif()
|
|
|
|
if(@USE_SCIP@)
|
|
if(NOT scip_FOUND AND NOT TARGET libscip)
|
|
find_dependency(scip REQUIRED ${CONFIG_FLAG})
|
|
endif()
|
|
endif()
|
|
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|