summaryrefslogtreecommitdiffstats
path: root/Modules/Internal/FeatureTesting.cmake
diff options
context:
space:
mode:
authorMatthew Woehlke <matthew.woehlke@kitware.com>2022-09-26 16:24:03 (GMT)
committerMatthew Woehlke <matthew.woehlke@kitware.com>2022-09-27 17:29:52 (GMT)
commitdb76876db5c16d610efd08f6deb0e4c9cd0e5603 (patch)
treeaf62cdbbf0860aee9a3b3a249cbfa578cc01aa33 /Modules/Internal/FeatureTesting.cmake
parent98aef0929f4c5ce7bbf7ce9c2dfc5cad382f5a96 (diff)
downloadCMake-db76876db5c16d610efd08f6deb0e4c9cd0e5603.zip
CMake-db76876db5c16d610efd08f6deb0e4c9cd0e5603.tar.gz
CMake-db76876db5c16d610efd08f6deb0e4c9cd0e5603.tar.bz2
Modules: Use new SOURCES_FROM_* try_compile (1/2)
Modify some modules that ship with CMake to use the new SOURCES_FROM_* arguments to try_compile / try_run as added by commits cb14ae2b87 (try_compile: Add SOURCE_FROM_{ARG,VAR}, 2022-09-21) and 611d801790 (try_compile: Add SOURCE_FROM_FILE, 2022-09-22). This covers users which previously either used an existing file (but sometimes needed to rename it), or which wrote out their source in entirety. It does NOT cover users that actually need configure_file functionality, as those will be more involved to update and will thus be tackled in part 2.
Diffstat (limited to 'Modules/Internal/FeatureTesting.cmake')
-rw-r--r--Modules/Internal/FeatureTesting.cmake9
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake
index 0b10032..5c144ec 100644
--- a/Modules/Internal/FeatureTesting.cmake
+++ b/Modules/Internal/FeatureTesting.cmake
@@ -4,7 +4,7 @@ macro(_record_compiler_features lang compile_flags feature_list)
string(TOLOWER ${lang} lang_lc)
file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin")
- file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "
+ set(_content "
const char features[] = {\"\\n\"\n")
get_property(known_features GLOBAL PROPERTY CMAKE_${lang}_KNOWN_FEATURES)
@@ -16,10 +16,11 @@ macro(_record_compiler_features lang compile_flags feature_list)
else()
set(_feature_condition "#if ${_cmake_feature_test_${feature}}\n\"1\"\n#else\n\"0\"\n#endif\n")
endif()
- file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" "\"${lang}_FEATURE:\"\n${_feature_condition}\"${feature}\\n\"\n")
+ string(APPEND _content
+ "\"${lang}_FEATURE:\"\n${_feature_condition}\"${feature}\\n\"\n")
endif()
endforeach()
- file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}"
+ string(APPEND _content
"\n};\n\nint main(int argc, char** argv) { (void)argv; return features[argc]; }\n")
if(CMAKE_${lang}_LINK_WITH_STANDARD_COMPILE_OPTION)
@@ -31,7 +32,7 @@ macro(_record_compiler_features lang compile_flags feature_list)
endif()
try_compile(CMAKE_${lang}_FEATURE_TEST
- SOURCES "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}"
+ SOURCE_FROM_VAR "feature_tests.${lang_lc}" _content
COMPILE_DEFINITIONS "${compile_flags}"
LINK_LIBRARIES "${compile_flags_for_link}"
OUTPUT_VARIABLE _output