[CMake] Chaining custom commands in VS 2010
James Bigler
jamesbigler at gmail.com
Mon Dec 3 17:42:06 EST 2012
I'm trying to add a custom command that takes one output and generates an
additional output.
source1.cpp -> source1.obj
source2.cpp -> source2.obj
source1.obj + source2.obj -> temp.obj
link source1.obj source2.obj temp.obj
For VS 2008 and Makefiles, this works out just fine. For VS 2010 it
doesn't seem to understand that if source1.obj or source2.obj changes that
it needs to run the temp.obj build rule. The dependencies look correct in
the project.
In a fresh build it builds source1.obj, source2.obj and temp.obj just fine.
In subsequent builds where source1.obj or source2.obj are compiled, it
fails to build temp.obj on the first build command (as if it didn't
understand that building source1.obj or source2.obj were a dependency for
temp.obj). On a subsequent build, MSbuild recognizes that source1.obj or
source2.obj have changed and runs the build command for temp.obj.
I've attached the zip file if anyone cares to take a look. Here's the
CMake code inlines, in case mail systems eat the zip file. source1.cpp and
source2.cpp don't have anything really useful in it.
cmake_minimum_required(VERSION 2.8.0)
project(obj-translate)
set(s1 "${CMAKE_CURRENT_SOURCE_DIR}/source1.cpp")
set(s2 "${CMAKE_CURRENT_SOURCE_DIR}/source2.cpp")
set(o1 "${CMAKE_CFG_INTDIR}/source1${CMAKE_CXX_OUTPUT_EXTENSION}")
set(o2 "${CMAKE_CFG_INTDIR}/source2${CMAKE_CXX_OUTPUT_EXTENSION}")
set(temp "${CMAKE_CFG_INTDIR}/temp${CMAKE_CXX_OUTPUT_EXTENSION}")
add_custom_command(
OUTPUT ${o1}
MAIN_DEPENDENCY ${s1}
COMMAND ${CMAKE_CXX_COMPILER} ${s1} -c "/Fo\"${o1}\""
COMMENT "11111111111111 Making ${s1} -> ${o1}\n\n"
)
add_custom_command(
OUTPUT ${o2}
MAIN_DEPENDENCY ${s2}
COMMAND ${CMAKE_CXX_COMPILER} ${s2} -c "/Fo\"${o2}\""
COMMENT "22222222222222 Making ${s2} -> ${o2}\n\n"
)
add_custom_command(
OUTPUT ${temp}
DEPENDS ${o1} ${o2}
COMMAND "${CMAKE_COMMAND}" -E copy "${o1}" "${temp}"
COMMENT "TTTTTTTTTTTTTT Making ${o1} + ${o2} -> ${temp}\n\n"
)
set_source_files_properties("${s1}" "${s2}"
PROPERTIES
HEADER_FILE_ONLY TRUE # Don't let VS compile this file
)
set_source_files_properties("${o1}" "${o2}" "${temp}"
PROPERTIES
GENERATED TRUE # This file is generated during the build
EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but
only be linked.
)
add_library(obj-translate STATIC
${s1} ${s2} ${temp} ${o1} ${o2}
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121203/2de46126/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: obj-translate.zip
Type: application/zip
Size: 1290 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121203/2de46126/attachment-0001.zip>
More information about the CMake
mailing list