[CMake] novice question about set of CMAKE_C_COMPILE_OBJECT variable

David Cole david.cole at kitware.com
Fri Sep 2 14:57:57 EDT 2011


CMAKE_C_COMPILE_OBJECT and friends are called "rule variables" --
they're described on and around p. 247 in the 5th Edition of the
Mastering CMake book.

It's covered in the "Porting CMake to New Platforms and Languages"
chapter. (Chapter 11 in the 5th Edition)

You're generally not supposed to set these rule variables in a
CMakeLists.txt file. They're supposed to be rules for the compiler
being used, and should not have to change from project to project.

But, if you must... The "official" way to override these rule
variables is to point to a "user make rules" file via the CMake
variable CMAKE_USER_MAKE_RULES_OVERRIDE:

  http://cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_USER_MAKE_RULES_OVERRIDE

In other words, you'd have your set call in a file named
"MyRules.cmake" like this:

  set(CMAKE_C_COMPILE_OBJECT "${target_compiler} -c <FLAGS> -o <OBJECT>")

And then, in your CMakeLists.txt file, you'd have:

  set(CMAKE_USER_MAKE_RULES_OVERRIDE
"${CMAKE_CURRENT_SOURCE_DIR}/MyRules.cmake")

Using that technique, CMake will be able to guarantee that the rules
are set prior to actually needing them. (i.e. -- in the middle of the
"project" or "enable_language" commands...)


Why do you have to override anyhow? Are you using a
not-fully-supported compiler?


HTH,
David


On Fri, Sep 2, 2011 at 2:30 PM, David Dunkle <ddunkle at arxan.com> wrote:
> This is a novice question, sorry. I have inherited a cmake build that is
> giving me trouble. Specifically this line might be at fault in a
> CMakeLists.txt file:
>
> set(CMAKE_C_COMPILE_OBJECT "${target_compiler} -c <FLAGS> -o <OBJECT>")
>
> I understand what CMAKE_C_COMPILE_OBJECT is doing, and what
> ${target_compiler} is set to, but I don't understand what <FLAGS> will be
> set to, and when it will be set. For that matter, although the syntax of
> <FLAGS> looks like it is a variable to be substituted, but what kind of
> variable is it? I can't seem to find any discussion of this in the
> documentation on cmake, including the book, that discuss this syntax of
> variables, the set command, etc.
>
> More specifically, I suspect that <FLAGS> is getting set to values that are
> incompatible with the ${target_compiler}, but I don't know that for certain.
> How can I find out? For example, is there a way to display the value <FLAGS>
> is getting, even if it means modifying the CMakeLists.txt to do so?
>
> -David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list