Files
ortools-clone/cmake/cpp.cmake

435 lines
14 KiB
CMake
Raw Normal View History

if(NOT BUILD_CXX)
return()
endif()
# Main Target
add_library(${PROJECT_NAME} "")
2020-05-17 18:23:08 +02:00
# Xcode fails to build if library doesn't contains at least one source file.
if(XCODE)
2020-05-27 17:13:48 +02:00
file(GENERATE
OUTPUT ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/version.cpp
CONTENT "namespace {char* version = \"${PROJECT_VERSION}\";}")
target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/version.cpp)
2020-05-17 18:23:08 +02:00
endif()
2020-01-29 17:35:51 +01:00
if(BUILD_SHARED_LIBS)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "OR_TOOLS_AS_DYNAMIC_LIB")
endif()
2020-01-29 17:35:51 +01:00
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS
"USE_BOP" # enable BOP support
"USE_GLOP" # enable GLOP support
)
2022-03-24 13:35:24 +01:00
if(BUILD_LP_PARSER)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_LP_PARSER")
endif()
2022-02-25 23:43:01 +01:00
if(USE_COINOR)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS
"USE_CBC" # enable COIN-OR CBC support
"USE_CLP" # enable COIN-OR CLP support
)
endif()
if(USE_GLPK)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_GLPK")
set(GLPK_DIR glpk)
2022-02-25 23:43:01 +01:00
endif()
2022-02-16 17:38:48 +01:00
if(USE_PDLP)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_PDLP")
set(PDLP_DIR pdlp)
endif()
2020-07-03 16:16:50 +02:00
if(USE_SCIP)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_SCIP")
2020-11-09 14:04:05 +01:00
set(GSCIP_DIR gscip)
2020-07-03 16:16:50 +02:00
endif()
if(USE_CPLEX)
2020-01-29 17:35:51 +01:00
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_CPLEX")
endif()
if(USE_XPRESS)
2020-01-29 17:35:51 +01:00
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_XPRESS")
if(MSVC)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "XPRESS_PATH=\"${XPRESS_ROOT}\"")
else()
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "XPRESS_PATH=${XPRESS_ROOT}")
endif()
2020-01-29 17:35:51 +01:00
endif()
if(WIN32)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "__WIN32__")
endif()
if(MSVC)
2020-02-07 07:58:01 +01:00
list(APPEND OR_TOOLS_COMPILE_OPTIONS
2020-01-29 17:35:51 +01:00
"/bigobj" # Allow big object
"/DNOMINMAX"
"/DWIN32_LEAN_AND_MEAN=1"
"/D_CRT_SECURE_NO_WARNINGS"
"/D_CRT_SECURE_NO_DEPRECATE"
"/MP" # Build with multiple processes
"/DNDEBUG"
2020-01-29 17:35:51 +01:00
)
# MSVC warning suppressions
2020-02-07 07:58:01 +01:00
list(APPEND OR_TOOLS_COMPILE_OPTIONS
2020-01-29 17:35:51 +01:00
"/wd4005" # 'macro-redefinition'
"/wd4018" # 'expression' : signed/unsigned mismatch
"/wd4065" # switch statement contains 'default' but no 'case' labels
"/wd4068" # 'unknown pragma'
"/wd4101" # 'identifier' : unreferenced local variable
"/wd4146" # unary minus operator applied to unsigned type, result still unsigned
"/wd4200" # nonstandard extension used : zero-sized array in struct/union
"/wd4244" # 'conversion' conversion from 'type1' to 'type2', possible loss of data
"/wd4251" # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
"/wd4267" # 'var' : conversion from 'size_t' to 'type', possible loss of data
"/wd4305" # 'identifier' : truncation from 'type1' to 'type2'
"/wd4307" # 'operator' : integral constant overflow
"/wd4309" # 'conversion' : truncation of constant value
"/wd4334" # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
"/wd4355" # 'this' : used in base member initializer list
"/wd4477" # 'fwprintf' : format string '%s' requires an argument of type 'wchar_t *'
"/wd4506" # no definition for inline function 'function'
"/wd4715" # function' : not all control paths return a value
"/wd4800" # 'type' : forcing value to bool 'true' or 'false' (performance warning)
"/wd4996" # The compiler encountered a deprecated declaration.
)
else()
2020-02-07 07:58:01 +01:00
list(APPEND OR_TOOLS_COMPILE_OPTIONS "-fwrapv")
endif()
2017-06-28 15:45:56 +05:30
2020-01-29 17:35:51 +01:00
# Includes
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
# Compile options
2020-02-21 19:37:50 +01:00
set_target_properties(${PROJECT_NAME} PROPERTIES
2022-02-19 15:05:17 +01:00
CXX_STANDARD 20
2020-02-21 19:37:50 +01:00
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
2020-01-29 17:35:51 +01:00
target_compile_definitions(${PROJECT_NAME} PUBLIC ${OR_TOOLS_COMPILE_DEFINITIONS})
target_compile_options(${PROJECT_NAME} PUBLIC ${OR_TOOLS_COMPILE_OPTIONS})
2020-01-29 17:35:51 +01:00
# Properties
if(NOT APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
else()
# Clang don't support version x.y.z with z > 255
2020-03-05 11:01:57 +01:00
set_target_properties(${PROJECT_NAME} PROPERTIES
INSTALL_RPATH "@loader_path"
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set_target_properties(${PROJECT_NAME} PROPERTIES COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION)
2020-01-29 17:35:51 +01:00
# Dependencies
target_link_libraries(${PROJECT_NAME} PUBLIC
2020-06-26 01:01:42 +02:00
${CMAKE_DL_LIBS}
ZLIB::ZLIB
2020-03-02 09:46:15 +01:00
${ABSL_DEPS}
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
protobuf::libprotobuf
${RE2_DEPS}
2020-02-06 18:32:40 +01:00
${COINOR_DEPS}
2020-08-10 11:46:30 +02:00
$<$<BOOL:${USE_CPLEX}>:CPLEX::CPLEX>
2022-02-16 17:38:48 +01:00
$<$<BOOL:${USE_GLPK}>:GLPK::GLPK>
${PDLP_DEPS}
$<$<BOOL:${USE_SCIP}>:libscip>
2020-08-10 11:46:30 +02:00
$<$<BOOL:${USE_XPRESS}>:XPRESS::XPRESS>
Threads::Threads)
if(WIN32)
2020-01-21 16:41:11 +01:00
target_link_libraries(${PROJECT_NAME} PUBLIC psapi.lib ws2_32.lib)
endif()
2020-01-29 17:35:51 +01:00
# ALIAS
2021-11-12 01:30:58 +01:00
add_library(${PROJECT_NAMESPACE}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
2017-06-28 15:45:56 +05:30
# Generate Protobuf cpp sources
set(PROTO_HDRS)
set(PROTO_SRCS)
2020-02-21 19:37:01 +01:00
file(GLOB_RECURSE proto_files RELATIVE ${PROJECT_SOURCE_DIR}
"ortools/bop/*.proto"
"ortools/constraint_solver/*.proto"
"ortools/glop/*.proto"
"ortools/graph/*.proto"
"ortools/linear_solver/*.proto"
"ortools/linear_solver/*.proto"
"ortools/packing/*.proto"
2020-02-21 19:37:01 +01:00
"ortools/sat/*.proto"
"ortools/scheduling/*.proto"
2020-02-21 19:37:01 +01:00
"ortools/util/*.proto"
)
2022-02-16 17:38:48 +01:00
if(USE_PDLP)
file(GLOB_RECURSE pdlp_proto_files RELATIVE ${PROJECT_SOURCE_DIR} "ortools/pdlp/*.proto")
list(APPEND proto_files ${pdlp_proto_files})
endif()
2020-10-19 11:27:02 +02:00
if(USE_SCIP)
file(GLOB_RECURSE gscip_proto_files RELATIVE ${PROJECT_SOURCE_DIR} "ortools/gscip/*.proto")
list(APPEND proto_files ${gscip_proto_files})
endif()
2018-04-19 16:27:51 +02:00
2020-07-01 21:01:16 +02:00
## Get Protobuf include dir
2018-04-19 16:27:51 +02:00
get_target_property(protobuf_dirs protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
2020-03-03 14:52:57 +01:00
foreach(dir IN LISTS protobuf_dirs)
if (NOT "${dir}" MATCHES "INSTALL_INTERFACE|-NOTFOUND")
2020-07-01 21:01:16 +02:00
message(STATUS "Adding proto path: ${dir}")
list(APPEND PROTO_DIRS "--proto_path=${dir}")
2018-04-19 16:27:51 +02:00
endif()
endforeach()
2020-03-03 14:52:57 +01:00
foreach(PROTO_FILE IN LISTS proto_files)
#message(STATUS "protoc proto(cc): ${PROTO_FILE}")
get_filename_component(PROTO_DIR ${PROTO_FILE} DIRECTORY)
get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
set(PROTO_HDR ${PROJECT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME}.pb.h)
set(PROTO_SRC ${PROJECT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME}.pb.cc)
#message(STATUS "protoc hdr: ${PROTO_HDR}")
#message(STATUS "protoc src: ${PROTO_SRC}")
add_custom_command(
OUTPUT ${PROTO_SRC} ${PROTO_HDR}
2021-01-07 22:52:48 +01:00
COMMAND ${PROTOC_PRG}
"--proto_path=${PROJECT_SOURCE_DIR}"
${PROTO_DIRS}
"--cpp_out=${PROJECT_BINARY_DIR}"
${PROTO_FILE}
2021-01-07 22:52:48 +01:00
DEPENDS ${PROTO_FILE} ${PROTOC_PRG}
2020-03-04 17:46:34 +01:00
COMMENT "Generate C++ protocol buffer for ${PROTO_FILE}"
VERBATIM)
list(APPEND PROTO_HDRS ${PROTO_HDR})
list(APPEND PROTO_SRCS ${PROTO_SRC})
endforeach()
#add_library(${PROJECT_NAME}_proto STATIC ${PROTO_SRCS} ${PROTO_HDRS})
add_library(${PROJECT_NAME}_proto OBJECT ${PROTO_SRCS} ${PROTO_HDRS})
2020-10-16 22:21:21 +02:00
set_target_properties(${PROJECT_NAME}_proto PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
target_include_directories(${PROJECT_NAME}_proto PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
$<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>
)
2020-01-29 17:35:51 +01:00
target_compile_definitions(${PROJECT_NAME}_proto PUBLIC ${OR_TOOLS_COMPILE_DEFINITIONS})
target_compile_options(${PROJECT_NAME}_proto PUBLIC ${OR_TOOLS_COMPILE_OPTIONS})
#target_link_libraries(${PROJECT_NAME}_proto PRIVATE protobuf::libprotobuf)
add_dependencies(${PROJECT_NAME}_proto protobuf::libprotobuf)
2021-11-12 01:30:58 +01:00
add_library(${PROJECT_NAMESPACE}::proto ALIAS ${PROJECT_NAME}_proto)
# Add ${PROJECT_NAMESPACE}::proto to libortools
#target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAMESPACE}::proto)
target_sources(${PROJECT_NAME} PRIVATE $<TARGET_OBJECTS:${PROJECT_NAMESPACE}::proto>)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAMESPACE}::proto)
2017-06-28 15:45:56 +05:30
2020-03-02 14:27:13 +01:00
foreach(SUBPROJECT IN ITEMS
2020-10-19 11:27:02 +02:00
algorithms
base
bop
constraint_solver
${GLPK_DIR}
2022-02-16 17:38:48 +01:00
${PDLP_DIR}
2020-10-19 11:27:02 +02:00
${GSCIP_DIR}
glop
graph
2021-03-18 02:49:30 +01:00
gurobi
2021-03-21 16:19:12 +01:00
init
2020-10-19 11:27:02 +02:00
linear_solver
lp_data
packing
2020-10-19 11:27:02 +02:00
port
sat
scheduling
2020-10-19 11:27:02 +02:00
util)
add_subdirectory(ortools/${SUBPROJECT})
2020-10-19 23:02:01 +02:00
#target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_${SUBPROJECT})
target_sources(${PROJECT_NAME} PRIVATE $<TARGET_OBJECTS:${PROJECT_NAME}_${SUBPROJECT}>)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_${SUBPROJECT})
endforeach()
2017-06-28 15:45:56 +05:30
2022-02-24 08:29:43 +01:00
add_subdirectory(ortools/model_builder/wrappers)
target_sources(${PROJECT_NAME} PRIVATE $<TARGET_OBJECTS:${PROJECT_NAME}_model_builder_wrappers>)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_model_builder_wrappers)
2022-04-01 15:08:12 +02:00
###################
## Install rules ##
###################
include(GNUInstallDirs)
include(GenerateExportHeader)
GENERATE_EXPORT_HEADER(${PROJECT_NAME})
install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT ${PROJECT_NAME}Targets
2021-11-12 01:30:58 +01:00
NAMESPACE ${PROJECT_NAMESPACE}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(DIRECTORY ortools
2022-04-01 15:08:12 +02:00
TYPE INCLUDE
COMPONENT Devel
FILES_MATCHING
PATTERN "*.h")
install(DIRECTORY ${PROJECT_BINARY_DIR}/ortools
2022-04-01 15:08:12 +02:00
TYPE INCLUDE
COMPONENT Devel
FILES_MATCHING
PATTERN "*.pb.h"
PATTERN CMakeFiles EXCLUDE)
include(CMakePackageConfigHelpers)
string (TOUPPER "${PROJECT_NAME}" PACKAGE_PREFIX)
configure_package_config_file(cmake/${PROJECT_NAME}Config.cmake.in
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
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)
Fix CMake package config file (#3068) * 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
2022-01-13 23:38:37 -08:00
if(USE_COINOR)
install(
FILES
"${PROJECT_SOURCE_DIR}/cmake/FindCbc.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindClp.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/modules"
COMPONENT Devel)
endif()
2020-09-19 17:21:50 +02:00
2022-03-07 15:12:15 +00:00
if(MSVC)
# Bundle lib for MSVC
configure_file(
${PROJECT_SOURCE_DIR}/cmake/bundle-install.cmake.in
${PROJECT_BINARY_DIR}/bundle-install.cmake
@ONLY)
install(SCRIPT ${PROJECT_BINARY_DIR}/bundle-install.cmake)
endif()
2022-04-01 15:08:12 +02:00
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE"
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
COMPONENT Devel)
if(INSTALL_DOC)
install(DIRECTORY ortools/sat/docs/
DESTINATION "${CMAKE_INSTALL_DOCDIR}/sat"
FILES_MATCHING
PATTERN "*.md")
install(DIRECTORY ortools/constraint_solver/docs/
DESTINATION "${CMAKE_INSTALL_DOCDIR}/constraint_solver"
FILES_MATCHING
PATTERN "*.md")
endif()
############################
## Samples/Examples/Tests ##
############################
2020-09-19 17:21:50 +02:00
# add_cxx_sample()
# CMake function to generate and build C++ sample.
# Parameters:
# the C++ filename
# e.g.:
# add_cxx_sample(foo.cc)
function(add_cxx_sample FILE_NAME)
2021-09-17 15:13:11 +02:00
message(STATUS "Configuring sample ${FILE_NAME}: ...")
2020-09-19 17:21:50 +02:00
get_filename_component(SAMPLE_NAME ${FILE_NAME} NAME_WE)
get_filename_component(SAMPLE_DIR ${FILE_NAME} DIRECTORY)
get_filename_component(COMPONENT_DIR ${SAMPLE_DIR} DIRECTORY)
get_filename_component(COMPONENT_NAME ${COMPONENT_DIR} NAME)
if(APPLE)
set(CMAKE_INSTALL_RPATH
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
elseif(UNIX)
2022-03-04 09:17:01 +01:00
set(CMAKE_INSTALL_RPATH
"$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
2020-09-19 17:21:50 +02:00
endif()
add_executable(${SAMPLE_NAME} ${FILE_NAME})
target_include_directories(${SAMPLE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(${SAMPLE_NAME} PRIVATE cxx_std_17)
2021-11-12 01:30:58 +01:00
target_link_libraries(${SAMPLE_NAME} PRIVATE ${PROJECT_NAMESPACE}::ortools)
2020-09-19 17:21:50 +02:00
include(GNUInstallDirs)
2020-11-12 22:05:34 +01:00
install(TARGETS ${SAMPLE_NAME})
2020-09-19 17:21:50 +02:00
if(BUILD_TESTING)
add_test(NAME cxx_${COMPONENT_NAME}_${SAMPLE_NAME} COMMAND ${SAMPLE_NAME})
endif()
2021-09-17 15:13:11 +02:00
message(STATUS "Configuring sample ${FILE_NAME}: ...DONE")
endfunction()
# add_cxx_example()
# CMake function to generate and build C++ example.
# Parameters:
# the C++ filename
# e.g.:
# add_cxx_example(foo.cc)
function(add_cxx_example FILE_NAME)
message(STATUS "Configuring example ${FILE_NAME}: ...")
get_filename_component(EXAMPLE_NAME ${FILE_NAME} NAME_WE)
get_filename_component(COMPONENT_DIR ${FILE_NAME} DIRECTORY)
get_filename_component(COMPONENT_NAME ${COMPONENT_DIR} NAME)
if(APPLE)
set(CMAKE_INSTALL_RPATH
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
elseif(UNIX)
2022-03-04 09:17:01 +01:00
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
2021-09-17 15:13:11 +02:00
endif()
add_executable(${EXAMPLE_NAME} ${FILE_NAME})
target_include_directories(${EXAMPLE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(${EXAMPLE_NAME} PRIVATE cxx_std_17)
2021-11-12 01:30:58 +01:00
target_link_libraries(${EXAMPLE_NAME} PRIVATE ${PROJECT_NAMESPACE}::ortools)
2021-09-17 15:13:11 +02:00
include(GNUInstallDirs)
install(TARGETS ${EXAMPLE_NAME})
if(BUILD_TESTING)
add_test(NAME cxx_${COMPONENT_NAME}_${EXAMPLE_NAME} COMMAND ${EXAMPLE_NAME})
endif()
message(STATUS "Configuring example ${FILE_NAME}: ...DONE")
endfunction()
# add_cxx_test()
# CMake function to generate and build C++ test.
# Parameters:
# the C++ filename
# e.g.:
# add_cxx_test(foo.cc)
function(add_cxx_test FILE_NAME)
message(STATUS "Configuring test ${FILE_NAME}: ...")
get_filename_component(TEST_NAME ${FILE_NAME} NAME_WE)
get_filename_component(COMPONENT_DIR ${FILE_NAME} DIRECTORY)
get_filename_component(COMPONENT_NAME ${COMPONENT_DIR} NAME)
if(APPLE)
set(CMAKE_INSTALL_RPATH
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
elseif(UNIX)
2022-03-04 09:17:01 +01:00
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
2021-09-17 15:13:11 +02:00
endif()
add_executable(${TEST_NAME} ${FILE_NAME})
target_include_directories(${TEST_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(${TEST_NAME} PRIVATE cxx_std_17)
2021-11-12 01:30:58 +01:00
target_link_libraries(${TEST_NAME} PRIVATE ${PROJECT_NAMESPACE}::ortools)
2020-09-19 17:21:50 +02:00
2021-09-17 15:13:11 +02:00
if(BUILD_TESTING)
add_test(NAME cxx_${COMPONENT_NAME}_${TEST_NAME} COMMAND ${TEST_NAME})
endif()
message(STATUS "Configuring test ${FILE_NAME}: ...DONE")
2020-09-19 17:21:50 +02:00
endfunction()