diff --git a/nc_optimisation.cmake b/nc_optimisation.cmake index 00c0513..add187c 100644 --- a/nc_optimisation.cmake +++ b/nc_optimisation.cmake @@ -8,12 +8,27 @@ option(ENABLE_LTO "enable link-time optimisation" OFF) ##----------------------------------------------------------------------------- +## Enable link-time optimisation. +## +## Rather than rely on the INTERPROCEDURAL_OPTIMISATION flag we add some +## arguments explicitly because we want a little more control over object +## creation. if (ENABLE_LTO) + # Add the linker flags first otherwise the linker may not recognise the + # object format + append_link_flag("-fuse-linker-plugin") + append_link_flag("-flto") + + # Actually enable LTO object creation, but try very hard to avoid + # situations where we may accidentally use regular/fat objects. append_compile_flag("-flto") append_compile_flag("-fno-fat-lto-objects") - append_link_flag("-fuse-linker-plugin") - append_compile_flags("-fdevirtualize-at-ltrans") -endif (ENABLE_LTO) + + # Throw in some optimisation flags that are LTO specific. We don't + # particularly care about checking Debug/Release here because LTO is + # pretty heavyweight anyway. + append_compile_flag("-fdevirtualize-at-ltrans") +endif () ###############################################################################