Skip to content

Commit

Permalink
Use visibility hidden by default (#392)
Browse files Browse the repository at this point in the history
* Use visibility hidden by default

The commit changes the gz-cmake projects to use C/C++ visibility hidden
by default. This is a potential breaking changed for projects using
gz-cmake but the benefits in terms of creating portable code and
time spend by the loader could be huge.

To avoid this change, the EXPOSE_SYMBOLS_BY_DEFAULT flag can be used
in the gz_configure_project call.

The change deprecates the HIDDEN_SYMBOLS_BY_DEFAULT flag.

---------

Signed-off-by: Jose Luis Rivero <[email protected]>
Co-authored-by: Michael Carroll <[email protected]>
Co-authored-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent e3f3998 commit 646292a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ release will remove the deprecated code.

1. The minimum required cmake version is now 3.22.1.

1. **Breaking**: C/C++ projects enable the `visibility=hidden` compiler flag by default.
gz-cmake4 changes gz-cmake projects to use C/C++ visibility hidden
by default. This is a potential breaking changed for projects using
gz-cmake but the benefits in terms of creating portable code and
time spend by the loader could be relevant.
To avoid this change, the EXPOSE_SYMBOLS_BY_DEFAULT flag can be used in
the gz_configure_project call.
The change deprecates the HIDDEN_SYMBOLS_BY_DEFAULT flag that can be
removed.


## Gazebo CMake 2.X to 3.X

1. **Breaking**: Examples are now built using native cmake.
Expand Down
10 changes: 8 additions & 2 deletions cmake/GzConfigureBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@
#################################################
# Configure the build of the Gazebo project
# Pass the argument HIDE_SYMBOLS_BY_DEFAULT to configure symbol visibility so
# that symbols are hidden unless explicitly marked as visible.
# that symbols are hidden unless explicitly marked as visible. (DEPRECATED)
# Pass the argument EXPOSE_SYMBOLS_BY_DEFAULT to configure symbol visibility
# so symbols are exposed unless explicitly marked as hidden.
# Pass the argument QUIT_IF_BUILD_ERRORS to have this macro quit cmake when the
# build_errors
macro(gz_configure_build)
# Parse the arguments that are passed in
set(options HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS)
set(options HIDE_SYMBOLS_BY_DEFAULT EXPOSE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS)
set(oneValueArgs)
set(multiValueArgs COMPONENTS)
cmake_parse_arguments(gz_configure_build "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(gz_configure_build_HIDE_SYMBOLS_BY_DEFAULT)
message(DEPRECATION "HIDE_SYMBOLS_BY_DEFAULT is now the default. You can safely remove the option.")
endif()

#============================================================================
# Examine the build type. If we do not recognize the type, we will generate
# an error, so this must come before the error handling.
Expand Down
8 changes: 4 additions & 4 deletions cmake/GzSetCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ endmacro()
# Internal to gz-cmake.
macro(_gz_setup_gcc_or_clang)

if(gz_configure_build_HIDE_SYMBOLS_BY_DEFAULT)
set(CMAKE_C_VISIBILITY_PRESET "hidden")
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
else()
if(gz_configure_build_EXPOSE_SYMBOLS_BY_DEFAULT)
set(CMAKE_C_VISIBILITY_PRESET "default")
set(CMAKE_CXX_VISIBILITY_PRESET "default")
else()
set(CMAKE_C_VISIBILITY_PRESET "hidden")
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
endif()


Expand Down

0 comments on commit 646292a

Please sign in to comment.