[CMake] CMAKE_C*_FLAGS undefined.

Óscar Fuentes ofv at wanadoo.es
Sat Apr 4 14:37:04 EDT 2009


Philip Lowman <philip at yhbt.com> writes:

[snip]

> One suggestion would be if you have non-definition flags you want to add to
> every compilation you make, simply use CMAKE_C_FLAGS or CMAKE_CXX_FLAGS.
>
> if(CMAKE_COMPILER_IS_GNU_CC)
>    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,s -save-temps")
> endif()

Wouldn't this conflict with the cache?

> add_definitions() was originally intended for preprocessor definitions
> only.  If you're using it to non-definition compilation flags I have no idea
> how you'll be able to pull those out again.

As per my interpretation of the docs, add_definitions is the recommended
way of adding extra compiler options. I may wrong.

>> OTOH, what happens if the user sets CFLAGS and other environment
>> variables that affects the build after cmake is run? I ask just out of
>> curiosity, as I know that the method I'm using for configuring the file
>> does not take into account this possibility.
>
> You can set CFLAGS and/or CXXFLAGS but they only work before the first
> configure.  After that they are ignored.  If you need to change
> CFLAGS/CXXFLAGS after that the best way is to modify CMAKE_C_FLAGS and
> CMAKE_CXX_FLAGS in the CACHE.

Thanks.

>> I can't believe that there is not a simple method for knowing such a
>> basic piece of information as "which compiler switches and options are
>> used for compiling source files of language X?" so it seems that I'm
>> missing something.
>
> There might be a better way to do this I'm not aware of.  If so hopefully
> someone else can chime in.

Okay. Thanks for your help so far Philip.

-- 
Oscar



More information about the CMake mailing list