cmake/Utilities/cmcurl/CMake/CurlSymbolHiding.cmake

81 lines
3.3 KiB
CMake
Raw Normal View History

2020-08-30 11:54:41 +02:00
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
2023-07-02 19:51:09 +02:00
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
2020-08-30 11:54:41 +02:00
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
2021-09-14 00:13:48 +02:00
# are also available at https://curl.se/docs/copyright.html.
2020-08-30 11:54:41 +02:00
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
2022-11-16 20:14:03 +01:00
# SPDX-License-Identifier: curl
#
2020-08-30 11:54:41 +02:00
###########################################################################
2017-04-14 19:02:05 +02:00
include(CheckCSourceCompiles)
2024-11-11 15:18:55 +01:00
option(CURL_HIDDEN_SYMBOLS "Hide libcurl internal symbols (=hide all symbols that are not officially external)" ON)
2017-04-14 19:02:05 +02:00
mark_as_advanced(CURL_HIDDEN_SYMBOLS)
2024-11-11 15:18:55 +01:00
if(WIN32 AND (ENABLE_DEBUG OR ENABLE_CURLDEBUG))
# We need to export internal debug functions,
# e.g. curl_easy_perform_ev() or curl_dbg_*(),
# so disable symbol hiding for debug builds and for memory tracking.
2023-12-07 09:12:54 +01:00
set(CURL_HIDDEN_SYMBOLS OFF)
endif()
2017-04-14 19:02:05 +02:00
if(CURL_HIDDEN_SYMBOLS)
2024-11-11 15:18:55 +01:00
set(_supports_symbol_hiding FALSE)
2017-04-14 19:02:05 +02:00
2021-09-14 00:13:48 +02:00
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
2024-11-11 15:18:55 +01:00
set(_supports_symbol_hiding TRUE)
set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
set(_cflag_symbols_hide "-fvisibility=hidden")
2018-10-28 12:09:07 +01:00
elseif(CMAKE_COMPILER_IS_GNUCC)
2020-08-30 11:54:41 +02:00
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
2024-11-11 15:18:55 +01:00
# Note: This is considered buggy prior to 4.0 but the autotools do not care, so let us ignore that fact
set(_supports_symbol_hiding TRUE)
set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
set(_cflag_symbols_hide "-fvisibility=hidden")
2017-04-14 19:02:05 +02:00
endif()
2018-10-28 12:09:07 +01:00
elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
2024-11-11 15:18:55 +01:00
set(_supports_symbol_hiding TRUE)
set(_symbol_extern "__global")
set(_cflag_symbols_hide "-xldscope=hidden")
2018-10-28 12:09:07 +01:00
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
2024-11-11 15:18:55 +01:00
# Note: This should probably just check for version 9.1.045 but I am not 100% sure
# so let us do it the same way autotools do.
set(_supports_symbol_hiding TRUE)
set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
set(_cflag_symbols_hide "-fvisibility=hidden")
2018-10-28 12:09:07 +01:00
check_c_source_compiles("#include <stdio.h>
2024-11-11 15:18:55 +01:00
int main(void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
2018-10-28 12:09:07 +01:00
if(NOT _no_bug)
2024-11-11 15:18:55 +01:00
set(_supports_symbol_hiding FALSE)
set(_symbol_extern "")
set(_cflag_symbols_hide "")
2018-10-28 12:09:07 +01:00
endif()
elseif(MSVC)
2024-11-11 15:18:55 +01:00
set(_supports_symbol_hiding TRUE)
2018-10-28 12:09:07 +01:00
endif()
2017-04-14 19:02:05 +02:00
2024-11-11 15:18:55 +01:00
set(CURL_HIDES_PRIVATE_SYMBOLS ${_supports_symbol_hiding})
2020-02-01 23:06:01 +01:00
else()
2024-11-11 15:18:55 +01:00
if(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
set(CURL_HIDES_PRIVATE_SYMBOLS FALSE)
2017-04-14 19:02:05 +02:00
endif()
2024-11-11 15:18:55 +01:00
set(CURL_CFLAG_SYMBOLS_HIDE ${_cflag_symbols_hide})
set(CURL_EXTERN_SYMBOL ${_symbol_extern})