diff options
Diffstat (limited to 'cmake/tests')
-rw-r--r-- | cmake/tests/CMakeLists.txt | 48 | ||||
-rw-r--r-- | cmake/tests/empty.cpp | 0 | ||||
-rw-r--r-- | cmake/tests/features/CMakeLists.txt | 42 | ||||
-rw-r--r-- | cmake/tests/features/configure.cmake | 35 | ||||
-rw-r--r-- | cmake/tests/features/src/CMakeLists.txt | 7 | ||||
-rw-r--r-- | cmake/tests/main.cpp | 1 | ||||
-rw-r--r-- | cmake/tests/qt_make_output_file/CMakeLists.txt | 22 | ||||
-rw-r--r-- | cmake/tests/test.cmake | 54 |
8 files changed, 209 insertions, 0 deletions
diff --git a/cmake/tests/CMakeLists.txt b/cmake/tests/CMakeLists.txt new file mode 100644 index 0000000000..6b53c9703d --- /dev/null +++ b/cmake/tests/CMakeLists.txt @@ -0,0 +1,48 @@ +# These macros are inspired by ECM: + +# a macro for tests that have a simple format where the name matches the +# directory and project + +# 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}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${build_dir}") +endmacro() + +macro(add_cmake_test_generate name) + add_cmake_test_generate_variant("${name}" "${name}") +endmacro() + +add_cmake_test_generate(features) +add_cmake_test_generate(qt_make_output_file) diff --git a/cmake/tests/empty.cpp b/cmake/tests/empty.cpp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/cmake/tests/empty.cpp diff --git a/cmake/tests/features/CMakeLists.txt b/cmake/tests/features/CMakeLists.txt new file mode 100644 index 0000000000..0fff2b8be9 --- /dev/null +++ b/cmake/tests/features/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.12.0) + +project(FeaturesTest + VERSION 1.0.0 + DESCRIPTION "QtFeature test" + HOMEPAGE_URL "https://qt.io/" + LANGUAGES CXX C +) + +## Add some paths to check for cmake modules: +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/extra-cmake-modules/find-modules;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/kwin") + +## Qt specific setup common for all modules: +include(QtSetup) + +## Library to hold global features: +add_library(GlobalConfig INTERFACE) + +qt_feature_module_begin(LIBRARY GlobalConfig + PUBLIC_FILE src/corelib/global/qconfig.h + PRIVATE_FILE src/corelib/global/qconfig_p.h +) +include("${CMAKE_CURRENT_SOURCE_DIR}/configure.cmake") +qt_feature_module_end(GlobalConfig) + +assert(QT_FEATURE_top_a STREQUAL "ON") +assert(QT_FEATURE_top_b STREQUAL "OFF") +assert(QT_FEATURE_top_enabled STREQUAL "ON") +assert(QT_FEATURE_top_disabled STREQUAL "OFF") +assert(QT_FEATURE_top_disabled_enabled STREQUAL "OFF") +assert(QT_FEATURE_top_not_emitted STREQUAL "OFF") + +## Enable feature summary at the end of the configure run: +include(FeatureSummary) + +add_subdirectory(src) + +## Delayed actions on some of the Qt targets: +include(QtPostProcess) + +## Print a feature summary: +feature_summary(WHAT PACKAGES_FOUND PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/cmake/tests/features/configure.cmake b/cmake/tests/features/configure.cmake new file mode 100644 index 0000000000..ace2b62450 --- /dev/null +++ b/cmake/tests/features/configure.cmake @@ -0,0 +1,35 @@ +#### Features + +# This belongs into gui, but the license check needs it here already. +qt_feature("top_a" PRIVATE + LABEL "top_a" + CONDITION ON +) +qt_feature("top_b" PUBLIC PRIVATE + LABEL "top_b" + AUTODETECT OFF +) +qt_feature_definition("top_a" "top_defa") + +qt_feature("top_enabled" PRIVATE + LABEL "top_enabled" + ENABLE ON +) + +qt_feature("top_disabled" PRIVATE + LABEL "top_enabled" + DISABLE ON +) + +qt_feature("top_disabled_enabled" PRIVATE + LABEL "top_enabled_enabled" + DISABLE ON + ENABLE ON +) + +qt_feature("top_not_emitted" PRIVATE + LABEL "top_not_emitted" + EMIT_IF OFF +) + +qt_extra_definition("top_extra" "PUBLIC_FOO" PUBLIC) diff --git a/cmake/tests/features/src/CMakeLists.txt b/cmake/tests/features/src/CMakeLists.txt new file mode 100644 index 0000000000..bfb02be07d --- /dev/null +++ b/cmake/tests/features/src/CMakeLists.txt @@ -0,0 +1,7 @@ +## Features from parent scope were inherited: +assert(QT_FEATURE_top_a STREQUAL "ON") +assert(QT_FEATURE_top_b STREQUAL "OFF") +assert(QT_FEATURE_top_enabled STREQUAL "ON") +assert(QT_FEATURE_top_disabled STREQUAL "OFF") +assert(QT_FEATURE_top_disabled_enabled STREQUAL "OFF") +assert(QT_FEATURE_top_not_emitted STREQUAL "OFF") diff --git a/cmake/tests/main.cpp b/cmake/tests/main.cpp new file mode 100644 index 0000000000..a9b8738990 --- /dev/null +++ b/cmake/tests/main.cpp @@ -0,0 +1 @@ +int main(int argc, char** argv) { return 0; } diff --git a/cmake/tests/qt_make_output_file/CMakeLists.txt b/cmake/tests/qt_make_output_file/CMakeLists.txt new file mode 100644 index 0000000000..3620909494 --- /dev/null +++ b/cmake/tests/qt_make_output_file/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.12.0) + +project(QtMakeOutputFileTest + VERSION 1.0.0 + DESCRIPTION "qt_make_output_file test" + HOMEPAGE_URL "https://qt.io/" + LANGUAGES CXX C +) + +## Add some paths to check for cmake modules: +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/extra-cmake-modules/find-modules;${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/kwin") + +include(QtBuild) + +qt_make_output_file("foo.cpp" "" ".mapped" "/tmp/foo" "/tmp/bar" outfile) +assert(outfile STREQUAL "/tmp/bar/foo.mapped") + +qt_make_output_file("../foo.cpp" "prefix_" ".cpp" "/tmp/foo" "/tmp/bar" outfile) +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") diff --git a/cmake/tests/test.cmake b/cmake/tests/test.cmake new file mode 100644 index 0000000000..099f490c94 --- /dev/null +++ b/cmake/tests/test.cmake @@ -0,0 +1,54 @@ +# FAKE moc-ing: +set(QT_MOCSCANNER /usr/bin/true) + +# Fake mocscanner run. +# The files passed in after MOC will be reported to be in need of moc-ing, +# but will not be built. +# The files passed in after MOC_AND_BUILD will be reported to be in need +# of moc-ing and should also be built by the target. +function(fake_moc_results) + cmake_parse_arguments(arg "" "" "MOC;MOC_AND_BUILD" ${ARGN}) + + string(REPLACE ";" "\n" arg_MOC "${arg_MOC}") + string(REPLACE ";" "\n" arg_MOC_AND_BUILD "${arg_MOC_AND_BUILD}") + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_included.txt" "${arg_MOC}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/moc_files_to_build.txt" "${arg_MOC_AND_BUILD}") +endfunction() + +# Test whether a target has a file listed in its sources. +# Tests with the BUILD flag set will require this file to be built, +# while those without will require the file to not be built by +# the target. +function(test_source_file target file) + cmake_parse_arguments(arg "BUILD" "" "" ${ARGN}) + + get_target_property(sources "${target}" SOURCES) + list(FIND sources "${file}" source_pos) + assert(NOT source_pos STREQUAL "-1") + + get_source_file_property(prop "${file}" HEADER_FILE_ONLY) + if (arg_BUILD) + assert(NOT prop) + else() + assert(prop) + endif() +endfunction() + +# Test whether or not a target uses a header path +# The test passes when the path is in the list of include directories. +# Passing 'UNKNOWN' to this function reverses the test result. +function(test_include_directory target path) + cmake_parse_arguments(arg "UNKNOWN" "" "" ${ARGN}) + get_target_property(includes "${target}" INCLUDE_DIRECTORIES) + list(FIND includes "${path}" include_pos) + if(arg_UNKNOWN) + assert(include_pos STREQUAL "-1") + else() + assert(NOT include_pos STREQUAL "-1") + endif() +endfunction() + +# Add Core and Qt::Core libraries: +add_library(Core SHARED "${CMAKE_CURRENT_LIST_DIR}/empty.cpp") +add_library(Qt::Core ALIAS Core) |