113498266Sopenharmony_ci#***************************************************************************
213498266Sopenharmony_ci#                                  _   _ ____  _
313498266Sopenharmony_ci#  Project                     ___| | | |  _ \| |
413498266Sopenharmony_ci#                             / __| | | | |_) | |
513498266Sopenharmony_ci#                            | (__| |_| |  _ <| |___
613498266Sopenharmony_ci#                             \___|\___/|_| \_\_____|
713498266Sopenharmony_ci#
813498266Sopenharmony_ci# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
913498266Sopenharmony_ci#
1013498266Sopenharmony_ci# This software is licensed as described in the file COPYING, which
1113498266Sopenharmony_ci# you should have received as part of this distribution. The terms
1213498266Sopenharmony_ci# are also available at https://curl.se/docs/copyright.html.
1313498266Sopenharmony_ci#
1413498266Sopenharmony_ci# You may opt to use, copy, modify, merge, publish, distribute and/or sell
1513498266Sopenharmony_ci# copies of the Software, and permit persons to whom the Software is
1613498266Sopenharmony_ci# furnished to do so, under the terms of the COPYING file.
1713498266Sopenharmony_ci#
1813498266Sopenharmony_ci# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1913498266Sopenharmony_ci# KIND, either express or implied.
2013498266Sopenharmony_ci#
2113498266Sopenharmony_ci# SPDX-License-Identifier: curl
2213498266Sopenharmony_ci#
2313498266Sopenharmony_ci###########################################################################
2413498266Sopenharmony_ciinclude(CheckCSourceCompiles)
2513498266Sopenharmony_ci
2613498266Sopenharmony_cioption(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide all symbols that aren't officially external)." ON)
2713498266Sopenharmony_cimark_as_advanced(CURL_HIDDEN_SYMBOLS)
2813498266Sopenharmony_ci
2913498266Sopenharmony_ciif(WIN32 AND ENABLE_CURLDEBUG)
3013498266Sopenharmony_ci  # We need to export internal debug functions (e.g. curl_dbg_*), so disable
3113498266Sopenharmony_ci  # symbol hiding for debug builds.
3213498266Sopenharmony_ci  set(CURL_HIDDEN_SYMBOLS OFF)
3313498266Sopenharmony_ciendif()
3413498266Sopenharmony_ci
3513498266Sopenharmony_ciif(CURL_HIDDEN_SYMBOLS)
3613498266Sopenharmony_ci  set(SUPPORTS_SYMBOL_HIDING FALSE)
3713498266Sopenharmony_ci
3813498266Sopenharmony_ci  if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
3913498266Sopenharmony_ci    set(SUPPORTS_SYMBOL_HIDING TRUE)
4013498266Sopenharmony_ci    set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
4113498266Sopenharmony_ci    set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
4213498266Sopenharmony_ci  elseif(CMAKE_COMPILER_IS_GNUCC)
4313498266Sopenharmony_ci    if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
4413498266Sopenharmony_ci      # note: this is considered buggy prior to 4.0 but the autotools don't care, so let's ignore that fact
4513498266Sopenharmony_ci      set(SUPPORTS_SYMBOL_HIDING TRUE)
4613498266Sopenharmony_ci      set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
4713498266Sopenharmony_ci      set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
4813498266Sopenharmony_ci    endif()
4913498266Sopenharmony_ci  elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
5013498266Sopenharmony_ci    set(SUPPORTS_SYMBOL_HIDING TRUE)
5113498266Sopenharmony_ci    set(_SYMBOL_EXTERN "__global")
5213498266Sopenharmony_ci    set(_CFLAG_SYMBOLS_HIDE "-xldscope=hidden")
5313498266Sopenharmony_ci  elseif(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
5413498266Sopenharmony_ci    # note: this should probably just check for version 9.1.045 but I'm not 100% sure
5513498266Sopenharmony_ci    #       so let's do it the same way autotools do.
5613498266Sopenharmony_ci    set(SUPPORTS_SYMBOL_HIDING TRUE)
5713498266Sopenharmony_ci    set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
5813498266Sopenharmony_ci    set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
5913498266Sopenharmony_ci    check_c_source_compiles("#include <stdio.h>
6013498266Sopenharmony_ci        int main (void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
6113498266Sopenharmony_ci    if(NOT _no_bug)
6213498266Sopenharmony_ci      set(SUPPORTS_SYMBOL_HIDING FALSE)
6313498266Sopenharmony_ci      set(_SYMBOL_EXTERN "")
6413498266Sopenharmony_ci      set(_CFLAG_SYMBOLS_HIDE "")
6513498266Sopenharmony_ci    endif()
6613498266Sopenharmony_ci  elseif(MSVC)
6713498266Sopenharmony_ci    set(SUPPORTS_SYMBOL_HIDING TRUE)
6813498266Sopenharmony_ci  endif()
6913498266Sopenharmony_ci
7013498266Sopenharmony_ci  set(HIDES_CURL_PRIVATE_SYMBOLS ${SUPPORTS_SYMBOL_HIDING})
7113498266Sopenharmony_cielseif(MSVC)
7213498266Sopenharmony_ci  if(NOT CMAKE_VERSION VERSION_LESS 3.7)
7313498266Sopenharmony_ci    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) #present since 3.4.3 but broken
7413498266Sopenharmony_ci    set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
7513498266Sopenharmony_ci  else()
7613498266Sopenharmony_ci    message(WARNING "Hiding private symbols regardless CURL_HIDDEN_SYMBOLS being disabled.")
7713498266Sopenharmony_ci    set(HIDES_CURL_PRIVATE_SYMBOLS TRUE)
7813498266Sopenharmony_ci  endif()
7913498266Sopenharmony_cielse()
8013498266Sopenharmony_ci  set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
8113498266Sopenharmony_ciendif()
8213498266Sopenharmony_ci
8313498266Sopenharmony_ciset(CURL_CFLAG_SYMBOLS_HIDE ${_CFLAG_SYMBOLS_HIDE})
8413498266Sopenharmony_ciset(CURL_EXTERN_SYMBOL ${_SYMBOL_EXTERN})
85