[CMake] Projects with C++ and Assembly

Brad King brad.king at kitware.com
Wed Jun 22 13:16:07 EDT 2005


Mr David McKinnon wrote:
> Hi,
>   here is the functioning script I have in a lower directory cmake file
> passing the terrain_asm_obj varibale containing the .obj file generated
> from src.asm.
> 
> SET(src ${CMAKE_CURRENT_SOURCE_DIR}/${terrain_asm_sources}.asm)
> SET(obj ${TGE_BINARY_DIR}/Debug/${terrain_asm_sources}.obj)
> ADD_CUSTOM_COMMAND(OUTPUT ${obj}
>                    MAIN_DEPENDENCY ${src}
>                    COMMAND ${TGE_SOURCE_DIR}/bin/nasm/nasmw.exe
>                    ARGS -fwin32 ${src})
> SET(terrain_asm_obj ${obj} CACHE INTERNAL "cache")
> 
> I then intend to create a library from the .obj file using - perhaps the
> ADD_LIBRARY(asm_library ${terrain_asm_obj})command - but I do not
> understand how to create libraries using .obj files as opposed to
> standard source files.

You should just be able to add the object files like you do other 
sources.  CMake has support for "external object files" that should get 
included when linking the library.  This has not been well-tested, 
though.  You may need at least one .c source file even if it doesn't 
have any code to tell CMake what language's linker should be used to 
link the library.

> Furthermore how would I then bind two different libraries into single
> library?

There is no standard cross-platform way to do this so it is not possible 
right now (we have a solution in mind but it is not yet implemented). 
In your case though since you already have the individual object files 
you can just use the same object in more than one library.

-Brad


More information about the CMake mailing list