Skip to content

Commit 13943fd

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 b2526ae commit 13943fd

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
@@ -449,8 +449,9 @@ function(add_cxx_example FILE_NAME)
449449

450450
install(TARGETS ${EXAMPLE_NAME})
451451

452-
if(BUILD_TESTING)
453-
add_test(NAME cxx_${COMPONENT_NAME}_${EXAMPLE_NAME} COMMAND ${EXAMPLE_NAME})
452+
set(SKIP_TEST (${ARGC} GREATER 1) AND ${ARG1})
453+
if(BUILD_TESTING AND NOT SKIP_TEST)
454+
add_test(NAME cxx_${COMPONENT_NAME}_${EXAMPLE_NAME} COMMAND ${EXAMPLE_NAME})
454455
endif()
455456
message(STATUS "Configuring example ${FILE_NAME}: ...DONE")
456457
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)