diff options
author | Brad King <brad.king@kitware.com> | 2018-03-09 12:38:51 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-03-09 12:39:43 (GMT) |
commit | 897bd57025d4bb18bbeaec454f0ea1c26e4a901e (patch) | |
tree | 81e585d47604752ff1bf781cd6db35936fa1416f /Modules | |
parent | 98622e5e72a4bb705bf88b2d442c492dad45c072 (diff) | |
parent | de348a9638bd51af4523f36c68884b901d4aff18 (diff) | |
download | CMake-897bd57025d4bb18bbeaec454f0ea1c26e4a901e.zip CMake-897bd57025d4bb18bbeaec454f0ea1c26e4a901e.tar.gz CMake-897bd57025d4bb18bbeaec454f0ea1c26e4a901e.tar.bz2 |
Merge topic 'GenerateExportHeader-C'
de348a9638 GenerateExportHeader: Add support for C projects
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1799
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/GenerateExportHeader.cmake | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/Modules/GenerateExportHeader.cmake b/Modules/GenerateExportHeader.cmake index 17a3357..e6dcd00 100644 --- a/Modules/GenerateExportHeader.cmake +++ b/Modules/GenerateExportHeader.cmake @@ -185,6 +185,7 @@ # :prop_tgt:`CXX_VISIBILITY_PRESET <<LANG>_VISIBILITY_PRESET>` and # :prop_tgt:`VISIBILITY_INLINES_HIDDEN` instead. +include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) # TODO: Install this macro separately? @@ -194,6 +195,13 @@ macro(_check_cxx_compiler_attribute _ATTRIBUTE _RESULT) ) endmacro() +# TODO: Install this macro separately? +macro(_check_c_compiler_attribute _ATTRIBUTE _RESULT) + check_c_source_compiles("${_ATTRIBUTE} int somefunc() { return 0; } + int main() { return somefunc();}" ${_RESULT} + ) +endmacro() + macro(_test_compiler_hidden_visibility) if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.2") @@ -213,9 +221,15 @@ macro(_test_compiler_hidden_visibility) AND NOT CMAKE_CXX_COMPILER_ID MATCHES XL AND NOT CMAKE_CXX_COMPILER_ID MATCHES PGI AND NOT CMAKE_CXX_COMPILER_ID MATCHES Watcom) - check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY) - check_cxx_compiler_flag(-fvisibility-inlines-hidden - COMPILER_HAS_HIDDEN_INLINE_VISIBILITY) + if (CMAKE_CXX_COMPILER_LOADED) + check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY) + check_cxx_compiler_flag(-fvisibility-inlines-hidden + COMPILER_HAS_HIDDEN_INLINE_VISIBILITY) + else() + check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY) + check_c_compiler_flag(-fvisibility-inlines-hidden + COMPILER_HAS_HIDDEN_INLINE_VISIBILITY) + endif() endif() endmacro() @@ -232,14 +246,27 @@ macro(_test_compiler_has_deprecated) set(COMPILER_HAS_DEPRECATED "" CACHE INTERNAL "Compiler support for a deprecated attribute") else() - _check_cxx_compiler_attribute("__attribute__((__deprecated__))" - COMPILER_HAS_DEPRECATED_ATTR) - if(COMPILER_HAS_DEPRECATED_ATTR) - set(COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED_ATTR}" - CACHE INTERNAL "Compiler support for a deprecated attribute") + if (CMAKE_CXX_COMPILER_LOADED) + _check_cxx_compiler_attribute("__attribute__((__deprecated__))" + COMPILER_HAS_DEPRECATED_ATTR) + if(COMPILER_HAS_DEPRECATED_ATTR) + set(COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED_ATTR}" + CACHE INTERNAL "Compiler support for a deprecated attribute") + else() + _check_cxx_compiler_attribute("__declspec(deprecated)" + COMPILER_HAS_DEPRECATED) + endif() else() - _check_cxx_compiler_attribute("__declspec(deprecated)" - COMPILER_HAS_DEPRECATED) + _check_c_compiler_attribute("__attribute__((__deprecated__))" + COMPILER_HAS_DEPRECATED_ATTR) + if(COMPILER_HAS_DEPRECATED_ATTR) + set(COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED_ATTR}" + CACHE INTERNAL "Compiler support for a deprecated attribute") + else() + _check_c_compiler_attribute("__declspec(deprecated)" + COMPILER_HAS_DEPRECATED) + endif() + endif() endif() endmacro() |