[CMake] add_custom_command using CMAKE_CXX_FLAGS

Marcel Loose loose at astron.nl
Tue Aug 25 06:34:19 EDT 2009


Hi John,

I took a different approach to the problem you're describing.
Following the instructions on the Wiki
(http://www.cmake.org/Wiki/CMake/Assembler), I've written the three
required *ASM*.cmake files.
In the CMakeASM-<foo>Information.cmake file I've redefined the rule to
build .S files.

set(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS S)
set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM
${ASM_DIALECT}_COMPILER> <DEFINES> <FLAGS> -c -o <OBJECT> <SOURCE>")
set(CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE "<CMAKE_ASM
${ASM_DIALECT}_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET>
<LINK_LIBRARIES>")

The trick is in the second line; there I've added <DEFINES> so that any
relevant preprocessor variables will actually be passed when invoking
the compiler.

Furthermore, you need to make sure that the variable
CMAKE_ASM-<foo>_COMPILER points to your C or C++ compiler. This variable
must be set before you use the enable_language(<foo>) command.

Hope this helps.

Best regards,
Marcel Loose.


On Mon, 2009-08-24 at 13:38 -0400, John Smith wrote:
> 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
> _______________________________________________
> 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