2013/8/12 Paul Smith <[email protected]>: > Hi all. > > I've got a situation where I'm creating generated source files (from > bison/flex, actually, but I'm writing my own rules for it since I need > specialized support for C++ output, etc.) > > However I need to compile the generated output into two different libraries, > building two different ways (with different #defines/compiler flags). > > So I have tried using add_custom_command() with OUTPUT, but the > documentation says: > > "Do not list the output in more than one independent target that may build > in parallel or the two instances of the rule may conflict (instead use > add_custom_target to drive the command and make the other targets depend on > that one)." > > > Sure enough, it seems that if I have my different libraries depend on these > outputs I get problems during parallel builds. So then I tried to use > add_custom_target(), but that says: > > "The target has no output file and is ALWAYS CONSIDERED OUT OF DATE" > > > and, sure enough, if I do it this way my source files (and everything that > depends on them) rebuild every time I run the build, even if nothing has > changed. This is a big bummer.
I did never tried befoire but think you should "simply" keep your
current add_custom_command
and create a new target with add_custom_target whose only purpose is
to "serialize"
the dependency for the 2 (or more) independent libraries which use the
output of your custom command
concurrently.
Something like:
cmake_minimum_required(VERSION 2.8.10)
project(ParallelAddCustomCommand C)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.c
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/template.c
${CMAKE_CURRENT_BINARY_DIR}/generated.c)
add_custom_target(SerializeTarget
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated.c)
add_library(MyLib1 ${CMAKE_CURRENT_BINARY_DIR}/generated.c lib1.c)
set_target_properties(MyLib1 PROPERTIES COMPILE_FLAGS -DDEFGEN=3)
add_dependencies(MyLib1 SerializeTarget)
add_library(MyLib2 ${CMAKE_CURRENT_BINARY_DIR}/generated.c lib2.c)
set_target_properties(MyLib2 PROPERTIES COMPILE_FLAGS -DDEFGEN=4)
add_dependencies(MyLib2 SerializeTarget)
> How can I have generated source files compiled different ways into different
> libraries, but not have them (and anything that depends on them) rebuilt
> every time?
>
>
> The only way I've thought of so far is to have two different
> add_custom_command() options with the same input but different output (in
> different directories maybe), one for each target. This means I need to
> generate the files twice even though the output source files will have
> identical content. But as long as I don't have to REBUILD them every time
> maybe that's not so bad. I haven't tried this yet though. Are there other
> options?
I tried to craft some working example which is attached to this mail.
--
Erk
L'élection n'est pas la démocratie -- http://www.le-message.org
ParallelAddCustomCommand.tgz
Description: GNU Zip compressed data
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
