[CMake] How to set platform-specific compiler-options from within CMakeFiles

Philip Lowman philip at yhbt.com
Wed Jul 2 23:57:02 EDT 2008


On Fri, Jun 6, 2008 at 9:00 AM, Bill Hoffman <bill.hoffman at kitware.com>
wrote:

> Martin Apel wrote:
>
>> Mike Jackson wrote:
>>
>>> typically, the PROJECT() statement is the first line of your
>>> CMakeLists.txt. Could you explain your project layout a bit more?
>>>
>>>
>>>  I found out, that CMAKE_CXX_FLAGS is set to the compound of
>> $ENV{CXXFLAGS} and the platform-specific default at the time, the PROJECT
>> statement is executed.
>> In order to preset CMAKE_CXX_FLAGS I tried to set $ENV{CXXFLAGS} from
>> within the CMakeFile. Thus this setting has to be done before the PROJECT
>> statement, otherwise
>> CMAKE_CXX_FLAGS is already set. So I tried to include an external file by
>> INCLUDE (${CMAKE_SYSTEM_NAME}.cmake)
>> before the PROJECT statement. This doesn't work, because
>> ${CMAKE_SYSTEM_NAME} is not set at that time.
>>
>> When setting CMAKE_CXX_FLAGS after the PROJECT statement, the CMake-local
>> variable is set correctly, but the cache is not updated. The situation I
>> tried to achieve, was to preset
>> the cache variable CMAKE_CXX_FLAGS to include certain compiler flags. If
>> the user looked at the cache e.g. by using ccmake, he would also see and be
>> able to edit those additional flags.
>> By setting the flags later, you only change the CMake-local variable, but
>> never the cache value, which is somewhat irritating, because the compile
>> happens with other flags than can be seen using
>> ccmake.
>>
>
> You want to use this variable:
> CMAKE_USER_MAKE_RULES_OVERRIDE
>
> You can set that to a file that will be loaded at the right time so you can
> set the cache variables yourself.


Wow this is an old thread.  Sorry for the late response.

I think what's needed here is a way to detect the platform and allow people
to modify CMAKE_CXX_FLAGS and friends before they get cemented in stone in
the cache.  IIRC doesn't CMAKE_USER_MAKE_RULES_OVERRIDE put the onus on the
user to know the proper platform, compiler, etc. before they set the flags?

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080702/623d7595/attachment.htm>


More information about the CMake mailing list