Skip to content

Commit

Permalink
Reuse common add_cxx_sample function for Sat Runner
Browse files Browse the repository at this point in the history
Add an optional parameter to leave out the example from testing.
  • Loading branch information
StefanBruens committed May 11, 2023
1 parent 3381657 commit 1ee1e2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
8 changes: 5 additions & 3 deletions cmake/cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ function(add_cxx_sample FILE_NAME)

install(TARGETS ${SAMPLE_NAME})

if(BUILD_TESTING)
set(SKIP_TEST (${ARGC} GREATER 1) AND ${ARG1})
if(BUILD_TESTING AND NOT SKIP_TEST)
add_test(NAME cxx_${COMPONENT_NAME}_${SAMPLE_NAME} COMMAND ${SAMPLE_NAME})
endif()
message(STATUS "Configuring sample ${FILE_NAME}: ...DONE")
Expand Down Expand Up @@ -496,8 +497,9 @@ function(add_cxx_example FILE_NAME)

install(TARGETS ${EXAMPLE_NAME})

if(BUILD_TESTING)
add_test(NAME cxx_${COMPONENT_NAME}_${EXAMPLE_NAME} COMMAND ${EXAMPLE_NAME})
set(SKIP_TEST (${ARGC} GREATER 1) AND ${ARG1})
if(BUILD_TESTING AND NOT SKIP_TEST)
add_test(NAME cxx_${COMPONENT_NAME}_${EXAMPLE_NAME} COMMAND ${EXAMPLE_NAME})
endif()
message(STATUS "Configuring example ${FILE_NAME}: ...DONE")
endfunction()
Expand Down
19 changes: 3 additions & 16 deletions ortools/sat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,7 @@ target_link_libraries(${NAME} PRIVATE
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::sat ALIAS ${NAME})

# Sat Runner
include(GNUInstallDirs)
if(APPLE)
set(CMAKE_INSTALL_RPATH
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
elseif(UNIX)
set(CMAKE_INSTALL_RPATH
"$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
endif()

add_executable(sat_runner)
target_sources(sat_runner PRIVATE "sat_runner.cc")
target_include_directories(sat_runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(sat_runner PRIVATE cxx_std_17)
target_link_libraries(sat_runner PRIVATE ${PROJECT_NAMESPACE}::ortools)
include(cpp)

install(TARGETS sat_runner)
# Sat Runner
add_cxx_sample("${CMAKE_CURRENT_LIST_DIR}/sat_runner.cc" TRUE)

0 comments on commit 1ee1e2d

Please sign in to comment.