[CMake] novice question about set of CMAKE_C_COMPILE_OBJECT variable

David Dunkle ddunkle at arxan.com
Fri Sep 2 16:24:54 EDT 2011


I inherited this code, so I am trying to figure it out myself, with
learning cmake part of the work involved.

In this case, the cmake build of a project is using the standard gcc
compiler on Linux for most of the project, but a few pieces of the
project need to be built with an (llvm-gcc) cross compiler with certain
options. So I think the code in CMakeLists.txt is meant to change
compilers and compiler options for the subdirectory needing the cross
build. Actually, there is a set of subdirectories each needing a
different compiler and options.

Specifically why CMAKE_C_COMPILER_OBJECT is being set is not clear to
me.  Could CMAKE_C_COMPILER be set instead? The code (CMakeLists.txt
file) at this point sets CMAKE_C_FLAGS so it looks basically like this:

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

David W. Dunkle
Arxan Technologies, Inc.
w:415-445-1350 x19   f:415-445-1340
ddunkle at arxan.com   www.arxan.com

Arxan protects your IP from software piracy, tampering, reverse
engineering, and any manner of theft.

-----Original Message-----
From: David Cole [mailto:david.cole at kitware.com] 
Sent: Friday, September 02, 2011 11:58 AM
To: David Dunkle
Cc: cmake at cmake.org
Subject: Re: [CMake] novice question about set of CMAKE_C_COMPILE_OBJECT
variable

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