-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix super build (e.g. FetchContent) integration - cmake: option() honors normal variables (CMP0077)
- Loading branch information
Showing
8 changed files
with
637 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,6 @@ | |
aclocal.m4* | ||
acinclude.m4 | ||
autom4te* | ||
*.swp | ||
.vs/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
||
include(ParseAc) | ||
parse_ac(VERSION MAJOR MINOR PATCH) | ||
|
||
project(Cgl VERSION ${VERSION} LANGUAGES CXX C) | ||
set(PROJECT_NAMESPACE coin) | ||
message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}") | ||
#message(STATUS "major: ${PROJECT_VERSION_MAJOR}") | ||
#message(STATUS "minor: ${PROJECT_VERSION_MINOR}") | ||
#message(STATUS "patch: ${PROJECT_VERSION_PATCH}") | ||
|
||
# Set max os target version. | ||
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) | ||
|
||
# Default Build Type to be Release | ||
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) | ||
if(isMultiConfig) | ||
if(NOT CMAKE_CONFIGURATION_TYPES) | ||
set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING | ||
"Choose the type of builds, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release;Debug)" | ||
FORCE) | ||
endif() | ||
message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}") | ||
else() | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING | ||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release)" | ||
FORCE) | ||
endif() | ||
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") | ||
endif() | ||
|
||
# Layout build dir like install dir | ||
include(GNUInstallDirs) | ||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) | ||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) | ||
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) | ||
if(UNIX) | ||
option(BUILD_SHARED_LIBS "Build shared libraries (.so or .dylib)." ON) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) | ||
# for multi-config build system (e.g. Xcode, Ninja Multi-Config) | ||
foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES) | ||
string(TOUPPER ${OutputConfig} OUTPUTCONFIG) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR}) | ||
endforeach() | ||
else() | ||
# Currently Only support static build for windows | ||
option(BUILD_SHARED_LIBS "Build shared libraries (.dll)." OFF) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) | ||
# for multi-config builds (e.g. msvc) | ||
foreach(OutputConfig IN LISTS CMAKE_CONFIGURATION_TYPES) | ||
string(TOUPPER ${OutputConfig} OUTPUTCONFIG) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR}) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OutputConfig}/${CMAKE_INSTALL_BINDIR}) | ||
endforeach() | ||
endif() | ||
|
||
if(MSVC AND BUILD_SHARED_LIBS) | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
endif() | ||
|
||
# config options | ||
if(MSVC) | ||
# Build with multiple processes | ||
add_definitions(/MP) | ||
add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE) | ||
# MSVC warning suppressions | ||
add_definitions( | ||
/wd4018 # 'expression' : signed/unsigned mismatch | ||
/wd4065 # switch statement contains 'default' but no 'case' labels | ||
/wd4101 # 'identifier' : unreferenced local variable | ||
/wd4102 # 'label' : unreferenced label | ||
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data | ||
/wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data | ||
/wd4309 # 'conversion' : truncation of constant value | ||
/wd4805 # 'operation' : unsafe mix of type 'type1' and type 'type2' in operation. | ||
/wd4996 # The compiler encountered a deprecated declaration. | ||
) | ||
endif() | ||
if(APPLE) | ||
set( | ||
CMAKE_CXX_FLAGS | ||
"${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override -Wno-unused-command-line-argument -Wno-unused-result -Wno-exceptions" | ||
) | ||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version") | ||
endif() | ||
|
||
# ZLIB | ||
if(NOT TARGET ZLIB::ZLIB) | ||
find_package(ZLIB) | ||
endif() | ||
if(ZLIB_FOUND OR TARGET ZLIB::ZLIB) | ||
message(STATUS "Use zlib") | ||
set(HAVE_ZLIB_H "1" CACHE INTERNAL "Use zlib") | ||
set(COIN_HAS_ZLIB "1" CACHE INTERNAL "Use zlib") | ||
endif() | ||
|
||
# PThread | ||
set(THREADS_PREFER_PTHREAD_FLAG ON) | ||
find_package(Threads) | ||
if(CMAKE_USE_PTHREADS_INIT) | ||
set(PTHREADS_FOUND TRUE) | ||
else() | ||
set(PTHREADS_FOUND FALSE) | ||
endif() | ||
|
||
# CoinUtils | ||
if(NOT TARGET Coin::CoinUtils) | ||
find_package(CoinUtils REQUIRED CONFIG) | ||
endif() | ||
# Osi | ||
if(NOT TARGET Coin::Osi) | ||
find_package(Osi REQUIRED CONFIG) | ||
endif() | ||
# Clp | ||
if(NOT TARGET Coin::Clp) | ||
find_package(Clp REQUIRED CONFIG) | ||
endif() | ||
|
||
include(CheckEnv) | ||
include(CTest) | ||
|
||
add_subdirectory(Cgl) | ||
|
||
include(GNUInstallDirs) | ||
install(EXPORT ${PROJECT_NAME}Targets | ||
NAMESPACE Coin:: | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") | ||
include(CMakePackageConfigHelpers) | ||
configure_package_config_file(cmake/Config.cmake.in | ||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") | ||
write_basic_package_version_file( | ||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" | ||
COMPATIBILITY SameMajorVersion) | ||
install( | ||
FILES | ||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" | ||
COMPONENT Devel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
set(NAME "CGL") | ||
|
||
# PTHREAD | ||
if(PTHREADS_FOUND) | ||
set(${NAME}_PTHREADS "1" CACHE INTERNAL "Use pthread") | ||
endif() | ||
|
||
set(COIN_${NAME}_CHECKLEVEL "0" CACHE INTERNAL | ||
"${NAME} check level") | ||
set(COIN_${NAME}_VERBOSITY "0" CACHE INTERNAL | ||
"${NAME} verbosity level") | ||
configure_file(config.h.cmake.in config.h) | ||
configure_file(config_cgl.h.cmake.in config_cgl.h) | ||
|
||
set(_SRCS | ||
src/CglMixedIntegerRounding/CglMixedIntegerRoundingTest.cpp | ||
src/CglMixedIntegerRounding/CglMixedIntegerRounding.cpp | ||
src/CglDuplicateRow/CglDuplicateRow.cpp | ||
src/CglCutGenerator.cpp | ||
src/CglPreProcess/CglPreProcess.cpp | ||
src/CglProbing/CglProbing.cpp | ||
src/CglProbing/CglProbingTest.cpp | ||
src/CglMixedIntegerRounding2/CglMixedIntegerRounding2.cpp | ||
src/CglMixedIntegerRounding2/CglMixedIntegerRounding2Test.cpp | ||
src/CglLandP/CglLandPUtils.cpp | ||
src/CglLandP/CglLandPTest.cpp | ||
src/CglLandP/CglLandPTabRow.cpp | ||
src/CglLandP/CglLandPSimplex.cpp | ||
src/CglLandP/CglLandPValidator.cpp | ||
src/CglLandP/CglLandPMessages.cpp | ||
src/CglLandP/CglLandP.cpp | ||
src/CglOddHole/CglOddHoleTest.cpp | ||
src/CglOddHole/CglOddHole.cpp | ||
src/CglRedSplit/CglRedSplitParam.cpp | ||
src/CglRedSplit/CglRedSplit.cpp | ||
src/CglRedSplit/CglRedSplitTest.cpp | ||
src/CglAllDifferent/CglAllDifferent.cpp | ||
src/CglKnapsackCover/CglKnapsackCoverTest.cpp | ||
src/CglKnapsackCover/CglKnapsackCover.cpp | ||
src/CglSimpleRounding/CglSimpleRoundingTest.cpp | ||
src/CglSimpleRounding/CglSimpleRounding.cpp | ||
src/CglZeroHalf/CglZeroHalfTest.cpp | ||
src/CglZeroHalf/Cgl012cut.cpp | ||
src/CglZeroHalf/CglZeroHalf.cpp | ||
src/CglRedSplit2/CglRedSplit2Test.cpp | ||
src/CglRedSplit2/CglRedSplit2Param.cpp | ||
src/CglRedSplit2/CglRedSplit2.cpp | ||
src/CglMessage.cpp | ||
src/CglStored.cpp | ||
src/CglParam.cpp | ||
src/CglResidualCapacity/CglResidualCapacity.cpp | ||
src/CglResidualCapacity/CglResidualCapacityTest.cpp | ||
src/CglTwomir/CglTwomirTest.cpp | ||
src/CglTwomir/CglTwomir.cpp | ||
src/CglFlowCover/CglFlowCoverTest.cpp | ||
src/CglFlowCover/CglFlowCover.cpp | ||
src/CglClique/CglCliqueHelper.cpp | ||
src/CglClique/CglCliqueTest.cpp | ||
src/CglClique/CglClique.cpp | ||
src/CglTreeInfo.cpp | ||
src/CglLiftAndProject/CglLiftAndProject.cpp | ||
src/CglGomory/CglGomoryTest.cpp | ||
src/CglGomory/CglGomory.cpp | ||
src/CglGMI/CglGMI.cpp | ||
src/CglGMI/CglGMIParam.cpp) | ||
|
||
set(_HDRS | ||
src/CglConfig.h | ||
src/CglMixedIntegerRounding/CglMixedIntegerRounding.hpp | ||
src/CglDuplicateRow/CglDuplicateRow.hpp | ||
src/CglStored.hpp | ||
src/CglPreProcess/CglPreProcess.hpp | ||
src/CglProbing/CglProbing.hpp | ||
src/CglMixedIntegerRounding2/CglMixedIntegerRounding2.hpp | ||
src/CglLandP/CglLandP.hpp | ||
src/CglLandP/CglLandPUtils.hpp | ||
src/CglLandP/CglLandPValidator.hpp | ||
src/CglLandP/CglLandPTabRow.hpp | ||
src/CglLandP/CglLandPMessages.hpp | ||
src/CglLandP/CglLandPSimplex.hpp | ||
src/CglOddHole/CglOddHole.hpp | ||
src/CglRedSplit/CglRedSplitParam.hpp | ||
src/CglRedSplit/CglRedSplit.hpp | ||
src/CglAllDifferent/CglAllDifferent.hpp | ||
src/CglKnapsackCover/CglKnapsackCover.hpp | ||
src/CglSimpleRounding/CglSimpleRounding.hpp | ||
src/CglMessage.hpp | ||
src/CglZeroHalf/CglZeroHalf.hpp | ||
src/CglZeroHalf/Cgl012cut.hpp | ||
src/CglRedSplit2/CglRedSplit2Param.hpp | ||
src/CglRedSplit2/CglRedSplit2.hpp | ||
src/CglCutGenerator.hpp | ||
src/CglResidualCapacity/CglResidualCapacity.hpp | ||
src/CglTwomir/CglTwomir.hpp | ||
src/CglFlowCover/CglFlowCover.hpp | ||
src/CglClique/CglClique.hpp | ||
src/CglLiftAndProject/CglLiftAndProject.hpp | ||
src/CglGomory/CglGomory.hpp | ||
src/CglGMI/CglGMIParam.hpp | ||
src/CglGMI/CglGMI.hpp | ||
src/CglParam.hpp | ||
src/CglTreeInfo.hpp) | ||
|
||
include(GNUInstallDirs) | ||
|
||
add_library(Cgl ${_SRCS} ${_HDRS}) | ||
target_include_directories(Cgl PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglClique> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglDuplicateRow> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglFlowCover> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglGMI> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglGomory> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglKnapsackCover> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglLandP> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglMixedIntegerRounding> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglMixedIntegerRounding2> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglPreProcess> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglProbing> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglOddHole> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglRedSplit> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglRedSplit2> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglResidualCapacity> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglSimpleRounding> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglTwomir> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/CglZeroHalf> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
$<INSTALL_INTERFACE:include/coin>) | ||
target_compile_definitions(Cgl | ||
PUBLIC HAVE_CONFIG_H | ||
PRIVATE CGL_BUILD) | ||
if(CMAKE_VERSION VERSION_LESS "3.8.2") | ||
set_property(TARGET Cgl PROPERTY CXX_STANDARD 11) | ||
set_property(TARGET Cgl PROPERTY CXX_STANDARD_REQUIRED ON) | ||
else() | ||
target_compile_features(Cgl PUBLIC cxx_std_11) | ||
endif() | ||
if(APPLE) | ||
set_target_properties(Cgl PROPERTIES INSTALL_RPATH "@loader_path") | ||
elseif(UNIX) | ||
set_target_properties(Cgl PROPERTIES INSTALL_RPATH "$ORIGIN") | ||
endif() | ||
target_link_libraries(Cgl PUBLIC | ||
Coin::CoinUtils | ||
Coin::Osi | ||
Coin::OsiClp) | ||
set_target_properties(Cgl PROPERTIES | ||
PUBLIC_HEADER "${_HDRS};${CMAKE_CURRENT_BINARY_DIR}/config_cgl.h" | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR}) | ||
add_library(Coin::Cgl ALIAS Cgl) | ||
|
||
# Install | ||
install(TARGETS Cgl | ||
EXPORT ${PROJECT_NAME}Targets | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/coin | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) |
Oops, something went wrong.