Skip to content

Commit

Permalink
CMake: Implement configure -reduce-exports
Browse files Browse the repository at this point in the history
This option maps to FEATURE_reduce_exports. The feature is on by
default, except for MSVC. The reduce_exports configure test is not used
in the CMake build.

The <LANG>_VISIBILITY_PRESET and VISIBILITY_INLINES_HIDDEN target
properties are now explicitly initialized in the
qt_set_common_target_properties function, because we don't have access
to the feature in QtSetup.cmake where the CMAKE_<LANG>_VISIBILITY_PRESET
variables were set before.

Task-number: QTBUG-85373
Change-Id: I378453f0e0665731970016170302871e20ceb4e2
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
jobor committed Oct 5, 2020
1 parent 313ed3d commit c09df7b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
7 changes: 0 additions & 7 deletions cmake/QtSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Do not relink dependent libraries when no header has changed:
set(CMAKE_LINK_DEPENDS_NO_SHARED ON)

# Default to hidden visibility for symbols:
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_OBJC_VISIBILITY_PRESET hidden)
set(CMAKE_OBJCXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

# Detect non-prefix builds: either when the qtbase install prefix is set to the binary dir
# or when a developer build is explicitly enabled and no install prefix is specified.
# This detection only happens when building qtbase, and later is propagated via the generated
Expand Down
8 changes: 8 additions & 0 deletions cmake/QtTargetHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ endfunction()
# Set target properties that are the same for all modules, plugins, executables
# and 3rdparty libraries.
function(qt_set_common_target_properties target)
if(QT_FEATURE_reduce_exports)
set_target_properties(${target} PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
OBJC_VISIBILITY_PRESET hidden
OBJCXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1)
endif()
if(FEATURE_static_runtime)
if(MSVC)
set_property(TARGET ${target} PROPERTY
Expand Down
2 changes: 1 addition & 1 deletion cmake/configure-cmake-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The effort of this is tracked in QTBUG-85373 and QTBUG-85349.
| -R <string> | -DQT_EXTRA_RPATHS=path1;path2 | |
| -rpath | negative CMAKE_SKIP_BUILD_RPATH | |
| | negative CMAKE_SKIP_INSTALL_RPATH | |
| -reduce-exports | | |
| -reduce-exports | -DFEATURE_reduce_exports=ON | |
| -reduce-relocations | -DFEATURE_reduce_relocations=ON | |
| -plugin-manifests | | |
| -static-runtime | -DFEATURE_static_runtime=ON | |
Expand Down
2 changes: 1 addition & 1 deletion configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ qt_feature("enable_gdb_index"
qt_feature_config("enable_gdb_index" QMAKE_PRIVATE_CONFIG)
qt_feature("reduce_exports" PRIVATE
LABEL "Reduce amount of exported symbols"
CONDITION NOT WIN32 AND CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY
CONDITION NOT MSVC
)
qt_feature_definition("reduce_exports" "QT_VISIBILITY_AVAILABLE")
qt_feature_config("reduce_exports" QMAKE_PUBLIC_QT_CONFIG)
Expand Down
4 changes: 3 additions & 1 deletion util/cmake/configurejson2cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def map_tests(test: str) -> Optional[str]:
"spe": "TEST_subarch_spe",
"vsx": "TEST_subarch_vsx",
"openssl11": '(OPENSSL_VERSION VERSION_GREATER_EQUAL "1.1.0")',
"reduce_exports": "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY",
"libinput_axis_api": "ON",
"xlib": "X11_FOUND",
"wayland-scanner": "WaylandScanner_FOUND",
Expand Down Expand Up @@ -952,6 +951,9 @@ def get_feature_mapping():
},
],
},
"reduce_exports": {
"condition": "NOT MSVC",
},
"release": None,
"release_tools": None,
"rpath": {
Expand Down

0 comments on commit c09df7b

Please sign in to comment.