diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-09-14 17:17:42 (GMT) |
---|---|---|
committer | Robert Maynard <robert.maynard@kitware.com> | 2020-09-23 16:28:37 (GMT) |
commit | 10ae907de07c26820a765c6a516d1f4baa46161d (patch) | |
tree | 51550bfe24aa14db9bec91efc1e45a1d841fb939 /Modules/CheckCSourceCompiles.cmake | |
parent | f5c928f73cdb35b4cc0ea052f663071ec590624e (diff) | |
download | CMake-10ae907de07c26820a765c6a516d1f4baa46161d.zip CMake-10ae907de07c26820a765c6a516d1f4baa46161d.tar.gz CMake-10ae907de07c26820a765c6a516d1f4baa46161d.tar.bz2 |
CheckSoureCompiles: Add a unified way to check if a source compiles
Diffstat (limited to 'Modules/CheckCSourceCompiles.cmake')
-rw-r--r-- | Modules/CheckCSourceCompiles.cmake | 76 |
1 files changed, 2 insertions, 74 deletions
diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake index 67fc993..975e653 100644 --- a/Modules/CheckCSourceCompiles.cmake +++ b/Modules/CheckCSourceCompiles.cmake @@ -66,80 +66,8 @@ Check if given C source compiles and links into an executable. #]=======================================================================] include_guard(GLOBAL) +include(CheckSourceCompiles) macro(CHECK_C_SOURCE_COMPILES SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(_FAIL_REGEX) - set(_key) - foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(FAIL_REGEX)$") - set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_compile(${VAR} - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}" - OUTPUT_VARIABLE OUTPUT) - - foreach(_regex ${_FAIL_REGEX}) - if("${OUTPUT}" MATCHES "${_regex}") - set(${VAR} 0) - endif() - endforeach() - - if(${VAR}) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing C SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - else() - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing C SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + check_source_compiles(C "${SOURCE}" ${VAR} ${ARGN}) endmacro() |