From 41a8f3f40fc6ee08a347f5b515154a4471f6af3d Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Sat, 1 Oct 2022 16:08:26 +0200 Subject: [PATCH] Lagom: Link LibMain statically This matches how LibMain is used within Serenity. This commit makes it possible to build Lagom with LTO. Previously, `serenity_main` functions would be dead-stripped away, as the linker could prove that nothing from the executable ever called them. --- Meta/Lagom/CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 4635207a5b3..dcaa8fcf40b 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -171,9 +171,13 @@ install( ) function(lagom_lib library fs_name) - cmake_parse_arguments(LAGOM_LIBRARY "" "" "SOURCES;LIBS" ${ARGN}) + cmake_parse_arguments(LAGOM_LIBRARY "STATIC" "" "SOURCES;LIBS" ${ARGN}) set(target_name "Lib${library}") - add_library(${target_name} ${LAGOM_LIBRARY_SOURCES}) + if (LAGOM_LIBRARY_STATIC) + add_library(${target_name} STATIC ${LAGOM_LIBRARY_SOURCES}) + else() + add_library(${target_name} ${LAGOM_LIBRARY_SOURCES}) + endif() # Don't make alias when we're going to import a previous build for Tools # FIXME: Is there a better way to write this? @@ -283,11 +287,8 @@ endif() file(GLOB LIBMAIN_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibMain/*.cpp") lagom_lib(Main main SOURCES ${LIBMAIN_SOURCES} + STATIC ) -# The macOS linker is not happy about LibMain's main() calling an undefined symbol (serenity_main()). -if (APPLE) - target_link_options(LibMain PRIVATE -undefined dynamic_lookup) -endif() # LibTimeZone # This is needed even if Lagom is not enabled because it is depended upon by code generators.