[CMake] Output of ADD_CUSTOM_COMMAND generated multiple times
Martin Apel
martin.apel at simpack.de
Wed Oct 8 11:04:41 EDT 2008
Brad King wrote:
> We've built huge projects with thousands of custom build rules while
> still only having a few custom targets. Your original example can be
> written like this:
>
> ADD_CUSTOM_COMMAND(
> OUTPUT ${CMAKE_BINARY_DIR}/a
> COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/a
> )
> ADD_CUSTOM_COMMAND(
> OUTPUT ${CMAKE_BINARY_DIR}/b
> COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/b
> DEPENDS ${CMAKE_BINARY_DIR}/a
> )
> ADD_CUSTOM_COMMAND(
> OUTPUT ${CMAKE_BINARY_DIR}/c
> COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/c
> DEPENDS ${CMAKE_BINARY_DIR}/a
> )
> ADD_CUSTOM_TARGET(world
> DEPENDS ${CMAKE_BINARY_DIR}/b ${CMAKE_BINARY_DIR}/c
> )
>
> Now the 'world' target contains all the rules and will build 'a' first,
> then 'b' and 'c' in parallel.
>
>
Thanks a lot, Brad. This approach improves my build output very much!
>> I think CMake should be smart enough to handle this without the extra
>> targets, at least as long as all of them are in
>> the same directory. That is what the "generated" attribute of a source
>> file is about, isn't it.
>> But for now, I will modify my CMakeLists.txt to contain the extra targets.
>>
>
> There is a feature request here:
>
> http://www.cmake.org/Bug/view.php?id=6285
>
> However, the solution I have in mind for it will still not handle your
> case. You're basically telling two different targets how to build a
> file, and not adding any other dependencies to control the order.
>
> Each target gets built with its own make process. It is at this stage
> that file-level dependencies are evaluated by the build system. A
> higher-level make process considers only inter-target dependencies with
> symbolic (phony) targets.
>
It would be nice, if CMake could compute these dependencies
automatically, but there have to be
some features left for CMake 3.0 :-)
Martin
____________
Virus checked by G DATA AntiVirus
Version: AVB 19.56 from 08.10.2008
More information about the CMake
mailing list