Skip to content

Commit

Permalink
Use PLATFORM_ID for whole archive linker flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiklohmann committed Apr 16, 2021
1 parent 71f1184 commit 974a6f9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cmake/VASTRegisterPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ function (VASTRegisterPlugin)
if (target_type STREQUAL "STATIC_LIBRARY")
# Prevent elision of self-registration code in statically linked libraries,
# c.f., https://www.bfilipek.com/2018/02/static-vars-static-lib.html
# Possible PLATFORM_ID values:
# - Windows: Windows (Visual Studio, MinGW GCC)
# - Darwin: macOS/OS X (Clang, GCC)
# - Linux: Linux (GCC, Intel, PGI)
# - Android: Android NDK (GCC, Clang)
# - FreeBSD: FreeBSD
# - CrayLinuxEnvironment: Cray supercomputers (Cray compiler)
# - MSYS: Windows (MSYS2 shell native GCC)#
target_link_options(
${target}
${visibility}
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:LINKER:-force_load,$<TARGET_FILE:${library}>>
$<$<CXX_COMPILER_ID:GNU>:LINKER:--whole-archive,$<TARGET_FILE:${library}>,--no-whole-archive>
$<$<CXX_COMPILER_ID:MSVC>:LINKER:/WHOLEARCHIVE,$<TARGET_FILE:${library}>>
$<$<OR:$<PLATFORM_ID:Darwin>,$<PLATFORM_ID:FreeBSD>>:LINKER:-force_load,$<TARGET_FILE:${library}>>
$<$<PLATFORM_ID:Linux>:LINKER:--whole-archive,$<TARGET_FILE:${library}>,--no-whole-archive>
$<$<PLATFORM_ID:Windows>:LINKER:/WHOLEARCHIVE,$<TARGET_FILE:${library}>>
)
endif ()
target_link_libraries(${target} ${visibility} ${library})
Expand Down

0 comments on commit 974a6f9

Please sign in to comment.