Skip to content

Commit 6c01e3e

Browse files
committed
cmake: make LTO possible for gcc release builds
This adds a new CMake option `enable_LTO` when configuring with `CMAKE_BUILD_TYPE=Release` and compiler matches GNU. I want to figure out, whether our PFASST code can benefit from LTO. Signed-off-by: Torbjörn Klatt <[email protected]>
1 parent e008335 commit 6c01e3e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/3rdparty)
1616
option(pfasst_DISABLE_LIBCXX "Disable use of LLVM's libc++ when compiling with Clang." ON )
1717
option(pfasst_BUILD_SHARED_LIBS "Build shared libraries." ON )
1818
option(pfasst_BUILD_EXAMPLES "Build example programs." ON )
19-
CMAKE_DEPENDENT_OPTION(pfasst_INSTALL_EXAMPLES "Install example programs." ON
20-
"pfasst_BUILD_EXAMPLES" OFF)
19+
cmake_dependent_option(
20+
pfasst_INSTALL_EXAMPLES "Install example programs." ON
21+
"pfasst_BUILD_EXAMPLES" OFF)
2122
option(pfasst_BUILD_TESTS "Build test suite for PFASST." ON )
2223
option(pfasst_WITH_MPI "Build with MPI enabled." ON )
2324
option(pfasst_WITH_GCC_PROF "Enable excessive debugging & profiling output with GCC." OFF)
2425
option(pfasst_DEFAULT_RAND_SEED "Using a hardcoded random seed" ON )
26+
cmake_dependent_option(
27+
enable_LTO "enable LinkTimeOptimization" OFF
28+
"CMAKE_BUILD_TYPE" Release)
2529

2630
if(${pfasst_WITH_MPI})
2731
find_package(MPI REQUIRED)
@@ -54,6 +58,12 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
5458
if(pfasst_WITH_GCC_PROF)
5559
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-ggdb3 -pg")
5660
endif(pfasst_WITH_GCC_PROF)
61+
if(${CMAKE_BUILD_TYPE} MATCHES "Release" AND ${enable_LTO})
62+
message(STATUS "enabling Link Time Optimization (LTO)")
63+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto -fwhole-program")
64+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto")
65+
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -flto")
66+
endif()
5767
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
5868
check_cxx_compiler_flag(-std=c++11 HAVE_STD11)
5969
if(HAVE_STD11)

0 commit comments

Comments
 (0)