I have a CMake Toolchain file that cross compiles for arm-linux on an x86_64-linux host.
During configuration, my toolchain file is parsed and it (correcty) finds a GNU compiler. Therefore it will load GNU.cmake
(in my case /usr/share/cmake-3.10/Modules/Compiler/GNU.cmake
). The including hierarchy here is unclear to me (could not find documentation. Any link is appreceated). However it seems like this:
- root
CMakeLists.txt
toproject()
- my toolchain.cmake
- stuff in modules dir (including
GNU.cmake
) - loads
%_INIT
variables to%
Cache variables - continue after
project()
Say i want this target to build only with -O2 optimization. I set it in my toolchain, because it is then global for many project.
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O2")
but then GNU.cmake is loaded and appends it with "-O3". Therefore my setting is overwritten. After this i can only overwrite it in my projects CMakeLists.txt
files. I would have to do this for each project, and developers will miss this!
So, my question is (repeating the headline): How to overwrite settings from CMake modules from toolchain file?