diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -24,7 +24,6 @@ set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") include(GNUInstallDirs) -include(WarningFlags) # Require out of source build. include(MacroEnsureOutOfSourceBuild) @@ -840,6 +839,8 @@ endif() # Setup all common build flags ================================================= +include(LTO) +include(WarningFlags) function(cxx_add_common_build_flags target) cxx_add_basic_build_flags(${target}) cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC}) @@ -848,6 +849,7 @@ cxx_add_rtti_flags(${target}) cxx_add_module_flags(${target}) cxx_link_system_libraries(${target}) + cxx_enable_lto(${target}) endfunction() #=============================================================================== diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -154,11 +154,13 @@ string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") endif() +include(LTO) include(WarningFlags) # Build the shared library. add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) cxx_add_warning_flags(cxxabi_shared_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC}) +cxx_enable_lto(cxxabi_shared_objects) if (LIBCXXABI_USE_LLVM_UNWINDER) if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY) target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared_objects) # propagate usage requirements @@ -243,6 +245,7 @@ # Build the static library. add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) cxx_add_warning_flags(cxxabi_static_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC}) +cxx_enable_lto(cxxabi_static_objects) if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY) target_link_libraries(cxxabi_static_objects PUBLIC unwind_static_objects) # propagate usage requirements target_sources(cxxabi_static_objects PUBLIC $) diff --git a/runtimes/cmake/Modules/LTO.cmake b/runtimes/cmake/Modules/LTO.cmake new file mode 100644 --- /dev/null +++ b/runtimes/cmake/Modules/LTO.cmake @@ -0,0 +1,8 @@ +include(CheckIPOSupported) +check_ipo_supported(RESULT _ipo_supported LANGUAGES C CXX) + +function(cxx_enable_lto target) + if (_ipo_supported) + set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() +endfunction()