[CMake] CMAKE_BUILD_TYPE and exact control of compiler options

René J. V. Bertin rjvbertin at gmail.com
Mon Oct 12 08:48:42 EDT 2015


Andreas Pakulat wrote:


> No this is not possible in general. A CMakeLists.txt file can always just
> set their own compiler/linker flags.

Which would require patching each and every one of them, which isn't exactly 
desirable.

>> - Out of curiosity, what's special about the CMAKE_BUILD_TYPE=Debian build
>> type?
>>
> 
> There's no such build type in CMake, see the Compilers and Tools section
> here: https://cmake.org/Wiki/CMake_Useful_Variables#Various_Options that
> details the built-in types in CMake.

I know it doesn't exist as a preset in CMake. But take a look at the CMake files 
shipped with KDE4's kdelibs: those actually introduce CMAKE_C*_FLAGS_DEBIAN 
variables (in addition to using specific install locations, for instance).
It's quite important that there is such a feature: configure and its alternatives 
are supposed to take CFLAGS, CXXFLAGS and family into consideration (or at least 
should have a mode in which they do, IMVHO).

I suppose that what happens is that requesting an unknown CMAKE_BUILD_TYPE is 
equivalent to not requesting one at all, and also prevents downstream CMake files 
to pick a default preset if CMAKE_BUILD_TYPE hasn't been defined by the caller.
I've had a better look at the control file I mentioned, and found the reason why 
$CFLAGS and $CXXFLAGS weren't being used. 

It turns out that if you set CMAKE_CXX_FLAGS on the commandline, it is no longer 
set to include $CXXFLAGS from the environment. Comments in the control file 
suggest that that wasn't always the case.

R.



More information about the CMake mailing list