Home | History | Annotate | Download | only in CMake
      1 include(CheckCSourceCompiles)
      2 
      3 option(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide all symbols that aren't officially external)." ON)
      4 mark_as_advanced(CURL_HIDDEN_SYMBOLS)
      5 
      6 if(CURL_HIDDEN_SYMBOLS)
      7     set(SUPPORTS_SYMBOL_HIDING FALSE)
      8 
      9     if(CMAKE_C_COMPILER_ID MATCHES "Clang")
     10         set(SUPPORTS_SYMBOL_HIDING TRUE)
     11         set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
     12         set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
     13     elseif(CMAKE_COMPILER_IS_GNUCC)
     14         if(NOT CMAKE_VERSION VERSION_LESS 2.8.10)
     15             set(GCC_VERSION ${CMAKE_C_COMPILER_VERSION})
     16         else()
     17             execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
     18                             OUTPUT_VARIABLE GCC_VERSION)
     19         endif()
     20         if(NOT GCC_VERSION VERSION_LESS 3.4)
     21             # note: this is considered buggy prior to 4.0 but the autotools don't care, so let's ignore that fact
     22             set(SUPPORTS_SYMBOL_HIDING TRUE)
     23             set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
     24             set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
     25         endif()
     26     elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
     27         set(SUPPORTS_SYMBOL_HIDING TRUE)
     28         set(_SYMBOL_EXTERN "__global")
     29         set(_CFLAG_SYMBOLS_HIDE "-xldscope=hidden")
     30     elseif(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
     31         # note: this should probably just check for version 9.1.045 but I'm not 100% sure
     32         #       so let's to it the same way autotools do.
     33         set(SUPPORTS_SYMBOL_HIDING TRUE)
     34         set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
     35         set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
     36         check_c_source_compiles("#include <stdio.h>
     37             int main (void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
     38         if(NOT _no_bug)
     39             set(SUPPORTS_SYMBOL_HIDING FALSE)
     40             set(_SYMBOL_EXTERN "")
     41             set(_CFLAG_SYMBOLS_HIDE "")
     42         endif()
     43     elseif(MSVC)
     44         set(SUPPORTS_SYMBOL_HIDING TRUE)
     45     endif()
     46 
     47     set(HIDES_CURL_PRIVATE_SYMBOLS ${SUPPORTS_SYMBOL_HIDING})
     48 elseif(MSVC)
     49     if(NOT CMAKE_VERSION VERSION_LESS 3.7)
     50         set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) #present since 3.4.3 but broken
     51         set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
     52     else()
     53         message(WARNING "Hiding private symbols regardless CURL_HIDDEN_SYMBOLS being disabled.")
     54         set(HIDES_CURL_PRIVATE_SYMBOLS TRUE)
     55     endif()
     56 elseif()
     57     set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
     58 endif()
     59 
     60 set(CURL_CFLAG_SYMBOLS_HIDE ${_CFLAG_SYMBOLS_HIDE})
     61 set(CURL_EXTERN_SYMBOL ${_SYMBOL_EXTERN})
     62