0

What's the correct way to enable whole program optimization with CMake and g++? I know about CMake's INTERPROCEDURAL_OPTIMIZATION variable, but it looks like there are additional optimizations available if I specify -fuse-linker-plugin, -ffat-lto-objects, and possibly others.

What's the most aggressive optimization I can do in terms of cross-object optimization, and how do I enable this with g++ and CMake?

Thomas Johnson
  • 10,776
  • 18
  • 60
  • 98
  • If you now the command line options for the linker, then in CMake project you may add them via `CMAKE_EXE_LINKER_FLAGS` variable. Do not expect that CMake has a convenient variable or a target's property (like `INTERPROCEDURAL_OPTIMIZATION`) for every compiler/linker feature. Normaly, they add only features supported by all well-known compilers, or at least by several of them. – Tsyvarev Jun 01 '20 at 22:53
  • Use `target_compile_options` and `target_link_options`. Also, the good idea is to check if the compiler used to build your project supports them (e.g., using `check_cxx_compiler_flag`). – zaufi Jun 02 '20 at 18:45

0 Answers0