1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
cmake_minimum_required(VERSION 3.11)
# INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()
project(CallableLibrary)
include(CTest)
if(TARGET SCIP::SCIP)
# find package by SCIP PATH
find_package(SCIP CONFIG NO_DEFAULT_PATH PATHS ${SCIP_BINARY_DIR} REQUIRED)
else()
find_package(SCIP REQUIRED)
endif()
include_directories(BEFORE PUBLIC ${SCIP_INCLUDE_DIRS})
add_executable(gastrans
src/gastrans.c)
add_executable(spring
src/spring.c)
add_executable(brachistochrone
src/brachistochrone.c)
add_executable(circlepacking
src/circlepacking.c)
# link to math library if it is available
find_library(LIBM m)
if(NOT LIBM)
set(LIBM "")
endif()
target_link_libraries(gastrans ${SCIP_LIBRARIES} ${LIBM})
target_compile_options(gastrans PRIVATE ${SCIP_COMPILE_FLAGS})
set_property(TARGET gastrans PROPERTY INTERPROCEDURAL_OPTIMIZATION ${LTO_AVAILABLE})
target_link_libraries(spring ${SCIP_LIBRARIES})
target_compile_options(spring PRIVATE ${SCIP_COMPILE_FLAGS})
set_property(TARGET spring PROPERTY INTERPROCEDURAL_OPTIMIZATION ${LTO_AVAILABLE})
target_link_libraries(brachistochrone ${SCIP_LIBRARIES} ${LIBM})
target_compile_options(brachistochrone PRIVATE ${SCIP_COMPILE_FLAGS})
set_property(TARGET brachistochrone PROPERTY INTERPROCEDURAL_OPTIMIZATION ${LTO_AVAILABLE})
target_link_libraries(circlepacking ${SCIP_LIBRARIES} ${LIBM})
target_compile_options(circlepacking PRIVATE ${SCIP_COMPILE_FLAGS})
set_property(TARGET circlepacking PROPERTY INTERPROCEDURAL_OPTIMIZATION ${LTO_AVAILABLE})
if( TARGET examples )
add_dependencies( examples gastrans spring brachistochrone circlepacking )
endif()
#
# add one test that builds the executable and one that runs it
#
macro(addbuildandtest target)
add_test(NAME examples-callablelibrary_${target}-build
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config $<CONFIG> --target ${target}
)
#
# avoid that several build jobs try to concurrently build the SCIP library
# note that this ressource lock name is not the actual libscip target
#
set_tests_properties(examples-callablelibrary_${target}-build
PROPERTIES
RESOURCE_LOCK libscip
)
add_test(NAME examples-callablelibrary_${target}
COMMAND $<TARGET_FILE:${target}>
)
set_tests_properties(examples-callablelibrary_${target}
PROPERTIES
FAIL_REGULAR_EXPRESSION "ERROR"
DEPENDS examples-callablelibrary_${target}-build
)
if(WIN32)
# on windows we need to execute the application and examples executables from the directory containing the libscip.dll,
# on other systems this directory does not exist.
set_tests_properties(examples-callablelibrary_${target}
PROPERTIES
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>
)
endif()
endmacro(addbuildandtest)
addbuildandtest(gastrans)
addbuildandtest(spring)
addbuildandtest(brachistochrone)
addbuildandtest(circlepacking)
|