From 8737453498d7dc4b62458e53f5318c76bc40865d Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 19:19:36 +0000 Subject: [PATCH] cmake: Compiler-specific whole-archive macro --- CMakeLists.txt | 1 + apps/opencs/CMakeLists.txt | 4 ++-- apps/openmw/CMakeLists.txt | 4 ++-- cmake/WholeArchive.cmake | 10 ++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 cmake/WholeArchive.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f883aecfc7..658a961f35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ endif(EXISTS ${PROJECT_SOURCE_DIR}/.git) # Macros include(OpenMWMacros) +include(WholeArchive) # doxygen main page diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index e6df909194..17b3375f59 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -237,8 +237,8 @@ if(OSG_STATIC) target_link_libraries(openmw_cs_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) endforeach() # We use --whole-archive because OSG plugins use registration. - target_link_options(openmw_cs_osg_plugins INTERFACE - -Wl,--whole-archive ${_osg_plugins_static_files} -Wl,--no-whole-archive) + get_whole_archive_options(_opts ${_osg_plugins_static_files}) + target_link_options(openmw_cs_osg_plugins INTERFACE ${_opts}) target_link_libraries(openmw-cs openmw_cs_osg_plugins) endif(OSG_STATIC) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c87a96b3a3..308b8bd5e5 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -152,8 +152,8 @@ if(OSG_STATIC) target_link_libraries(openmw_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) endforeach() # We use --whole-archive because OSG plugins use registration. - target_link_options(openmw_osg_plugins INTERFACE - -Wl,--whole-archive ${_osg_plugins_static_files} -Wl,--no-whole-archive) + get_whole_archive_options(_opts ${_osg_plugins_static_files}) + target_link_options(openmw_osg_plugins INTERFACE ${_opts}) target_link_libraries(openmw openmw_osg_plugins) endif(OSG_STATIC) diff --git a/cmake/WholeArchive.cmake b/cmake/WholeArchive.cmake new file mode 100644 index 0000000000..a834e830e0 --- /dev/null +++ b/cmake/WholeArchive.cmake @@ -0,0 +1,10 @@ +macro (get_whole_archive_options OUT_VAR) + # We use --whole-archive because OSG plugins use registration. + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(${OUT_VAR} -Wl,--whole-archive ${ARGN} -Wl,--no-whole-archive) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(${OUT_VAR} -Wl,-all_load ${ARGN} -Wl,-noall_load) + else () + message(FATAL_ERROR "get_whole_archive_options not implemented for CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}") + endif() +endmacro (whole_archive_options)