2
0

CurlSymbolHiding.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. include(CheckCSourceCompiles)
  25. option(CURL_HIDDEN_SYMBOLS "Hide libcurl internal symbols (=hide all symbols that are not officially external)" ON)
  26. mark_as_advanced(CURL_HIDDEN_SYMBOLS)
  27. if(WIN32 AND (ENABLE_DEBUG OR ENABLE_CURLDEBUG))
  28. # We need to export internal debug functions,
  29. # e.g. curl_easy_perform_ev() or curl_dbg_*(),
  30. # so disable symbol hiding for debug builds and for memory tracking.
  31. set(CURL_HIDDEN_SYMBOLS OFF)
  32. endif()
  33. if(CURL_HIDDEN_SYMBOLS)
  34. set(_supports_symbol_hiding FALSE)
  35. if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
  36. set(_supports_symbol_hiding TRUE)
  37. set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
  38. set(_cflag_symbols_hide "-fvisibility=hidden")
  39. elseif(CMAKE_COMPILER_IS_GNUCC)
  40. if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
  41. # Note: This is considered buggy prior to 4.0 but the autotools do not care, so let us ignore that fact
  42. set(_supports_symbol_hiding TRUE)
  43. set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
  44. set(_cflag_symbols_hide "-fvisibility=hidden")
  45. endif()
  46. elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
  47. set(_supports_symbol_hiding TRUE)
  48. set(_symbol_extern "__global")
  49. set(_cflag_symbols_hide "-xldscope=hidden")
  50. elseif(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
  51. # Note: This should probably just check for version 9.1.045 but I am not 100% sure
  52. # so let us do it the same way autotools do.
  53. set(_supports_symbol_hiding TRUE)
  54. set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
  55. set(_cflag_symbols_hide "-fvisibility=hidden")
  56. check_c_source_compiles("#include <stdio.h>
  57. int main(void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
  58. if(NOT _no_bug)
  59. set(_supports_symbol_hiding FALSE)
  60. set(_symbol_extern "")
  61. set(_cflag_symbols_hide "")
  62. endif()
  63. elseif(MSVC)
  64. set(_supports_symbol_hiding TRUE)
  65. endif()
  66. set(CURL_HIDES_PRIVATE_SYMBOLS ${_supports_symbol_hiding})
  67. else()
  68. if(MSVC)
  69. set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
  70. endif()
  71. set(CURL_HIDES_PRIVATE_SYMBOLS FALSE)
  72. endif()
  73. set(CURL_CFLAG_SYMBOLS_HIDE ${_cflag_symbols_hide})
  74. set(CURL_EXTERN_SYMBOL ${_symbol_extern})