[CMake] CMAKE_BUILD_TYPE and exact control of compiler options

René J. V. Bertin rjvbertin at gmail.com
Tue Oct 13 06:52:01 EDT 2015


Dan Liew wrote:

> Hi,
> 
> 
>> - If not, what is the best/official way to get exact control over the
>> compiler and linker options used?
> 
> I had to do something similar recently where I didn't want
> ``-DNDEBUG`` to be in any of the configurations.
> 
> I used  ``CMAKE_USER_MAKE_RULES_OVERRIDE `` to set the path to file
> containing overrides, this must be set before calling ``project()``

> I'm not sure if this is really the correct route to go down though for
> your use case.

That wouldn't be impossible. A more generic way to achieve what you did, one 
that doesn't require patching "client" CMake files (which I find unacceptable):

Store the customised settings in a file (I'd call it cmake.initcache) and call 
cmake as

%> cmake -C./cmake.initcache "$@"

This is an approach I follow with a more basic building workflow of my own, one 
where I keep localised/customised settings (CC/CXX, CFLAGS/CXXFLAGS, LDFLAGS 
etc) in a ./wconfigure.env file, which is parsed by wrappers to configure and 
cmake. It's not a usual approach for MacPorts, though.

R.



More information about the CMake mailing list