summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-10-04 16:42:40 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-10-04 16:43:24 (GMT)
commitc55a41c9b2fea1617ad2a0a50760e4f8b6e42a47 (patch)
tree12616c224f1302c14cb8a8c893f89b4e89b18fbb /Tests
parentb2726f13bdd2caffcd27dd5c7ebf3211169a40e4 (diff)
parent4a0485be7f4ab06201c478f5a46111ab1e8e773e (diff)
downloadCMake-c55a41c9b2fea1617ad2a0a50760e4f8b6e42a47.zip
CMake-c55a41c9b2fea1617ad2a0a50760e4f8b6e42a47.tar.gz
CMake-c55a41c9b2fea1617ad2a0a50760e4f8b6e42a47.tar.bz2
Merge topic 'default_extensions'
4a0485be7f cmStandardLevelResolver: Avoid unnecessary flags, fix unset level logic 29e2b85171 Tests: Simplify RunCMake.CompileFeatures introspection fc3a1cbdd8 CompilerID: Compiler extensions default detection 2adfd95d79 CompilerID: Rename language_dialect to language_standard 00055d7779 Help: Document CMAKE_<LANG>_STANDARD_DEFAULT a65bee4cfc Help: Document HIP standard/extensions properties and variables a40ff1bb5a Help: Make language standard/extensions variable pages less wordy 3feff8379b Help: Generic language standard and extension variables documentation Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6177
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt8
-rw-r--r--Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake7
-rw-r--r--Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt8
-rw-r--r--Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake6
-rw-r--r--Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake8
-rw-r--r--Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake9
-rw-r--r--Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake135
-rw-r--r--Tests/RunCMake/CompileFeatures/UnsetStandard-build-check.cmake12
-rw-r--r--Tests/RunCMake/CompileFeatures/UnsetStandard.cmake8
-rw-r--r--Tests/RunCMake/CompileFeatures/compiler_introspection.cmake38
-rw-r--r--Tests/RunCMake/CompileFeatures/empty.c2
-rw-r--r--Tests/RunCMake/CompileFeatures/generate_feature_list.cmake43
13 files changed, 225 insertions, 61 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index eb2c2d9..af6cbb5 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -310,7 +310,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()