[CMake] add_custom_command using CMAKE_CXX_FLAGS

John Smith codeforgenator at gmail.com
Mon Aug 24 13:38:13 EDT 2009


On Aug 24, 2009, at 12:48 PM, Tyler Roscoe wrote:
> On Sun, Aug 23, 2009 at 09:03:22PM -0400, John Smith wrote:
>> I am using the following test case in an attempt to add a custom
>> command to build an assembly file. The assembly file should be
>> compiled with the C++ compiler driver (which in turn should invoke  
>> the
>> assembler after pre-processing), and I am building up a
>> CMAKE_CXX_FLAGS variable from separate pieces:
>
> I think you can just hand your .S files to add_library(). Did you try
> searching the ML archives or google for how to handle assembler files
> with CMake?

I have tried doing that. However, the net end result is that I get a  
rule that invokes the assembler on the assembly source file. My top- 
level assembly source file is a shell containing a bunch of platform- 
specific conditionals, which in turn guard include directives for  
platform-specific assembly source files. Thus, I want to have the C++  
compiler driver compile the top-level file; the compiler driver would  
first preprocess the include directives and then invoke the assembler  
on the resulting translation unit.

An example of such a technique is here: http://svn.apache.org/viewvc/stdcxx/trunk/src/atomic.s?revision=704153


>
>> set(CMAKE_CXX_FLAGS -m32)
>
> When you do this, you clobber the pre-existing value of  
> CMAKE_CXX_FLAGS,
> which has some defaults that are probably useful for your platform.  
> Are
> you sure this is what you want?

Poorly chosen example, my bad. The point was to show how a variable is  
constructed in my CMakeLists.txt and how it ends up being used.


>> [...]
>> add_library(test SHARED foo.cpp bar.S)
>
> Yeah I think you're overthinking this. Look for some CMake examples  
> that
> use assembler and go from there.
>


Most surely I am over-thinking it. After more local testing I think I  
understand how variables are processed in the generation of commands.  
I started from the command include_directories which actually builds a  
*list* of tokens, each an include directory to be used in (a) makefile  
rule. I noticed that using such a list as ARGS to ADD_CUSTOM_COMMAND  
results in the splitting of the list in separate tokens, i.e.:

set(FOO a b c)
ADD_CUSTOM_COMMAND(...
   ARGS ${FOO}
   ...)

ends up in a rule like:

<CMD> a b c ...

However, strings set up as:

set (FOO "a b c")

end up in the rule as:

<CMD> a\ b\ c ...

Therefore, I conclude that ARGS require lists, not strings of  
concatenated, space-separated options. Am I right in this?

Thanks for the help.

-J


More information about the CMake mailing list