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.
This commit is contained in:
Matthew Woehlke
2022-09-26 12:24:03 -04:00
parent 98aef0929f
commit db76876db5
19 changed files with 76 additions and 78 deletions
+7 -9
View File
@@ -52,7 +52,7 @@ include_guard(GLOBAL)
macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
if(NOT DEFINED "${VARIABLE}")
set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
set(_src_content "/* */\n")
if("x${ARGN}" STREQUAL "x")
if(CMAKE_C_COMPILER_LOADED)
@@ -71,9 +71,9 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
endif()
if(_lang STREQUAL "C")
set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${VARIABLE}.c)
set(src ${VARIABLE}.c)
elseif(_lang STREQUAL "CXX")
set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${VARIABLE}.cpp)
set(src ${VARIABLE}.cpp)
else()
message(FATAL_ERROR "Unknown language:\n ${_lang}\nSupported languages: C, CXX.\n")
endif()
@@ -86,13 +86,11 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
set(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
set(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
foreach(FILE ${INCLUDE})
string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT
string(APPEND _src_content
"#include <${FILE}>\n")
endforeach()
string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT
string(APPEND _src_content
"\n\nint main(void){return 0;}\n")
configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
"${src}" @ONLY)
set(_INCLUDE ${INCLUDE}) # remove empty elements
if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$")
@@ -136,7 +134,7 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
message(CHECK_START "Looking for ${_description}")
endif()
try_compile(${VARIABLE}
SOURCES ${src}
SOURCE_FROM_VAR "${src}" _src_content
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
${_CIF_LINK_OPTIONS}
${_CIF_LINK_LIBRARIES}
@@ -163,7 +161,7 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if files ${INCLUDE} "
"exist failed with the following output:\n"
"${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
"${OUTPUT}\nSource:\n${_src_content}\n")
endif()
endif()
endmacro()