From 39cb35b1345e2d3878bcde7304a1c91c0281f5c1 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 31 Oct 2017 13:06:16 +0100 Subject: [PATCH] Avoid CMake errors with CMake<=3.4 --- .../Arrangement_on_surface_2/cgal_test.cmake | 30 +++++++++++++------ CMakeLists.txt | 4 +++ Installation/CMakeLists.txt | 5 +++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake index 44d338e1a4e..9bff34826c6 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake @@ -156,18 +156,22 @@ function(cgal_arr_2_add_target exe_name source_file) target_compile_options(${name} PRIVATE ${flags}) cgal_debug_message(STATUS "# -> target ${name} with TESTSUITE_CXXFLAGS: ${flags}") - add_test(NAME "compilation_of__${name}" - COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${name}") - set_property(TEST "compilation_of__${name}" - APPEND PROPERTY LABELS "${PROJECT_NAME}") + if(BUILD_TESTING) + add_test(NAME "compilation_of__${name}" + COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${name}") + set_property(TEST "compilation_of__${name}" + APPEND PROPERTY LABELS "${PROJECT_NAME}") + endif(BUILD_TESTING) # Add a compatibility-mode with the shell script `cgal_test_base` if(NOT TARGET ${exe_name}) create_single_source_cgal_program( "${source_file}" NO_TESTING) - add_test(NAME "compilation_of__${exe_name}" - COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${exe_name}") - set_property(TEST "compilation_of__${exe_name}" - APPEND PROPERTY LABELS "${PROJECT_NAME}") + if(BUILD_TESTING) + add_test(NAME "compilation_of__${exe_name}" + COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${exe_name}") + set_property(TEST "compilation_of__${exe_name}" + APPEND PROPERTY LABELS "${PROJECT_NAME}") + endif(BUILD_TESTING) endif() endfunction() @@ -180,11 +184,17 @@ endfunction() function(run_test_with_flags) # ${ARGV0} - executable name # ${ARGV1} - test substring name + if(NOT BUILD_TESTING) + return() + endif() cgal_debug_message(STATUS "# run_test_with_flags(${ARGN})") cgal_add_test(${ARGV0}_${suffix} ${ARGV0} ${ARGV0}.${ARGV1}) endfunction() function(run_test_alt name datafile) + if(NOT BUILD_TESTING) + return() + endif() if(suffix) set(name ${name}_${suffix}) endif() @@ -220,7 +230,9 @@ function(compile_and_run) cgal_debug_message(STATUS "# compile_and_run(${ARGN})") # message(" successful compilation of ${name}") cgal_arr_2_add_target(${name} ${name}.cpp) - cgal_add_test(${name}) + if(BUILD_TESTING) + cgal_add_test(${name}) + endif() endfunction() function(execute_commands_old_structure data_dir traits_type_name) diff --git a/CMakeLists.txt b/CMakeLists.txt index d36a83c631f..6c702f30227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,10 @@ message( "== CMake setup (DONE) ==\n" ) # Enable testing with BUILD_TESTING option(BUILD_TESTING "Build the testing tree." OFF) include(CTest) +if(BUILD_TESTING AND NOT POLICY CMP0064) + message(FATAL_ERROR "CGAL support of CTest requires CMake version 3.4 or later. +The variable BUILD_TESTING must be set of OFF.") +endif() # and finally start actual build add_subdirectory( Installation ) diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index 3d262b07bf5..89e4a61c5f3 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -135,7 +135,10 @@ else ( CGAL_BRANCH_BUILD ) # Enable testing with BUILD_TESTING option(BUILD_TESTING "Build the testing tree." OFF) include(CTest) - + if(BUILD_TESTING AND NOT POLICY CMP0064) + message(FATAL_ERROR "CGAL support of CTest requires CMake version 3.4 or later. +The variable BUILD_TESTING must be set of OFF.") + endif() endif (CGAL_BRANCH_BUILD ) #message(STATUS "Packages found: ${CGAL_CONFIGURED_PACKAGES}")