I’m having some problems when I try to check/enable IPO only for my application!
This is the project structure:
project
CMakeLists.txt <-- works for all modules including the externals
- external
CMakeLists.txt
- src
CMakeLists.txt <-- doesn't work
If I use this code inside the root CMake file, it works fine, it enables the IPO and I can see the flag being used.
# === IPO ===
if(OPTIONS_ENABLE_IPO)
log_option_enabled("ipo")
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
log_war("IPO is not supported: ${output}")
endif()
else()
log_option_disabled("ipo")
endif()
But when I use the same code inside my src/CMakeLists.txt file, it says that the compiler doesn’t support the IPO feature.
IPO is not supported: CMake doesn’t support IPO for current C compiler
Also tried to use: set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
I didn’t understood why I need to keep it on my root file as I am using some external modules, if I keep it there, it will be used on all externals modules.
However, I lately realized that check_ipo_supported requires the project command to have been called in order to probably know some required variables.
Maybe it is not enough to have the top-most project command being called but instead the one of the currently processed CMakeLists.txtfile needs to have been called? (As I said, just a wild guess.)
Tested here, added the project definition inside the src/CMakeFolder, but it didn’t worked, it complains that the compiler doesn’t support IPO, I think that is something related with the dependencies that if not compiled or linked with the IPO flag, blocks my application also to use it.
For now I am using on the root cmake file, what makes all external components use IPO enabled and throw a lot of warning, but at least it optimizing the code!