cmake: only add <LANG>_VISIBILITY_PRESET properties when compiler supports -fvisibility=

main
Anonymous Maarten 2023-01-25 22:27:47 +01:00
parent a37f2aed7e
commit 4ec3a5ac27
1 changed files with 16 additions and 3 deletions

View File

@ -628,6 +628,15 @@ if(USE_GCC OR USE_CLANG)
endif() endif()
endif() endif()
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fvisibility=hidden -Werror")
check_c_source_compiles("
#if !defined(__GNUC__) || __GNUC__ < 4
#error SDL only uses visibility attributes in GCC 4 or newer
#endif
int main(int argc, char **argv) { return 0; }" HAVE_GCC_FVISIBILITY)
cmake_pop_check_state()
check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW) check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
if(HAVE_GCC_WSHADOW) if(HAVE_GCC_WSHADOW)
target_compile_options(sdl-global-options INTERFACE "-Wshadow") target_compile_options(sdl-global-options INTERFACE "-Wshadow")
@ -3091,13 +3100,17 @@ if(SDL_SHARED)
# alias target for in-tree builds # alias target for in-tree builds
add_library(SDL3::SDL3 ALIAS SDL3) add_library(SDL3::SDL3 ALIAS SDL3)
set_target_properties(SDL3 PROPERTIES set_target_properties(SDL3 PROPERTIES
C_VISIBILITY_PRESET "hidden"
CXX_VISIBILITY_PRESET "hidden"
OBJC_VISIBILITY_PRESET "hidden"
POSITION_INDEPENDENT_CODE TRUE POSITION_INDEPENDENT_CODE TRUE
LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym" LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym"
INTERFACE_LINK_DEPENDS "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym>" INTERFACE_LINK_DEPENDS "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym>"
) )
if(HAVE_GCC_FVISIBILITY)
set_target_properties(SDL3 PROPERTIES
C_VISIBILITY_PRESET "hidden"
CXX_VISIBILITY_PRESET "hidden"
OBJC_VISIBILITY_PRESET "hidden"
)
endif()
if(NOT SDL_LIBC) if(NOT SDL_LIBC)
if(MSVC AND SDL_CPU_X86) if(MSVC AND SDL_CPU_X86)
# FIXME: should be added for all architectures (missing symbols for ARM) # FIXME: should be added for all architectures (missing symbols for ARM)