[CMake] Link in object files generated by another tool
Hugo Heden
hugoheden at gmail.com
Tue Nov 25 05:26:36 EST 2008
2008/11/24 James Bigler <jamesbigler at gmail.com>:
> Is it possible to link in an object file generated by another tool?
>
> I want to create a custom command that generates an object file that I
> could then link into a library or executable later.
>
> Is this possible from CMake?
>
An example follows. The ADD_CUSTOM_COMMAND that you may be looking for
is at the bottom.
SET( EXPAT_DIR_STRING expat-2.0.1 )
SET( expat_fpic_object_files
${CMAKE_CURRENT_BINARY_DIR}/${EXPAT_DIR_STRING}/lib/.libs/xmlparse.o
${CMAKE_CURRENT_BINARY_DIR}/${EXPAT_DIR_STRING}/lib/.libs/xmlrole.o
${CMAKE_CURRENT_BINARY_DIR}/${EXPAT_DIR_STRING}/lib/.libs/xmltok.o
)
ADD_LIBRARY(
expat
STATIC
EXCLUDE_FROM_ALL
${expat_fpic_object_files}
)
SET_SOURCE_FILES_PROPERTIES(
${expat_fpic_object_files}
PROPERTIES
EXTERNAL_OBJECT true # to say that "this is actually an object file,
so it should not be compiled, only linked"
GENERATED true # to say that "it is OK that the obj-files do
not exist before build time"
)
SET_TARGET_PROPERTIES(
expat
PROPERTIES
LINKER_LANGUAGE C # Or else we get an error message, because cmake
can't figure out from the ".o"-suffix that it is a C-linker we need.
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
)
ADD_CUSTOM_COMMAND(
OUTPUT
${expat_fpic_object_files}
WORKING_DIRECTORY ....
COMMAND ....# Some tool
COMMAND ....# Some tool
More information about the CMake
mailing list