diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-03-04 13:05:54 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-03-04 15:37:48 +0000 |
commit | e1de70933e3af47f5600ebe5a7b3930e26690c8a (patch) | |
tree | 084cc1f7001793bc6c35d92af6741394356956be /cmake | |
parent | f3e3832c4dfcdc9148b414c4063668a9306e77ba (diff) |
CMake: Handle gc-sections linker flags
Add a function to set gc-sections flags on the linker.
Change-Id: I9ac02364836d2aa8de239adb8d3a5d29659a4007
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtBuild.cmake | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 4fc60400f5..1cb8426b30 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -191,15 +191,6 @@ macro(qt_parse_all_arguments result type flags options multiopts) endmacro() -function(qt_internal_add_link_flags target to_add) - get_target_property(flags "${target}" LINK_FLAGS) - if ("${flags}" STREQUAL "flags-NOTFOUND") - set(flags "") - endif() - string(APPEND flags " ${to_add}") - set_target_properties("${target}" PROPERTIES LINK_FLAGS "${flags}") -endfunction() - function(qt_internal_add_link_flags_no_undefined target) if (GCC OR CLANG) if(APPLE) @@ -209,7 +200,26 @@ function(qt_internal_add_link_flags_no_undefined target) else() message(FATAL_ERROR "Platform linker doesn't support erroring upon encountering undefined symbols. Target:\"${target}\".") endif() - qt_internal_add_link_flags("${target}" "${no_undefined_flag}") + target_link_options("${target}" PRIVATE "${no_undefined_flag}") + endif() +endfunction() + +function(qt_internal_add_link_flags_gc_sections target visibility) + set(possible_visibilities PRIVATE INTERFACE PUBLIC) + list(FIND possible_visibilities "${visibility}" known_visibility) + if (known_visibility EQUAL "-1") + message(FATAL_ERROR "Visibitily setting must be one of PRIVATE, INTERFACE or PUBLIC.") + endif() + + if (GCC OR CLANG) + if(APPLE) + set(gc_sections_flag "-Wl,-dead_strip") + elseif(LINUX OR BSD OR SOLARIS OR WIN32) + set(gc_sections_flag "-Wl,--gc-sections") + else() + message(FATAL_ERROR "Platform linker doesn't support gc sections. Target:\"${target}\".") + endif() + target_link_options("${target}" ${visibility} "${gc_sections_flag}") endif() endfunction() @@ -256,7 +266,7 @@ function(qt_internal_add_linker_version_script target) WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Generating version linker script" ) - qt_internal_add_link_flags("${target}" "-Wl,--version-script,${outfile}") + target_link_options("${target}" PRIVATE "-Wl,--version-script,${outfile}") endif() endif() endfunction() |