Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ endif()
# more useful error reports from users.
option(BYN_ENABLE_ASSERTIONS "Enable assertions" ON)

option(BYN_ENABLE_LTO "Build with LTO" ${EMSCRIPTEN})
if(EMSCRIPTEN AND NOT "${CMAKE_BUILD_TYPE}" MATCHES "Debug")
# in opt builds, LTO helps so much (>20%) it's worth slow compile times,
# so we enable LTO by default in non-debug emscripten builds.
set(DEFAULT_LTO ON)
else()
set(DEFAULT_LTO OFF)
endif()
option(BYN_ENABLE_LTO "Build with LTO" ${DEFAULT_LTO})

# Turn this off to avoid the dependency on gtest.
option(BUILD_TESTS "Build GTest-based tests" ON)
Expand Down Expand Up @@ -222,6 +229,11 @@ if(BYN_ENABLE_LTO)
set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=2)
set(CMAKE_JOB_POOL_LINK link_job_pool)
add_compile_flag("-flto=thin")
if(EMSCRIPTEN)
# Under emscripten we also add `-flto` to the linker flags to tell the
# compiler driver to choose LTO versions of the system libraries.
add_link_flag("-flto=thin")
Comment thread
sbc100 marked this conversation as resolved.
endif()
endif()

if(MSVC)
Expand Down Expand Up @@ -353,10 +365,6 @@ if(EMSCRIPTEN)
# On Node.js, make the tools immediately usable.
add_link_flag("-sNODERAWFS")
endif()
if (BYN_ENABLE_LTO)
# in opt builds, LTO helps so much (>20%) it's worth slow compile times
add_nondebug_compile_flag("-flto")
endif()
if(EMSCRIPTEN_ENABLE_WASM64)
add_compile_flag("-sMEMORY64")
add_link_flag("-sMEMORY64")
Expand Down Expand Up @@ -556,9 +564,6 @@ if(EMSCRIPTEN)
target_link_libraries(binaryen_wasm PRIVATE optimized "--closure=1")
# TODO: Fix closure warnings! (#5062)
target_link_libraries(binaryen_wasm PRIVATE optimized "-Wno-error=closure")
if (BYN_ENABLE_LTO)
target_link_libraries(binaryen_wasm PRIVATE optimized "-flto")
endif()
target_link_libraries(binaryen_wasm PRIVATE debug "--profiling")
# Avoid catching exit as that can confuse error reporting in Node,
# see https://github.com/emscripten-core/emscripten/issues/17228
Expand Down Expand Up @@ -610,9 +615,6 @@ if(EMSCRIPTEN)
endif()
# TODO: Fix closure warnings! (#5062)
target_link_libraries(binaryen_js PRIVATE optimized "-Wno-error=closure")
if(BYN_ENABLE_LTO)
target_link_libraries(binaryen_js PRIVATE optimized "-flto")
endif()
target_link_libraries(binaryen_js PRIVATE debug "--profiling")
target_link_libraries(binaryen_js PRIVATE debug "-sASSERTIONS")
# Avoid catching exit as that can confuse error reporting in Node,
Expand Down
Loading