[CMake] add_custom_command using CMAKE_CXX_FLAGS
Tyler Roscoe
tyler at cryptio.net
Mon Aug 24 12:48:30 EDT 2009
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?
> 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?
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
>
> message (STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
>
> file (GLOB ASM_SRCS bar.S)
As a general rule, you probably don't want to use file (GLOB ...). Here
you can just say set(ASM_SRCS bar.S).
> foreach (src ${ASM_SRCS})
> get_filename_component (FILE_BASE ${src} NAME_WE)
> set (SRC ${src})
> set (OBJ ${CMAKE_CURRENT_BINARY_DIR}/${FILE_BASE}.o)
> add_custom_command (OUTPUT ${OBJ}
> MAIN_DEPENDENCY ${SRC}
> COMMAND ${CMAKE_CXX_COMPILER}
> ARGS ${CMAKE_CXX_FLAGS} -o ${OBJ} -c ${SRC}
> MAIN_DEPENDENCY ${src})
> set (ASM_OBJS ${ASM_OBJS} ${OBJ})
> endforeach(src)
>
> 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.
tyler
More information about the CMake
mailing list