mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-02 04:09:33 -05:00
CheckSymbolExists: Work around GCC failure with -pedantic-errors option
GCC mistakenly issues the pedantic warning "ISO C forbids conversion of function pointer to object pointer type". With -pedantic-errors in the compile flags, that diagnostic prevents check_symbol_exists() from detecting function symbols. The solution is to filter out -pedantic-errors (and -Werror, just to be future proof) before invoking try_compile(). Fixes: #13208
This commit is contained in:
@@ -67,14 +67,29 @@ cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
|
|||||||
|
|
||||||
macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
|
macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
|
||||||
if(CMAKE_C_COMPILER_LOADED)
|
if(CMAKE_C_COMPILER_LOADED)
|
||||||
|
__CHECK_SYMBOL_EXISTS_FILTER_FLAGS(C)
|
||||||
__CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
__CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
||||||
|
__CHECK_SYMBOL_EXISTS_RESTORE_FLAGS(C)
|
||||||
elseif(CMAKE_CXX_COMPILER_LOADED)
|
elseif(CMAKE_CXX_COMPILER_LOADED)
|
||||||
|
__CHECK_SYMBOL_EXISTS_FILTER_FLAGS(CXX)
|
||||||
__CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
__CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
||||||
|
__CHECK_SYMBOL_EXISTS_RESTORE_FLAGS(CXX)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "CHECK_SYMBOL_EXISTS needs either C or CXX language enabled")
|
message(FATAL_ERROR "CHECK_SYMBOL_EXISTS needs either C or CXX language enabled")
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
macro(__CHECK_SYMBOL_EXISTS_FILTER_FLAGS LANG)
|
||||||
|
set(__CMAKE_${LANG}_FLAGS_SAVED "${CMAKE_${LANG}_FLAGS}")
|
||||||
|
string(REGEX REPLACE "(^| )-Werror([= ][^ ]*)?( |$)" " " CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS}")
|
||||||
|
string(REGEX REPLACE "(^| )-pedantic-errors( |$)" " " CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(__CHECK_SYMBOL_EXISTS_RESTORE_FLAGS LANG)
|
||||||
|
set(CMAKE_${LANG}_FLAGS "${__CMAKE_${LANG}_FLAGS_SAVED}")
|
||||||
|
unset(__CMAKE_${LANG}_FLAGS_SAVED)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE)
|
macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE)
|
||||||
if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
|
if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
|
||||||
set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
|
set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
|
||||||
|
|||||||
@@ -48,4 +48,15 @@ if (CMAKE_COMPILER_IS_GNUCC)
|
|||||||
if (CSE_RESULT_O3)
|
if (CSE_RESULT_O3)
|
||||||
message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")
|
message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
string(APPEND CMAKE_C_FLAGS " -pedantic-errors")
|
||||||
|
unset(CS_RESULT_PEDANTIC_ERRORS CACHE)
|
||||||
|
message(STATUS "Testing with -pedantic-errors")
|
||||||
|
|
||||||
|
check_symbol_exists(fopen "stdio.h" CSE_RESULT_PEDANTIC_ERRORS)
|
||||||
|
|
||||||
|
if(NOT CSE_RESULT_PEDANTIC_ERRORS)
|
||||||
|
message(SEND_ERROR "CheckSymbolExists reported an existing symbol as nonexisting with -pedantic-errors")
|
||||||
|
endif()
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
Reference in New Issue
Block a user