@@ -31,7 +31,7 @@ endif()
3131# more useful error reports from users.
3232option (BYN_ENABLE_ASSERTIONS "Enable assertions" ON )
3333
34- option (BYN_ENABLE_LTO "Build with LTO" Off )
34+ option (BYN_ENABLE_LTO "Build with LTO" ${EMSCRIPTEN} )
3535
3636# Turn this off to avoid the dependency on gtest.
3737option (BUILD_TESTS "Build GTest-based tests" ON )
@@ -341,8 +341,10 @@ if(EMSCRIPTEN)
341341 # On Node.js, make the tools immediately usable.
342342 add_link_flag ("-sNODERAWFS" )
343343 endif ()
344+ if (BYN_ENABLE_LTO)
344345 # in opt builds, LTO helps so much (>20%) it's worth slow compile times
345346 add_nondebug_compile_flag ("-flto" )
347+ endif ()
346348 if (EMSCRIPTEN_ENABLE_WASM64)
347349 add_compile_flag ("-sMEMORY64 -Wno-experimental" )
348350 add_link_flag ("-sMEMORY64" )
@@ -523,7 +525,9 @@ if(EMSCRIPTEN)
523525 target_link_libraries (binaryen_wasm PRIVATE optimized "--closure=1" )
524526 # TODO: Fix closure warnings! (#5062)
525527 target_link_libraries (binaryen_wasm PRIVATE optimized "-Wno-error=closure" )
526- target_link_libraries (binaryen_wasm PRIVATE optimized "-flto" )
528+ if (BYN_ENABLE_LTO)
529+ target_link_libraries (binaryen_wasm PRIVATE optimized "-flto" )
530+ endif ()
527531 target_link_libraries (binaryen_wasm PRIVATE debug "--profiling" )
528532 # Avoid catching exit as that can confuse error reporting in Node,
529533 # see https://github.com/emscripten-core/emscripten/issues/17228
@@ -575,7 +579,9 @@ if(EMSCRIPTEN)
575579 endif ()
576580 # TODO: Fix closure warnings! (#5062)
577581 target_link_libraries (binaryen_js PRIVATE optimized "-Wno-error=closure" )
578- target_link_libraries (binaryen_js PRIVATE optimized "-flto" )
582+ if (BYN_ENABLE_LTO)
583+ target_link_libraries (binaryen_js PRIVATE optimized "-flto" )
584+ endif ()
579585 target_link_libraries (binaryen_js PRIVATE debug "--profiling" )
580586 target_link_libraries (binaryen_js PRIVATE debug "-sASSERTIONS" )
581587 # Avoid catching exit as that can confuse error reporting in Node,
0 commit comments