diff options
author | Hong Xu <hong@topbug.net> | 2019-07-07 22:47:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-07-26 19:09:28 (GMT) |
commit | 72fcadb007261f8e1883040d7dc5643e3555aa45 (patch) | |
tree | 0a7f2ab77a257930351375e04a61223149f74bdc /Modules/CheckSymbolExists.cmake | |
parent | 93f10f06b3b86085a180e5259f653646e1705baf (diff) | |
download | CMake-72fcadb007261f8e1883040d7dc5643e3555aa45.zip CMake-72fcadb007261f8e1883040d7dc5643e3555aa45.tar.gz CMake-72fcadb007261f8e1883040d7dc5643e3555aa45.tar.bz2 |
CheckCXXSymbolExists: Make C++-syntax symbols work on more compilers
On some compilers the syntax `#ifndef std::fopen` will always lead to
compilation error. Avoid generating it in the check.
Diffstat (limited to 'Modules/CheckSymbolExists.cmake')
-rw-r--r-- | Modules/CheckSymbolExists.cmake | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake index c2f488a..1053383 100644 --- a/Modules/CheckSymbolExists.cmake +++ b/Modules/CheckSymbolExists.cmake @@ -99,8 +99,28 @@ macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE) string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT "#include <${FILE}>\n") endforeach() - string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT - "\nint main(int argc, char** argv)\n{\n (void)argv;\n#ifndef ${SYMBOL}\n return ((int*)(&${SYMBOL}))[argc];\n#else\n (void)argc;\n return 0;\n#endif\n}\n") + string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT " +int main(int argc, char** argv) +{ + (void)argv;") + set(_CSE_CHECK_NON_MACRO "return ((int*)(&${SYMBOL}))[argc];") + if("${SYMBOL}" MATCHES "^[a-zA-Z_][a-zA-Z0-9_]*$") + # The SYMBOL has a legal macro name. Test whether it exists as a macro. + string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT " +#ifndef ${SYMBOL} + ${_CSE_CHECK_NON_MACRO} +#else + (void)argc; + return 0; +#endif") + else() + # The SYMBOL cannot be a macro (e.g., a template function). + string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT " + ${_CSE_CHECK_NON_MACRO}") + endif() + string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT " +}") + unset(_CSE_CHECK_NON_MACRO) configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" "${SOURCEFILE}" @ONLY) @@ -139,6 +159,7 @@ macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE) "${OUTPUT}\nFile ${SOURCEFILE}:\n" "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n") endif() + unset(CMAKE_CONFIGURABLE_FILE_CONTENT) endif() endmacro() |