summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2018-11-22 11:35:17 +0100
committerTobias Hunger <tobias.hunger@qt.io>2018-11-22 12:45:35 +0000
commitc68e5fc59ba8f0fd8b782a37df20ab9b7d7ecafa (patch)
tree4295a444826c3ca4be6fa895ed15a55ea38e42f8 /cmake
parentbdb5e2a48ea206005eaa8305b7517b2843f2aba1 (diff)
CMake: Add macro to generate cmake build-only tests
In addition to cmake tests that run cmake, build and then run the tests of that project, also add a macro for tests that only run cmake. Use this new kind of test for the existing tests. Change-Id: I465600974ed4114e724988b309404ccd3db2e0cb Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/tests/CMakeLists.txt58
-rw-r--r--cmake/tests/features/CMakeLists.txt2
-rw-r--r--cmake/tests/qt_make_output_file/CMakeLists.txt2
3 files changed, 40 insertions, 22 deletions
diff --git a/cmake/tests/CMakeLists.txt b/cmake/tests/CMakeLists.txt
index c7f7baafe1..6b53c9703d 100644
--- a/cmake/tests/CMakeLists.txt
+++ b/cmake/tests/CMakeLists.txt
@@ -1,26 +1,48 @@
-# These macros are taken from the ECM:
+# These macros are inspired by ECM:
# a macro for tests that have a simple format where the name matches the
# directory and project
-macro(add_test_variant NAME BASE COMMAND)
- string(REPLACE "." "/" src_dir "${BASE}")
- string(REPLACE "." "/" build_dir "${NAME}")
- string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}")
- add_test("cmake_${NAME}" ${CMAKE_CTEST_COMMAND}
- --build-and-test
+
+# The following macros will produce tests that generate the build
+# system for the test project, build it and then run its tests.
+macro(add_cmake_test_generate_build_run_variant name base command)
+ string(REPLACE "." "/" src_dir "${base}")
+ string(REPLACE "." "/" build_dir "${name}")
+ string(REGEX REPLACE "[^.]*\\." "" proj "${name}")
+ add_test(NAME "cmake_${name}"
+ COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMAKE_CURRENT_SOURCE_DIR}/${src_dir}"
+ "${CMAKE_CURRENT_BINARY_DIR}/${build_dir}"
+ --build-two-config
+ --build-generator ${CMAKE_GENERATOR}
+ --build-makeprogram ${CMAKE_MAKE_PROGRAM}
+ --build-project ${proj}
+ ${${name}_EXTRA_OPTIONS}
+ --test-command ${command} ${ARGN})
+endmacro()
+
+macro(add_cmake_test_generate_build_run name)
+ add_cmake_test_generate_build_run_variant("${name}" "${name}" ${ARGN})
+endmacro()
+
+# The following macros will produce tests that just run cmake
+# to generate the build system for the test project.
+macro(add_cmake_test_generate_variant name base)
+ string(REPLACE "." "/" src_dir "${base}")
+ string(REPLACE "." "/" build_dir "${name}")
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${build_dir}")
+ add_test(NAME "cmake_${name}"
+ COMMAND "${CMAKE_COMMAND}" "-G${CMAKE_GENERATOR}"
+ "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
+ ${${name}_EXTRA_OPTIONS}
"${CMAKE_CURRENT_SOURCE_DIR}/${src_dir}"
- "${CMAKE_CURRENT_BINARY_DIR}/${build_dir}"
- --build-two-config
- --build-generator ${CMAKE_GENERATOR}
- --build-makeprogram ${CMAKE_MAKE_PROGRAM}
- --build-project ${proj}
- ${${NAME}_EXTRA_OPTIONS}
- --test-command ${COMMAND} ${ARGN})
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${build_dir}")
endmacro()
-macro(add_test_macro NAME)
- add_test_variant("${NAME}" "${NAME}" ${ARGN})
+macro(add_cmake_test_generate name)
+ add_cmake_test_generate_variant("${name}" "${name}")
endmacro()
-add_test_macro(features features)
-add_test_macro(qt_make_output_file qt_make_output_file)
+add_cmake_test_generate(features)
+add_cmake_test_generate(qt_make_output_file)
diff --git a/cmake/tests/features/CMakeLists.txt b/cmake/tests/features/CMakeLists.txt
index e255b209c9..3cda8ebe26 100644
--- a/cmake/tests/features/CMakeLists.txt
+++ b/cmake/tests/features/CMakeLists.txt
@@ -40,5 +40,3 @@ include(QtPostProcess)
## Print a feature summary:
feature_summary(WHAT PACKAGES_FOUND PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)
-
-add_executable(features ../main.cpp)
diff --git a/cmake/tests/qt_make_output_file/CMakeLists.txt b/cmake/tests/qt_make_output_file/CMakeLists.txt
index d66579f514..3620909494 100644
--- a/cmake/tests/qt_make_output_file/CMakeLists.txt
+++ b/cmake/tests/qt_make_output_file/CMakeLists.txt
@@ -20,5 +20,3 @@ assert(outfile STREQUAL "/tmp/bar/__/prefix_foo.cpp")
qt_make_output_file("/tmp/bar/foo.cpp" "prefix_" ".cpp" "/tmp/foo" "/tmp/bar" outfile)
assert(outfile STREQUAL "/tmp/bar/prefix_foo.cpp")
-
-add_executable(qt_make_output_file ../main.cpp)