[CMake] CMAKE_C*_FLAGS undefined.

Philip Lowman philip at yhbt.com
Fri Apr 3 22:44:19 EDT 2009


On Fri, Apr 3, 2009 at 9:16 AM, Óscar Fuentes <ofv at wanadoo.es> wrote:

> I have this:
>
> add_custom_command(OUTPUT ${LLVM_CONFIG}
>  COMMAND echo "flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CPP_FLAGS}
> ${CMAKE_C_FLAGS}"
> .... more stuff ....
>
>
> When the custom command executes, this is the output:
>
> flags:
>
> i.e. the variables are empty, although I previously used add_definitions
> to add flags and the makefile uses the optimization flags that
> corresponds to the selected build type.
>
> How can I access the effective values of the flags used when the
> makefile is generated?


Hi Oscar,

CMAKE_CXX_FLAGS / CMAKE_C_FLAGS is empty by default on Linux unless you've
modified it which may have been what happened.  The build type specific
complilation flags are stored in CMAKE_CXX_FLAGS_<config_type>.
CMAKE_CXX_FLAGS is a base that gets prepended to all of the build solutions.

The command pasted below works for me on CMake 2.6.4 RC3 Win32 using the
MinGW generator (it outputs the flags used to compile during a Release
build).  If something like this doesn't work for you can you reply with your
version of CMake and generator you're using?

add_custom_target(foo COMMAND C:/cygwin/bin/echo.exe flags:
${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})

Also, to possibly anticipate your next question: On Makefile generators you
should be able to get the current build type being used by the end user by
referencing CMAKE_BUILD_TYPE.  Note that empty is a supported build type in
which case only CMAKE_CXX_FLAGS would be used.  On multi-solution generators
like for Visual Studio you won't be able to tell the CMAKE_BUILD_TYPE at
configure time so you'd pretty much have to just pick one or more
configuration types to output.

HTH

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


More information about the CMake mailing list