Interprocedural Optimization
Explore how to set up interprocedural optimization in your CMake project, verify compiler support, and ensure smooth builds using CMake's feature checks and test commands. Understand how to improve performance by enabling link-time optimizations and creating feature test files to catch potential compiler issues early.
We'll cover the following...
Usually, compilers optimize the code on the level of a single translation unit, which means that our .cpp file will be preprocessed, compiled, and then optimized. Later, these files will be passed to the linker to build a single binary. Modern compilers can perform optimization after linking (this is called link time optimization) so that all compilation units can be optimized as a single module. If our compiler supports CMAKE_INTERPROCEDURAL_OPTIMIZATION. But before we set it, we need to make sure it is supported to avoid errors:
As you can see, we had to include a built-in module to get access to the check_ipo_supported() command.