From f37ce9ab84400a45752787b9e015a7919c8771bd Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 14 Nov 2018 13:37:52 +0100 Subject: [PATCH] CMake: Add option to run cmake build tests Use "cmake -DBUILD_CMAKE_TESTING=ON" to enable running cmake build system tests with ctest. Change-Id: I0a32e2d1771c9bbb0df013d0d955a9b58b1d4b79 Reviewed-by: Frederik Gladhorn --- CMakeLists.txt | 3 +++ cmake/QtBaseCMakeTesting.cmake | 9 +++++++++ cmake/tests/CMakeLists.txt | 25 +++++++++++++++++++++++++ cmake/tests/features/CMakeLists.txt | 2 ++ cmake/tests/main.cpp | 1 + 5 files changed, 40 insertions(+) create mode 100644 cmake/QtBaseCMakeTesting.cmake create mode 100644 cmake/tests/CMakeLists.txt create mode 100644 cmake/tests/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e9b1293843e..622cc5e00bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ include(FeatureSummary) ## QtBase specific configure tests: include(QtBaseConfigureTests) +## Build System tests: +include(QtBaseCMakeTesting) + ## Targets for global features, etc.: include(QtBaseGlobalTargets) diff --git a/cmake/QtBaseCMakeTesting.cmake b/cmake/QtBaseCMakeTesting.cmake new file mode 100644 index 00000000000..662ac8f4986 --- /dev/null +++ b/cmake/QtBaseCMakeTesting.cmake @@ -0,0 +1,9 @@ +## Test the cmake build system: +option(BUILD_CMAKE_TESTING "Build tests for the Qt build system" OFF) +mark_as_advanced(BUILD_CMAKE_TESTING) + +if(BUILD_CMAKE_TESTING) + add_subdirectory("${PROJECT_SOURCE_DIR}/cmake/tests") +endif() + + diff --git a/cmake/tests/CMakeLists.txt b/cmake/tests/CMakeLists.txt new file mode 100644 index 00000000000..28568ce46f2 --- /dev/null +++ b/cmake/tests/CMakeLists.txt @@ -0,0 +1,25 @@ +# These macros are taken from the 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 + "${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_test_macro NAME) + add_test_variant("${NAME}" "${NAME}" ${ARGN}) +endmacro() + +add_test_macro(features features) diff --git a/cmake/tests/features/CMakeLists.txt b/cmake/tests/features/CMakeLists.txt index 0208e3d890e..7b76a4529fe 100644 --- a/cmake/tests/features/CMakeLists.txt +++ b/cmake/tests/features/CMakeLists.txt @@ -40,3 +40,5 @@ 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/main.cpp b/cmake/tests/main.cpp new file mode 100644 index 00000000000..a9b87389901 --- /dev/null +++ b/cmake/tests/main.cpp @@ -0,0 +1 @@ +int main(int argc, char** argv) { return 0; }