Skip to content

Commit 03b8139

Browse files
committed
Reuse common add_cxx_example function for Sat Runner
Add an optional parameter to leave out the example from testing.
1 parent b0dad09 commit 03b8139

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

cmake/cpp.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ function(add_cxx_example FILE_NAME)
467467

468468
install(TARGETS ${EXAMPLE_NAME})
469469

470-
if(BUILD_TESTING)
471-
add_test(NAME cxx_${COMPONENT_NAME}_${EXAMPLE_NAME} COMMAND ${EXAMPLE_NAME})
470+
set(SKIP_TEST (${ARGC} GREATER 1) AND ${ARG1})
471+
if(BUILD_TESTING AND NOT SKIP_TEST)
472+
add_test(NAME cxx_${COMPONENT_NAME}_${EXAMPLE_NAME} COMMAND ${EXAMPLE_NAME})
472473
endif()
473474
message(STATUS "Configuring example ${FILE_NAME}: ...DONE")
474475
endfunction()

examples/cpp/CMakeLists.txt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,8 @@ foreach(SAMPLE IN LISTS CXX_SRCS)
5454
endforeach()
5555

5656
# Sat Runner
57-
include(GNUInstallDirs)
58-
if(APPLE)
59-
set(CMAKE_INSTALL_RPATH
60-
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
61-
elseif(UNIX)
62-
set(CMAKE_INSTALL_RPATH
63-
"$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
64-
endif()
65-
66-
add_executable(sat_runner)
57+
add_cxx_example("${CMAKE_CURRENT_LIST_DIR}/sat_runner.cc" TRUE)
6758
target_sources(sat_runner PRIVATE
68-
"sat_runner.cc"
6959
"opb_reader.h"
7060
"sat_cnf_reader.h")
71-
target_include_directories(sat_runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
72-
target_compile_features(sat_runner PRIVATE cxx_std_17)
73-
target_link_libraries(sat_runner PRIVATE ${PROJECT_NAMESPACE}::ortools)
74-
75-
install(TARGETS sat_runner)
7661

0 commit comments

Comments
 (0)