CurlSymbolHiding.cmake 2.5 KB

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