From fff7b6ad8b66caefa9fdf979cbaea3edaac2dfc7 Mon Sep 17 00:00:00 2001 From: Mizux Seiha Date: Fri, 11 Sep 2020 16:05:03 +0200 Subject: [PATCH] cmake: update samples and examples management --- CMakeLists.txt | 19 ++++++- examples/contrib/CMakeLists.txt | 54 ++++++++++++------- examples/cpp/CMakeLists.txt | 28 ++++------ examples/dotnet/CMakeLists.txt | 4 ++ examples/java/CMakeLists.txt | 4 ++ examples/python/CMakeLists.txt | 4 ++ ortools/algorithms/samples/CMakeLists.txt | 9 ++-- .../constraint_solver/samples/CMakeLists.txt | 9 ++-- ortools/graph/samples/CMakeLists.txt | 9 ++-- ortools/linear_solver/samples/CMakeLists.txt | 9 ++-- ortools/sat/samples/CMakeLists.txt | 9 ++-- 11 files changed, 99 insertions(+), 59 deletions(-) create mode 100644 examples/dotnet/CMakeLists.txt create mode 100644 examples/java/CMakeLists.txt create mode 100644 examples/python/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index bd04ab7dd3..2fdc7f7d28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,11 +104,29 @@ if(BUILD_PYTHON OR BUILD_JAVA OR BUILD_DOTNET) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) endif() +include(CMakeDependentOption) option(BUILD_SAMPLES "Build samples" ON) message(STATUS "Build samples: ${BUILD_SAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_CXX_SAMPLES "Build cxx samples" ON "BUILD_SAMPLES;BUILD_CXX" OFF) +message(STATUS "Build C++ samples: ${BUILD_CXX_SAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_PYTHON_SAMPLES "Build python samples" ON "BUILD_SAMPLES;BUILD_PYTHON" OFF) +message(STATUS "Build Python samples: ${BUILD_PYTHON_SAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_JAVA_SAMPLES "Build java samples" ON "BUILD_SAMPLES;BUILD_JAVA" OFF) +message(STATUS "Build Java samples: ${BUILD_JAVA_SAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_DOTNET_SAMPLES "Build dotnet samples" ON "BUILD_SAMPLES;BUILD_DOTNET" OFF) +message(STATUS "Build .Net samples: ${BUILD_DOTNET_SAMPLES}") + option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_CXX_EXAMPLES "Build cxx samples" ON "BUILD_EXAMPLES;BUILD_CXX" OFF) +message(STATUS "Build C++ samples: ${BUILD_CXX_EXAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_PYTHON_EXAMPLES "Build python samples" ON "BUILD_EXAMPLES;BUILD_PYTHON" OFF) +message(STATUS "Build Python samples: ${BUILD_PYTHON_EXAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_JAVA_EXAMPLES "Build java samples" ON "BUILD_EXAMPLES;BUILD_JAVA" OFF) +message(STATUS "Build Java samples: ${BUILD_JAVA_EXAMPLES}") +CMAKE_DEPENDENT_OPTION(BUILD_DOTNET_EXAMPLES "Build dotnet samples" ON "BUILD_EXAMPLES;BUILD_DOTNET" OFF) +message(STATUS "Build .Net samples: ${BUILD_DOTNET_EXAMPLES}") #option(BUILD_DOC "Build doxygen" OFF) #message(STATUS "Build doxygen: ${BUILD_DOC}") @@ -125,7 +143,6 @@ message(STATUS "Build all dependencies: ${BUILD_DEPS}") option(INSTALL_BUILD_DEPS "Install build all dependencies" ON) # IF BUILD_DEPS=ON THEN Force all BUILD_*=ON -include(CMakeDependentOption) CMAKE_DEPENDENT_OPTION(BUILD_ZLIB "Build the ZLIB dependency Library" OFF "NOT BUILD_DEPS" ON) message(STATUS "Build ZLIB: ${BUILD_ZLIB}") diff --git a/examples/contrib/CMakeLists.txt b/examples/contrib/CMakeLists.txt index 4793d0a0b7..be47cb4a80 100644 --- a/examples/contrib/CMakeLists.txt +++ b/examples/contrib/CMakeLists.txt @@ -1,23 +1,37 @@ -if (NOT BUILD_PYTHON) - return() +if (NOT BUILD_EXAMPLES) + return() endif() -foreach(TEST IN ITEMS - hidato_table - integer_programming - knapsack - linear_programming - pyflow_example - tsp - vrp - vrpgs - cvrp - cvrptw) - add_test(py${TEST}_venv ${VENV_BIN_DIR}/python ${CMAKE_CURRENT_SOURCE_DIR}/${TEST}.py) - set_tests_properties(py${TEST}_venv PROPERTIES DEPENDS build_venv) -endforeach() +if(BUILD_CXX_EXAMPLES) -include(GNUInstallDirs) -install(DIRECTORY . - DESTINATION ${CMAKE_INSTALL_DATADIR}/ortools/examples/python - FILES_MATCHING PATTERN "*.py") +endif() + +if(BUILD_PYTHON) + foreach(TEST IN ITEMS + hidato_table + integer_programming + knapsack + linear_programming + pyflow_example + tsp + vrp + vrpgs + cvrp + cvrptw) + add_test(py${TEST}_venv ${VENV_BIN_DIR}/python ${CMAKE_CURRENT_SOURCE_DIR}/${TEST}.py) + set_tests_properties(py${TEST}_venv PROPERTIES DEPENDS build_venv) + endforeach() + + include(GNUInstallDirs) + install(DIRECTORY . + DESTINATION ${CMAKE_INSTALL_DATADIR}/ortools/examples/python + FILES_MATCHING PATTERN "*.py") +endif() + +if(BUILD_JAVA_EXAMPLES) + +endif() + +if(BUILD_DOTNET_EXAMPLES) + +endif() diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 5612fc6dc2..504916de5b 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -1,21 +1,16 @@ -if (NOT BUILD_CXX) +if(NOT BUILD_CXX_EXAMPLES) return() endif() -project(ortools_examples) - -if (APPLE) +if(APPLE) set(CMAKE_INSTALL_RPATH - "@loader_path/../..;@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") -else() - set(CMAKE_INSTALL_RPATH "$ORIGIN/../../:$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/") + "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") +elseif(UNIX) + set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN") endif() -get_filename_component(PARENT_SOURCE_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) - include(GNUInstallDirs) - -foreach(EXECUTABLE +foreach(EXECUTABLE IN ITEMS constraint_programming_cp costas_array_sat cvrp_disjoint_tw @@ -52,16 +47,13 @@ foreach(EXECUTABLE variable_intervals_sat weighted_tardiness_sat) add_executable(${EXECUTABLE} ${EXECUTABLE}.cc) - target_include_directories(${EXECUTABLE} PUBLIC ${PARENT_SOURCE_DIR}) + target_include_directories(${EXECUTABLE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(${EXECUTABLE} PRIVATE cxx_std_17) target_link_libraries(${EXECUTABLE} PRIVATE ortools::ortools) - set_target_properties(${EXECUTABLE} PROPERTIES - INSTALL_RPATH_USE_LINK_PATH TRUE) - install(TARGETS ${EXECUTABLE} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(TARGETS ${EXECUTABLE}) endforeach() -foreach(TEST +foreach(TEST IN ITEMS costas_array_sat cvrp_disjoint_tw cvrptw @@ -95,5 +87,5 @@ foreach(TEST #variable_intervals_sat #weighted_tardiness_sat ) - add_test(NAME cc_${TEST} COMMAND ${TEST}) + add_test(NAME cxx_${TEST} COMMAND ${TEST}) endforeach() diff --git a/examples/dotnet/CMakeLists.txt b/examples/dotnet/CMakeLists.txt new file mode 100644 index 0000000000..649896d31f --- /dev/null +++ b/examples/dotnet/CMakeLists.txt @@ -0,0 +1,4 @@ +if(NOT BUILD_DOTNET_EXAMPLES) + return() +endif() + diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt new file mode 100644 index 0000000000..36fef4dfef --- /dev/null +++ b/examples/java/CMakeLists.txt @@ -0,0 +1,4 @@ +if(NOT BUILD_JAVA_EXAMPLES) + return() +endif() + diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt new file mode 100644 index 0000000000..47557c7ed6 --- /dev/null +++ b/examples/python/CMakeLists.txt @@ -0,0 +1,4 @@ +if(NOT BUILD_PYTHON_EXAMPLES) + return() +endif() + diff --git a/ortools/algorithms/samples/CMakeLists.txt b/ortools/algorithms/samples/CMakeLists.txt index 5d475083f6..a243af671f 100644 --- a/ortools/algorithms/samples/CMakeLists.txt +++ b/ortools/algorithms/samples/CMakeLists.txt @@ -2,7 +2,7 @@ if(NOT BUILD_SAMPLES) return() endif() -if(BUILD_CXX) +if(BUILD_CXX_SAMPLES) if(APPLE) set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") @@ -17,17 +17,18 @@ if(BUILD_CXX) target_compile_features(${EXECUTABLE} PRIVATE cxx_std_17) target_link_libraries(${EXECUTABLE} PRIVATE ortools::ortools) install(TARGETS ${EXECUTABLE}) + add_test(NAME cxx_${EXECUTABLE} COMMAND ${EXECUTABLE}) endforeach() endif() -if(BUILD_PYTHON) +if(BUILD_PYTHON_SAMPLES) endif() -if(BUILD_JAVA) +if(BUILD_JAVA_SAMPLES) endif() -if(BUILD_DOTNET) +if(BUILD_DOTNET_SAMPLES) endif() diff --git a/ortools/constraint_solver/samples/CMakeLists.txt b/ortools/constraint_solver/samples/CMakeLists.txt index 5e81983703..20de39ff85 100644 --- a/ortools/constraint_solver/samples/CMakeLists.txt +++ b/ortools/constraint_solver/samples/CMakeLists.txt @@ -2,7 +2,7 @@ if(NOT BUILD_SAMPLES) return() endif() -if(BUILD_CXX) +if(BUILD_CXX_SAMPLES) if(APPLE) set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") @@ -40,17 +40,18 @@ if(BUILD_CXX) target_compile_features(${EXECUTABLE} PRIVATE cxx_std_17) target_link_libraries(${EXECUTABLE} PRIVATE ortools::ortools) install(TARGETS ${EXECUTABLE}) + add_test(NAME cxx_${EXECUTABLE} COMMAND ${EXECUTABLE}) endforeach() endif() -if(BUILD_PYTHON) +if(BUILD_PYTHON_SAMPLES) endif() -if(BUILD_JAVA) +if(BUILD_JAVA_SAMPLES) endif() -if(BUILD_DOTNET) +if(BUILD_DOTNET_SAMPLES) endif() diff --git a/ortools/graph/samples/CMakeLists.txt b/ortools/graph/samples/CMakeLists.txt index b433f0c7b3..31bd1d5772 100644 --- a/ortools/graph/samples/CMakeLists.txt +++ b/ortools/graph/samples/CMakeLists.txt @@ -2,7 +2,7 @@ if(NOT BUILD_SAMPLES) return() endif() -if(BUILD_CXX) +if(BUILD_CXX_SAMPLES) if(APPLE) set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") @@ -18,17 +18,18 @@ if(BUILD_CXX) target_compile_features(${EXECUTABLE} PRIVATE cxx_std_17) target_link_libraries(${EXECUTABLE} PRIVATE ortools::ortools) install(TARGETS ${EXECUTABLE}) + add_test(NAME cxx_${EXECUTABLE} COMMAND ${EXECUTABLE}) endforeach() endif() -if(BUILD_PYTHON) +if(BUILD_PYTHON_SAMPLES) endif() -if(BUILD_JAVA) +if(BUILD_JAVA_SAMPLES) endif() -if(BUILD_DOTNET) +if(BUILD_DOTNET_SAMPLES) endif() diff --git a/ortools/linear_solver/samples/CMakeLists.txt b/ortools/linear_solver/samples/CMakeLists.txt index 1a1553ec27..97b8e15570 100644 --- a/ortools/linear_solver/samples/CMakeLists.txt +++ b/ortools/linear_solver/samples/CMakeLists.txt @@ -2,7 +2,7 @@ if(NOT BUILD_SAMPLES) return() endif() -if(BUILD_CXX) +if(BUILD_CXX_SAMPLES) if(APPLE) set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") @@ -26,17 +26,18 @@ if(BUILD_CXX) target_compile_features(${EXECUTABLE} PRIVATE cxx_std_17) target_link_libraries(${EXECUTABLE} PRIVATE ortools::ortools) install(TARGETS ${EXECUTABLE}) + add_test(NAME cxx_${EXECUTABLE} COMMAND ${EXECUTABLE}) endforeach() endif() -if(BUILD_PYTHON) +if(BUILD_PYTHON_SAMPLES) endif() -if(BUILD_JAVA) +if(BUILD_JAVA_SAMPLES) endif() -if(BUILD_DOTNET) +if(BUILD_DOTNET_SAMPLES) endif() diff --git a/ortools/sat/samples/CMakeLists.txt b/ortools/sat/samples/CMakeLists.txt index ad6c83b427..16795ebd98 100644 --- a/ortools/sat/samples/CMakeLists.txt +++ b/ortools/sat/samples/CMakeLists.txt @@ -2,7 +2,7 @@ if(NOT BUILD_SAMPLES) return() endif() -if(BUILD_CXX) +if(BUILD_CXX_SAMPLES) if(APPLE) set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") @@ -39,17 +39,18 @@ if(BUILD_CXX) target_compile_features(${EXECUTABLE} PRIVATE cxx_std_17) target_link_libraries(${EXECUTABLE} PRIVATE ortools::ortools) install(TARGETS ${EXECUTABLE}) + add_test(NAME cxx_${EXECUTABLE} COMMAND ${EXECUTABLE}) endforeach() endif() -if(BUILD_PYTHON) +if(BUILD_PYTHON_SAMPLES) endif() -if(BUILD_JAVA) +if(BUILD_JAVA_SAMPLES) endif() -if(BUILD_DOTNET) +if(BUILD_DOTNET_SAMPLES) endif()