diff options
Diffstat (limited to 'Tests/RunCMake')
29 files changed, 359 insertions, 125 deletions
diff --git a/Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake b/Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake index 8fa6041..6d26f99 100644 --- a/Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake +++ b/Tests/RunCMake/Autogen/CMP0111-imported-target-prelude.cmake @@ -1,6 +1,6 @@ enable_language(CXX) -find_package(Qt5 REQUIRED COMPONENTS Core) +find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core) # Detect `-NOTFOUND` libraries at generate time. cmake_policy(SET CMP0111 NEW) diff --git a/Tests/RunCMake/Autogen/CMakeLists.txt b/Tests/RunCMake/Autogen/CMakeLists.txt index 9a66cde..2632ffa 100644 --- a/Tests/RunCMake/Autogen/CMakeLists.txt +++ b/Tests/RunCMake/Autogen/CMakeLists.txt @@ -1,3 +1,3 @@ -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.16) project(${RunCMake_TEST} NONE) include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/Autogen/QtInFunction.cmake b/Tests/RunCMake/Autogen/QtInFunction.cmake index a44bc5a..6c42cc2 100644 --- a/Tests/RunCMake/Autogen/QtInFunction.cmake +++ b/Tests/RunCMake/Autogen/QtInFunction.cmake @@ -1,9 +1,9 @@ enable_language(CXX) function (use_autogen target) - find_package(Qt5 REQUIRED COMPONENTS Core Widgets) - set(Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}" PARENT_SCOPE) - set(Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MINOR}" PARENT_SCOPE) + find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets) + set(Qt${with_qt_version}Core_VERSION_MAJOR "${Qt${with_qt_version}Core_VERSION_MAJOR}" PARENT_SCOPE) + set(Qt${with_qt_version}Core_VERSION_MINOR "${Qt${with_qt_version}Core_VERSION_MINOR}" PARENT_SCOPE) set_property(TARGET "${target}" PROPERTY AUTOMOC 1) set_property(TARGET "${target}" PROPERTY AUTORCC 1) set_property(TARGET "${target}" PROPERTY AUTOUIC 1) diff --git a/Tests/RunCMake/Autogen/QtInFunctionNested.cmake b/Tests/RunCMake/Autogen/QtInFunctionNested.cmake index 5421ba0..2e7b8ad 100644 --- a/Tests/RunCMake/Autogen/QtInFunctionNested.cmake +++ b/Tests/RunCMake/Autogen/QtInFunctionNested.cmake @@ -1,9 +1,9 @@ enable_language(CXX) function (use_autogen target) - find_package(Qt5 REQUIRED COMPONENTS Core Widgets) - set(Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}" PARENT_SCOPE) - set(Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MINOR}" PARENT_SCOPE) + find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets) + set(Qt${with_qt_version}Core_VERSION_MAJOR "${Qt${with_qt_version}Core_VERSION_MAJOR}" PARENT_SCOPE) + set(Qt${with_qt_version}Core_VERSION_MINOR "${Qt${with_qt_version}Core_VERSION_MINOR}" PARENT_SCOPE) set_property(TARGET "${target}" PROPERTY AUTOMOC 1) set_property(TARGET "${target}" PROPERTY AUTORCC 1) set_property(TARGET "${target}" PROPERTY AUTOUIC 1) diff --git a/Tests/RunCMake/Autogen/QtInFunctionProperty.cmake b/Tests/RunCMake/Autogen/QtInFunctionProperty.cmake index 35f1cd1..d9296c4 100644 --- a/Tests/RunCMake/Autogen/QtInFunctionProperty.cmake +++ b/Tests/RunCMake/Autogen/QtInFunctionProperty.cmake @@ -1,13 +1,13 @@ enable_language(CXX) function (use_autogen target) - find_package(Qt5 REQUIRED COMPONENTS Core Widgets) + find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets) set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY - Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}") + Qt${with_qt_version}Core_VERSION_MAJOR "${Qt${with_qt_version}Core_VERSION_MAJOR}") set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY - Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MINOR}") + Qt${with_qt_version}Core_VERSION_MINOR "${Qt${with_qt_version}Core_VERSION_MINOR}") set_property(TARGET "${target}" PROPERTY AUTOMOC 1) set_property(TARGET "${target}" PROPERTY AUTORCC 1) set_property(TARGET "${target}" PROPERTY AUTOUIC 1) diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index bbcbd5e..e4c5811 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -1,7 +1,13 @@ include(RunCMake) run_cmake(NoQt) -if (with_qt5) +if (DEFINED with_qt_version) + set(RunCMake_TEST_OPTIONS + -Dwith_qt_version=${with_qt_version} + "-DQt${with_qt_version}_DIR:PATH=${Qt${with_qt_version}_DIR}" + "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}" + ) + run_cmake(QtInFunction) run_cmake(QtInFunctionNested) run_cmake(QtInFunctionProperty) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index eb2c2d9..b7d38fb 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -151,8 +151,23 @@ endif() if(CMAKE_GENERATOR MATCHES "Make") add_RunCMake_test(Make -DMAKE_IS_GNU=${MAKE_IS_GNU}) endif() -if(CMake_TEST_Qt5) +unset(ninja_test_with_qt_version) +unset(ninja_qt_args) +if(CMake_TEST_Qt6) + find_package(Qt6Widgets QUIET NO_MODULE) + if(Qt6Widgets_FOUND) + set(ninja_test_with_qt_version 6) + # Work around Qt6 not finding sibling dependencies without CMAKE_PREFIX_PATH + cmake_path(GET Qt6_DIR PARENT_PATH base_dir) # <base>/lib/cmake + cmake_path(GET base_dir PARENT_PATH base_dir) # <base>/lib + cmake_path(GET base_dir PARENT_PATH base_dir) # <base> + set(ninja_qt_args -DCMAKE_PREFIX_PATH=${base_dir}) + endif() +elseif(CMake_TEST_Qt5) find_package(Qt5Widgets QUIET NO_MODULE) + if(Qt5Widgets_FOUND) + set(ninja_test_with_qt_version 5) + endif() endif() if(CMAKE_GENERATOR MATCHES "Ninja") set(Ninja_ARGS @@ -162,18 +177,27 @@ if(CMAKE_GENERATOR MATCHES "Ninja") if(CMAKE_Fortran_COMPILER) list(APPEND Ninja_ARGS -DTEST_Fortran=1) endif() - if(CMake_TEST_Qt5 AND Qt5Core_FOUND) - list(APPEND Ninja_ARGS -DCMake_TEST_Qt5=1 -DQt5Core_DIR=${Qt5Core_DIR} -DCMAKE_TEST_Qt5Core_Version=${Qt5Core_VERSION}) - if(Qt5Widgets_FOUND) - list(APPEND Ninja_ARGS -DQt5Widgets_DIR=${Qt5Widgets_DIR}) - endif() + if(ninja_test_with_qt_version) + list(APPEND Ninja_ARGS + -DCMake_TEST_Qt_version=${ninja_test_with_qt_version} + -DQt${ninja_test_with_qt_version}_DIR=${Qt${ninja_test_with_qt_version}_DIR} + -DQt${ninja_test_with_qt_version}Core_DIR=${Qt${ninja_test_with_qt_version}Core_DIR} + -DCMake_TEST_Qt${ninja_test_with_qt_version}Core_Version=${Qt${ninja_test_with_qt_version}Core_VERSION} + -DQt${ninja_test_with_qt_version}Widgets_DIR=${Qt${ninja_test_with_qt_version}Widgets_DIR} + ${ninja_qt_args} + ) endif() add_RunCMake_test(Ninja) set(NinjaMultiConfig_ARGS -DCYGWIN=${CYGWIN} -DMSYS=${MSYS} ) - if(CMake_TEST_Qt5 AND Qt5Core_FOUND) - list(APPEND NinjaMultiConfig_ARGS -DCMake_TEST_Qt5=1 -DQt5Core_DIR=${Qt5Core_DIR} -DCMAKE_TEST_Qt5Core_Version=${Qt5Core_VERSION}) + if(ninja_test_with_qt_version) + list(APPEND NinjaMultiConfig_ARGS + -DCMake_TEST_Qt_version=${ninja_test_with_qt_version} + -DQt${ninja_test_with_qt_version}Core_DIR=${Qt${ninja_test_with_qt_version}Core_DIR} + -DCMake_TEST_Qt${ninja_test_with_qt_version}Core_Version=${Qt${ninja_test_with_qt_version}Core_VERSION} + ${ninja_qt_args} + ) endif() if(DEFINED CMake_TEST_CUDA) list(APPEND NinjaMultiConfig_ARGS -DCMake_TEST_CUDA=${CMake_TEST_CUDA}) @@ -205,11 +229,29 @@ add_RunCMake_test(AndroidTestUtilities) if(CMake_TEST_APPLE_SILICON) add_RunCMake_test(AppleSilicon) endif() -set(autogen_with_qt5 FALSE) +set(want_NoQt_test TRUE) +if(CMake_TEST_Qt6 AND Qt6Widgets_FOUND) + # Work around Qt6 not finding sibling dependencies without CMAKE_PREFIX_PATH + cmake_path(GET Qt6_DIR PARENT_PATH base_dir) # <base>/lib/cmake + cmake_path(GET base_dir PARENT_PATH base_dir) # <base>/lib + cmake_path(GET base_dir PARENT_PATH base_dir) # <base> + add_RunCMake_test(AutogenQt6 TEST_DIR Autogen + -Dwith_qt_version=6 + "-DQt6_DIR:PATH=${Qt6_DIR}" + "-DCMAKE_PREFIX_PATH:STRING=${base_dir}" + ) + set(want_NoQt_test FALSE) +endif () if(CMake_TEST_Qt5 AND Qt5Widgets_FOUND) - set(autogen_with_qt5 TRUE) + add_RunCMake_test(AutogenQt5 TEST_DIR Autogen + -Dwith_qt_version=5 + "-DQt5_DIR:PATH=${Qt5_DIR}" + ) + set(want_NoQt_test FALSE) endif () -add_RunCMake_test(Autogen -Dwith_qt5=${autogen_with_qt5}) +if(want_NoQt_test) + add_RunCMake_test(AutogenNoQt TEST_DIR Autogen) +endif() add_RunCMake_test(ArtifactOutputDirs) @@ -310,7 +352,7 @@ add_RunCMake_test(TargetProperties) add_RunCMake_test(ToolchainFile) add_RunCMake_test(find_dependency) add_RunCMake_test(CompileDefinitions) -add_RunCMake_test(CompileFeatures) +add_RunCMake_test(CompileFeatures -DCMake_NO_C_STANDARD=${CMake_NO_C_STANDARD} -DCMake_NO_CXX_STANDARD=${CMake_NO_CXX_STANDARD}) add_RunCMake_test(Policy) add_RunCMake_test(PolicyScope) add_RunCMake_test(WriteBasicConfigVersionFile) diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt new file mode 100644 index 0000000..320c2ba --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) in CMakeLists\.txt: + Policy CMP0128 is not set: Selection of language standard and extension + flags improved\. Run "cmake --help-policy CMP0128" for policy details\. Use + the cmake_policy command to set the policy and suppress this warning\. + + For compatibility with older versions of CMake, unnecessary flags for + language standard or compiler extensions may be added. +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake new file mode 100644 index 0000000..0a5606a --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake @@ -0,0 +1,7 @@ +enable_language(@lang@) +cmake_policy(SET CMP0128 OLD) +set(CMAKE_POLICY_WARNING_CMP0128 ON) + +set(CMAKE_@lang@_EXTENSIONS @extensions_default@) +set(CMAKE_@lang@_STANDARD @standard_default@) +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt new file mode 100644 index 0000000..068cba9 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) in CMakeLists\.txt: + Policy CMP0128 is not set: Selection of language standard and extension + flags improved\. Run "cmake --help-policy CMP0128" for policy details\. Use + the cmake_policy command to set the policy and suppress this warning\. + + For compatibility with older versions of CMake, compiler extensions won't + be @opposite@\. +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake new file mode 100644 index 0000000..cd7af2c --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake @@ -0,0 +1,6 @@ +enable_language(@lang@) +cmake_policy(SET CMP0128 OLD) +set(CMAKE_POLICY_WARNING_CMP0128 ON) + +set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake b/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake new file mode 100644 index 0000000..4f767fa --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake @@ -0,0 +1,8 @@ +foreach(flag @flags@) + string(FIND "${actual_stdout}" "${flag}" position) + + if(NOT position EQUAL -1) + set(RunCMake_TEST_FAILED "\"${flag}\" compile flag found.") + break() + endif() +endforeach() diff --git a/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake b/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake new file mode 100644 index 0000000..8ef3a72 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake @@ -0,0 +1,9 @@ +enable_language(@lang@) + +# Make sure the compile command is not hidden. +string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") +string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") + +set(CMAKE_@lang@_EXTENSIONS @extensions_default@) +set(CMAKE_@lang@_STANDARD @standard_default@) +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index 5a70da2..3bfd211 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -9,17 +9,8 @@ run_cmake(NotAFeature_OriginDebugGenex) run_cmake(NotAFeature_OriginDebugTransitive) run_cmake(NotAFeature_OriginDebugCommand) -run_cmake(generate_feature_list) -file(READ - "${RunCMake_BINARY_DIR}/generate_feature_list-build/c_features.txt" - C_FEATURES -) -file(READ - "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx_features.txt" - CXX_FEATURES -) -include("${RunCMake_BINARY_DIR}/generate_feature_list-build/c_standard_default.cmake") -include("${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx_standard_default.cmake") +run_cmake(compiler_introspection) +include("${RunCMake_BINARY_DIR}/compiler_introspection-build/info.cmake") if (NOT C_FEATURES) run_cmake(NoSupportedCFeatures) @@ -43,21 +34,133 @@ elseif (cxx_std_98 IN_LIST CXX_FEATURES AND cxx_std_11 IN_LIST CXX_FEATURES) unset(RunCMake_TEST_OPTIONS) endif() +configure_file("${RunCMake_SOURCE_DIR}/CMakeLists.txt" "${RunCMake_BINARY_DIR}/CMakeLists.txt" COPYONLY) + +macro(test_build) + set(test ${name}-${lang}) + + configure_file("${RunCMake_SOURCE_DIR}/${name}.cmake" "${RunCMake_BINARY_DIR}/${test}.cmake" @ONLY) + if(EXISTS "${RunCMake_SOURCE_DIR}/${name}-build-check.cmake") + configure_file("${RunCMake_SOURCE_DIR}/${name}-build-check.cmake" "${RunCMake_BINARY_DIR}/${test}-build-check.cmake" @ONLY) + endif() + if(EXISTS "${RunCMake_SOURCE_DIR}/${name}-stderr.txt") + configure_file("${RunCMake_SOURCE_DIR}/${name}-stderr.txt" "${RunCMake_BINARY_DIR}/${test}-stderr.txt" @ONLY) + endif() + + set(RunCMake_SOURCE_DIR "${RunCMake_BINARY_DIR}") + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${test}-build") + run_cmake(${test}) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(${test}-build ${CMAKE_COMMAND} --build . ${ARGN}) +endmacro() + +# Mangle flags such as they're in verbose build output. +macro(mangle_flags variable) + set(result "${${variable}}") + + if(RunCMake_GENERATOR MATCHES "Visual Studio" AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141) + string(REPLACE "-" "/" result "${result}") + elseif(RunCMake_GENERATOR STREQUAL "Xcode" AND CMAKE_XCODE_BUILD_SYSTEM GREATER_EQUAL 12) + string(REPLACE "=" [[\\=]] result "${result}") + endif() + + string(REPLACE ";" " " result "${result}") + list(APPEND flags "${result}") +endmacro() + +function(test_unset_standard) + if(extensions_opposite) + set(flag_ext "_EXT") + endif() + + set(flag "${${lang}${${lang}_STANDARD_DEFAULT}${flag_ext}_FLAG}") + + if(NOT flag) + return() + endif() + + mangle_flags(flag) + + set(name UnsetStandard) + set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0128=NEW) + test_build(--verbose) +endfunction() + +function(test_no_unnecessary_flag) + set(standard_flag "${${lang}${${lang}_STANDARD_DEFAULT}_FLAG}") + set(extension_flag "${${lang}${${lang}_STANDARD_DEFAULT}_EXT_FLAG}") + + if(NOT standard_flag AND NOT extension_flag) + return() + endif() + + mangle_flags(standard_flag) + mangle_flags(extension_flag) + + set(name NoUnnecessaryFlag) + set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0128=NEW) + test_build(--verbose) +endfunction() + +function(test_cmp0128_warn_match) + set(name CMP0128WarnMatch) + test_build() +endfunction() + +function(test_cmp0128_warn_unset) + # For compilers that had CMAKE_<LANG>_EXTENSION_COMPILE_OPTION (only IAR) + # there is no behavioural change and thus no warning. + if(NOT "${${lang}_EXT_FLAG}" STREQUAL "") + return() + endif() + + if(extensions_opposite) + set(opposite "enabled") + else() + set(opposite "disabled") + endif() + + set(name CMP0128WarnUnset) + test_build() +endfunction() + +function(test_lang lang ext) + if(CMake_NO_${lang}_STANDARD) + return() + endif() + + set(extensions_default "${${lang}_EXTENSIONS_DEFAULT}") + set(standard_default "${${lang}_STANDARD_DEFAULT}") + + if(extensions_default) + set(extensions_opposite OFF) + else() + set(extensions_opposite ON) + endif() + + test_unset_standard() + test_no_unnecessary_flag() + test_cmp0128_warn_match() + test_cmp0128_warn_unset() +endfunction() + +if(C_STANDARD_DEFAULT) + test_lang(C c) +endif() + if(CXX_STANDARD_DEFAULT) run_cmake(NotAStandard) foreach(standard 98 11) - file(READ - "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx${standard}_flag.txt" - CXX${standard}_FLAG - ) if (CXX${standard}_FLAG STREQUAL NOTFOUND) run_cmake(RequireCXX${standard}) run_cmake(RequireCXX${standard}Variable) endif() - if (CXX${standard}EXT_FLAG STREQUAL NOTFOUND) + if (CXX${standard}_EXT_FLAG STREQUAL NOTFOUND) run_cmake(RequireCXX${standard}Ext) run_cmake(RequireCXX${standard}ExtVariable) endif() endforeach() + + test_lang(CXX cpp) endif() diff --git a/Tests/RunCMake/CompileFeatures/UnsetStandard-build-check.cmake b/Tests/RunCMake/CompileFeatures/UnsetStandard-build-check.cmake new file mode 100644 index 0000000..abe293c --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/UnsetStandard-build-check.cmake @@ -0,0 +1,12 @@ +foreach(flag @flags@) + string(FIND "${actual_stdout}" "${flag}" position) + + if(NOT position EQUAL -1) + set(found TRUE) + break() + endif() +endforeach() + +if(NOT found) + set(RunCMake_TEST_FAILED "No compile flags from \"@flags@\" found for CMAKE_@lang@_EXTENSIONS=@extensions_opposite@.") +endif() diff --git a/Tests/RunCMake/CompileFeatures/UnsetStandard.cmake b/Tests/RunCMake/CompileFeatures/UnsetStandard.cmake new file mode 100644 index 0000000..99bb3f0 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/UnsetStandard.cmake @@ -0,0 +1,8 @@ +enable_language(@lang@) + +# Make sure the compile command is not hidden. +string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") +string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") + +set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/compiler_introspection.cmake b/Tests/RunCMake/CompileFeatures/compiler_introspection.cmake new file mode 100644 index 0000000..5691344 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/compiler_introspection.cmake @@ -0,0 +1,38 @@ +enable_language(C CXX) + +set(info "") + +if(MSVC_TOOLSET_VERSION) + string(APPEND info " +set(MSVC_TOOLSET_VERSION ${MSVC_TOOLSET_VERSION}) + +") +endif() + +if(CMAKE_XCODE_BUILD_SYSTEM) + string(APPEND info " +set(CMAKE_XCODE_BUILD_SYSTEM ${CMAKE_XCODE_BUILD_SYSTEM}) + +") +endif() + +macro(info lang) + string(APPEND info "\ +set(${lang}_STANDARD_DEFAULT ${CMAKE_${lang}_STANDARD_DEFAULT}) +set(${lang}_EXTENSIONS_DEFAULT ${CMAKE_${lang}_EXTENSIONS_DEFAULT}) +set(${lang}_FEATURES ${CMAKE_${lang}_COMPILE_FEATURES}) + +set(${lang}_EXT_FLAG ${CMAKE_${lang}_EXTENSION_COMPILE_OPTION}) +") + + foreach(standard ${ARGN}) + string(APPEND info "\ +set(${lang}${standard}_FLAG ${CMAKE_${lang}${standard}_STANDARD_COMPILE_OPTION}) +set(${lang}${standard}_EXT_FLAG ${CMAKE_${lang}${standard}_EXTENSION_COMPILE_OPTION}) +") + endforeach() +endmacro() + +info(C 90 99 11 17 23) +info(CXX 98 11 14 17 20 23) +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}") diff --git a/Tests/RunCMake/CompileFeatures/empty.c b/Tests/RunCMake/CompileFeatures/empty.c index 11ec041..8d91e77 100644 --- a/Tests/RunCMake/CompileFeatures/empty.c +++ b/Tests/RunCMake/CompileFeatures/empty.c @@ -1,7 +1,7 @@ #ifdef _WIN32 __declspec(dllexport) #endif - int empty() + int empty(void) { return 0; } diff --git a/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake b/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake deleted file mode 100644 index 5c58052..0000000 --- a/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake +++ /dev/null @@ -1,43 +0,0 @@ - -enable_language(C) - -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/c_features.txt" - "${CMAKE_C_COMPILE_FEATURES}" -) - -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx_features.txt" - "${CMAKE_CXX_COMPILE_FEATURES}" -) - -if(DEFINED CMAKE_C_STANDARD_DEFAULT) - set(c_standard_default_code "set(C_STANDARD_DEFAULT \"${CMAKE_C_STANDARD_DEFAULT}\")\n") -else() - set(c_standard_default_code "unset(C_STANDARD_DEFAULT)\n") -endif() -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/c_standard_default.cmake" "${c_standard_default_code}") - -if(DEFINED CMAKE_CXX_STANDARD_DEFAULT) - set(cxx_standard_default_code "set(CXX_STANDARD_DEFAULT \"${CMAKE_CXX_STANDARD_DEFAULT}\")\n") -else() - set(cxx_standard_default_code "unset(CXX_STANDARD_DEFAULT)\n") -endif() -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx_standard_default.cmake" "${cxx_standard_default_code}") - -foreach(standard 98 11) - set(CXX${standard}_FLAG NOTFOUND) - if (DEFINED CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION) - set(CXX${standard}_FLAG ${CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION}) - endif() - - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}_flag.txt" - "${CXX${standard}_FLAG}" - ) - set(CXX${standard}EXT_FLAG NOTFOUND) - if (DEFINED CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION) - set(CXX${standard}EXT_FLAG ${CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION}) - endif() - - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}ext_flag.txt" - "${CXX${standard}EXT_FLAG}" - ) -endforeach() diff --git a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake deleted file mode 100644 index 46b840f..0000000 --- a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake +++ /dev/null @@ -1,21 +0,0 @@ -enable_language(CXX) - -find_package(Qt5Core REQUIRED) - -set(CMAKE_AUTOMOC ON) - -add_library(simple_lib SHARED simple_lib.cpp) -add_executable(app_with_qt app.cpp app_qt.cpp) -target_link_libraries(app_with_qt PRIVATE simple_lib Qt5::Core) - -if(Qt5Widgets_DIR) - find_package(Qt5Widgets REQUIRED) - qt5_wrap_ui(_headers MyWindow.ui) - add_executable(app_with_widget app.cpp MyWindow.cpp ${_headers}) - target_link_libraries(app_with_widget PRIVATE Qt5::Widgets) - target_include_directories(app_with_widget PRIVATE "${CMAKE_BINARY_DIR}") -endif() - -add_subdirectory(QtSubDir1) -add_subdirectory(QtSubDir2) -add_subdirectory(QtSubDir3) diff --git a/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake b/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake new file mode 100644 index 0000000..c441169 --- /dev/null +++ b/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake @@ -0,0 +1,27 @@ +enable_language(CXX) + +set(QtX Qt${with_qt_version}) + +find_package(${QtX} REQUIRED COMPONENTS Core) + +set(CMAKE_AUTOMOC ON) + +add_library(simple_lib SHARED simple_lib.cpp) +add_executable(app_with_qt app.cpp app_qt.cpp) +target_link_libraries(app_with_qt PRIVATE simple_lib ${QtX}::Core) + +if(${QtX}Widgets_DIR) + find_package(${QtX} REQUIRED COMPONENTS Widgets) + if(with_qt_version STREQUAL 5) + qt5_wrap_ui(_headers MyWindow.ui) + else() + qt_wrap_ui(_headers MyWindow.ui) + endif() + add_executable(app_with_widget app.cpp MyWindow.cpp ${_headers}) + target_link_libraries(app_with_widget PRIVATE ${QtX}::Widgets) + target_include_directories(app_with_widget PRIVATE "${CMAKE_BINARY_DIR}") +endif() + +add_subdirectory(QtSubDir1) +add_subdirectory(QtSubDir2) +add_subdirectory(QtSubDir3) diff --git a/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt index 64016b6..3a12dcd 100644 --- a/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt +++ b/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_policy(SET CMP0116 OLD) add_executable(sub_exe_1 ../app.cpp) -target_link_libraries(sub_exe_1 PRIVATE Qt5::Core) +target_link_libraries(sub_exe_1 PRIVATE ${QtX}::Core) diff --git a/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt index 3176426..a2f77e4 100644 --- a/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt +++ b/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_policy(SET CMP0116 NEW) add_executable(sub_exe_2 ../app.cpp) -target_link_libraries(sub_exe_2 PRIVATE Qt5::Core) +target_link_libraries(sub_exe_2 PRIVATE ${QtX}::Core) diff --git a/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt index d38cfe0..70644fa 100644 --- a/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt +++ b/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(sub_exe_3 ../app.cpp) -target_link_libraries(sub_exe_3 PRIVATE Qt5::Core) +target_link_libraries(sub_exe_3 PRIVATE ${QtX}::Core) diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 3f239b9..2a5b556 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -319,12 +319,17 @@ function (run_ChangeBuildType) endfunction() run_ChangeBuildType() -function(run_Qt5AutoMocDeps) - if(CMake_TEST_Qt5 AND CMAKE_TEST_Qt5Core_Version VERSION_GREATER_EQUAL 5.15.0) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Qt5AutoMocDeps-build) - set(RunCMake_TEST_OPTIONS "-DQt5Core_DIR=${Qt5Core_DIR}" "-DQt5Widgets_DIR=${Qt5Widgets_DIR}") - run_cmake(Qt5AutoMocDeps) - unset(RunCMake_TEST_OPTIONS) +function(run_QtAutoMocDeps) + set(QtX Qt${CMake_TEST_Qt_version}) + if(CMake_TEST_${QtX}Core_Version VERSION_GREATER_EQUAL 5.15.0) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocDeps-build) + run_cmake_with_options(QtAutoMocDeps + "-Dwith_qt_version=${CMake_TEST_Qt_version}" + "-D${QtX}_DIR=${${QtX}_DIR}" + "-D${QtX}Core_DIR=${${QtX}Core_DIR}" + "-D${QtX}Widgets_DIR=${${QtX}Widgets_DIR}" + "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}" + ) # Build the project. run_ninja("${RunCMake_TEST_BINARY_DIR}") # Touch just the library source file, which shouldn't cause a rerun of AUTOMOC @@ -352,4 +357,6 @@ function(run_Qt5AutoMocDeps) run_ninja("${RunCMake_TEST_BINARY_DIR}") endif() endfunction() -run_Qt5AutoMocDeps() +if(CMake_TEST_Qt_version) + run_QtAutoMocDeps() +endif() diff --git a/Tests/RunCMake/NinjaMultiConfig/Qt5-automoc-check-ninja-stdout.txt b/Tests/RunCMake/NinjaMultiConfig/QtX-automoc-check-ninja-stdout.txt index 85d5fdc..85d5fdc 100644 --- a/Tests/RunCMake/NinjaMultiConfig/Qt5-automoc-check-ninja-stdout.txt +++ b/Tests/RunCMake/NinjaMultiConfig/QtX-automoc-check-ninja-stdout.txt diff --git a/Tests/RunCMake/NinjaMultiConfig/Qt5-debug-in-release-graph-build-check.cmake b/Tests/RunCMake/NinjaMultiConfig/QtX-debug-in-release-graph-build-check.cmake index 2d8df13..2d8df13 100644 --- a/Tests/RunCMake/NinjaMultiConfig/Qt5-debug-in-release-graph-build-check.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/QtX-debug-in-release-graph-build-check.cmake diff --git a/Tests/RunCMake/NinjaMultiConfig/Qt5.cmake b/Tests/RunCMake/NinjaMultiConfig/QtX.cmake index 578256a..130f883 100644 --- a/Tests/RunCMake/NinjaMultiConfig/Qt5.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/QtX.cmake @@ -1,18 +1,21 @@ enable_language(CXX) -find_package(Qt5Core REQUIRED) +set(QtX Qt${with_qt_version}) + +find_package(${QtX} REQUIRED COMPONENTS Core) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC_COMPILER_PREDEFINES OFF) +# Source files are always named qt5.* for simplicity but apply to Qt5 and later add_executable(exe qt5.cxx) -target_link_libraries(exe PRIVATE Qt5::Core) +target_link_libraries(exe PRIVATE ${QtX}::Core) include(${CMAKE_CURRENT_LIST_DIR}/Common.cmake) generate_output_files(exe) set(moc_writes_depfiles 0) -if(Qt5Core_VERSION VERSION_GREATER_EQUAL "5.15.0") +if(${QtX}Core_VERSION VERSION_GREATER_EQUAL "5.15.0") set(moc_writes_depfiles 1) endif() diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake index 7c100eb..c7b876c 100644 --- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake @@ -446,14 +446,20 @@ if(CMake_TEST_CUDA AND NOT CMake_TEST_CUDA STREQUAL "Clang") run_ninja(CudaSimple all-clean build-Debug.ninja clean:Debug) endif() -if(CMake_TEST_Qt5) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Qt5-build) - set(RunCMake_TEST_OPTIONS "-DCMAKE_CROSS_CONFIGS=all" "-DQt5Core_DIR=${Qt5Core_DIR}") - run_cmake_configure(Qt5) +if(CMake_TEST_Qt_version) + set(QtX Qt${CMake_TEST_Qt_version}) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtX-build) + set(RunCMake_TEST_OPTIONS + "-DCMAKE_CROSS_CONFIGS=all" + "-Dwith_qt_version:STRING=${CMake_TEST_Qt_version}" + "-D${QtX}Core_DIR=${${QtX}Core_DIR}" + "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}" + ) + run_cmake_configure(QtX) unset(RunCMake_TEST_OPTIONS) include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) - run_cmake_build(Qt5 debug-in-release-graph Release exe:Debug) - if(CMAKE_TEST_Qt5Core_Version VERSION_GREATER_EQUAL 5.15.0) - run_ninja(Qt5 automoc-check build-Debug.ninja -t query exe_autogen/timestamp) + run_cmake_build(QtX debug-in-release-graph Release exe:Debug) + if(CMake_TEST_${QtX}Core_Version VERSION_GREATER_EQUAL 5.15.0) + run_ninja(QtX automoc-check build-Debug.ninja -t query exe_autogen/timestamp) endif() endif() |