From fd38458199dd12efb2239c7853159a0096f6e55b Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 16 Dec 2021 17:54:48 -0800 Subject: [PATCH] ign_configure_build: param HIDE_SYMBOLS_BY_DEFAULT Add parameter to ign_configure_build that is used to set CMAKE_C_VISIBILITY_PRESET and CMAKE_CXX_VISIBILITY_PRESET. Signed-off-by: Steve Peters --- cmake/IgnConfigureBuild.cmake | 5 ++++- cmake/IgnSetCompilerFlags.cmake | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cmake/IgnConfigureBuild.cmake b/cmake/IgnConfigureBuild.cmake index 7f1a67cb..ae84d605 100644 --- a/cmake/IgnConfigureBuild.cmake +++ b/cmake/IgnConfigureBuild.cmake @@ -23,13 +23,16 @@ ################################################# # Configure the build of the ignition project +# Pass the argument HIDE_SYMBOLS_BY_DEFAULT to configure symbol visibility so +# that symbols are hidden unless explicitly marked as visible. +# build_errors # Pass the argument QUIT_IF_BUILD_ERRORS to have this macro quit cmake when the # build_errors macro(ign_configure_build) #============================================================================ # Parse the arguments that are passed in - set(options QUIT_IF_BUILD_ERRORS) + set(options HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS) set(oneValueArgs) set(multiValueArgs COMPONENTS) cmake_parse_arguments(ign_configure_build "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) diff --git a/cmake/IgnSetCompilerFlags.cmake b/cmake/IgnSetCompilerFlags.cmake index 7793d8ab..edc2b888 100644 --- a/cmake/IgnSetCompilerFlags.cmake +++ b/cmake/IgnSetCompilerFlags.cmake @@ -115,18 +115,20 @@ endmacro() # Set up compilation flags for GCC or Clang macro(ign_setup_gcc_or_clang) - option(USE_DEFAULT_VISIBILITY_HIDDEN "Hide symbols by default if they are not explicitly specified as visible" FALSE) - if(USE_DEFAULT_VISIBILITY_HIDDEN) - set(VISIBILITY_FLAG "-fvisibility=hidden") + if(ign_configure_build_HIDE_SYMBOLS_BY_DEFAULT) + set(CMAKE_C_VISIBILITY_PRESET "hidden") + set(CMAKE_CXX_VISIBILITY_PRESET "hidden") else() - set(VISIBILITY_FLAG "-fvisibility") + set(CMAKE_C_VISIBILITY_PRESET "default") + set(CMAKE_CXX_VISIBILITY_PRESET "default") endif() + ign_filter_valid_compiler_options( CUSTOM_ALL_FLAGS -Wall -Wextra -Wno-long-long -Wno-unused-value -Wfloat-equal -Wshadow -Winit-self -Wswitch-default -Wmissing-include-dirs -pedantic - ${VISIBILITY_FLAG}) + ) # -ggdb3: Produce comprehensive debug information that can be utilized by gdb set(CUSTOM_DEBUG_FLAGS "-ggdb3")