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 <frederik.gladhorn@qt.io>
This commit is contained in:
parent
3acebfe6eb
commit
f37ce9ab84
@ -23,6 +23,9 @@ include(FeatureSummary)
|
|||||||
## QtBase specific configure tests:
|
## QtBase specific configure tests:
|
||||||
include(QtBaseConfigureTests)
|
include(QtBaseConfigureTests)
|
||||||
|
|
||||||
|
## Build System tests:
|
||||||
|
include(QtBaseCMakeTesting)
|
||||||
|
|
||||||
## Targets for global features, etc.:
|
## Targets for global features, etc.:
|
||||||
include(QtBaseGlobalTargets)
|
include(QtBaseGlobalTargets)
|
||||||
|
|
||||||
|
9
cmake/QtBaseCMakeTesting.cmake
Normal file
9
cmake/QtBaseCMakeTesting.cmake
Normal file
@ -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()
|
||||||
|
|
||||||
|
|
25
cmake/tests/CMakeLists.txt
Normal file
25
cmake/tests/CMakeLists.txt
Normal file
@ -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)
|
@ -40,3 +40,5 @@ include(QtPostProcess)
|
|||||||
|
|
||||||
## Print a feature summary:
|
## Print a feature summary:
|
||||||
feature_summary(WHAT PACKAGES_FOUND PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
feature_summary(WHAT PACKAGES_FOUND PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||||
|
|
||||||
|
add_executable(features ../main.cpp)
|
||||||
|
1
cmake/tests/main.cpp
Normal file
1
cmake/tests/main.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
int main(int argc, char** argv) { return 0; }
|
Loading…
x
Reference in New Issue
Block a user