[cmake-developers] Fwd: Chaining custom commands in VS 2010

David Cole david.cole at kitware.com
Wed Dec 5 06:03:56 EST 2012


As a workaround, you could try isolating the "generating obj" and
"combining obj" commands into their own respective custom targets, and then
making the target dependencies specify the ordering. That might kick the
VS10 dependency analysis enough to make it work. Not ideal, but not too
hard to try either.



On Tue, Dec 4, 2012 at 7:30 PM, James Bigler <jamesbigler at gmail.com> wrote:

> Is there something CMake can do to correct this error/bug with VS 2010?
>
>
> ---------- Forwarded message ----------
> From: James Bigler <jamesbigler at gmail.com>
> Date: Mon, Dec 3, 2012 at 3:42 PM
> Subject: Chaining custom commands in VS 2010
> To: "cmake at cmake.org" <cmake at cmake.org>
>
>
> 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}
>   )
>
>
>
>
> --
>
> 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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20121205/6ad00dec/attachment.html>


More information about the cmake-developers mailing list