Skip to content

Commit

Permalink
Check every variant of CMAKE_CXX_FLAGS_<CONFIG>
Browse files Browse the repository at this point in the history
BTW check_cxx_source_compiles() doesn't  use the _<CONFIG> flags
  • Loading branch information
graebm committed Nov 27, 2024
1 parent cabce87 commit 4797a57
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,17 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDA

# Hide symbols by default
# Except where it causes problems, and the situation is weird enough that it's not worth investigating further.
string(FIND "${CMAKE_CXX_FLAGS}" "-D_GLIBCXX_USE_CXX11_ABI=0" found_ancient_abi_flag)
#
# We've seen people set _GLIBCXX_USE_CXX11_ABI=0 which forces GCC to use it's pre-C++11 string implementation,
# which leads to crashes on shared-lib builds. Search every variant of CXX_FLAGS to see if it's set.
string(FIND "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS_MINSIZEREL}"
"-D_GLIBCXX_USE_CXX11_ABI=0" found_ancient_abi_flag)
if(found_ancient_abi_flag GREATER -1)
# We've seen people set _GLIBCXX_USE_CXX11_ABI=0 which forces GCC to use it's pre-C++11 string implementation.
# This leads to crashes on shared-lib builds.
message(STATUS "Cannot deal with hidden symbols when _GLIBCXX_USE_CXX11_ABI=0 is set, making everything visible")
message(WARNING "_GLIBCXX_USE_CXX11_ABI=0 is set. Making all symbols visible to prevent weird crashes")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0")
# Ancient GCC leads to crashes in shared-lib builds
# see: https://github.com/awslabs/aws-crt-cpp/pull/675
message(STATUS "Your compiler is too old to deal with hidden symbols, making everything visible")
message(WARNING "Ancient compiler (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}). Making all symbols visible to prevent weird crashes")
else()
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
endif()
Expand Down

0 comments on commit 4797a57

Please sign in to comment.