Dear All, I'm running into a new issue with my custom commands. :-(
I have a project with many subdirectories. Where most subdirectories generate some files during the build. Some of which need to be merged into a single file at the end of the build. In my current implementation the subdirectories declare both a custom command and a custom target for generating these files. So that the merge command in the main directory could depend on the custom targets of the subdirectories. (As the merge command can't depend on the generated files themselves directly.) Now, the merge command is not the only use using these generated files. They are also used inside the subdirectories in order to build some libraries. And now the problem comes. Apparently CMake / GNU Make doesn't make sure that the generation command would only run once. Attached is a simple example. When running make in single-process mode, things happen as I would expect them to. Scanning dependencies of target SubdirTarget [ 33%] Generating partialFile.txt [ 33%] Built target SubdirTarget Scanning dependencies of target MergeTarget [ 66%] Generating merged.txt [ 66%] Built target MergeTarget Scanning dependencies of target CompileSubdirTarget [100%] Built target CompileSubdirTarget But when I use multiple build processes, I get: Scanning dependencies of target SubdirTarget Scanning dependencies of target CompileSubdirTarget [ 66%] Generating partialFile.txt [ 66%] Generating partialFile.txt [ 66%] Built target CompileSubdirTarget [ 66%] Built target SubdirTarget Scanning dependencies of target MergeTarget [100%] Generating merged.txt [100%] Built target MergeTarget So, the file generation gets triggered twice at the same time. Of course in this simple example this wouldn't matter. But the generator that I use in real life can't handle this. As it creates some temporary files as it runs, which interfere with each other. So I come out with a corrupt output file. Does anyone have any suggestions? I would really need to be able to make sure that this custom command would not be executed multiple times. And most of all, not multiple times at once. Cheers, Attila P.S. It seems that the Ninja generator is a bit better in this respect. But of course it's not an option to not have my project work correctly with the Makefile generator.
custom_command_concurrency.tar.bz2
Description: BZip2 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://public.kitware.com/mailman/listinfo/cmake