[CMake] Parallel build with custom command

Ruslan Baratov ruslan_baratov at yahoo.com
Tue Oct 7 10:26:54 EDT 2014


On 07-Oct-14 18:00, Bill Hoffman wrote:
> On 10/7/2014 2:19 AM, Ruslan Baratov via CMake wrote:
>> Hi,
>>
>> I have a problem with parallel build of project with custom command.
>> Custom command generates two files and depends on generator script. For
>> optimization purpose first file created only when not exists. This lead
>> to conflict, even if I "protect" custom command with a custom target and
>> set explicit dependencies:
>
> Can you give an example?
Yes, I leave a links at the end of the previous message:

CMakeLists.txt: http://pastebin.com/dspw4j1S
generate.cmake: http://pastebin.com/XNS6hPRX
>
> add_dependencies should be what you use.
Have it:

add_custom_target(
     Generate
     ...
)
add_library(Alib "${A}")
add_library(Blib "${B}")
add_dependencies(Alib Generate)
add_dependencies(Blib Generate)

Tested on Ubuntu with Makefile generator:
  > cmake -H. -B_builds
  > cmake --build _builds -- -j4 # First build OK
  > touch generate.cmake
  > cmake --build _builds -- -j4 # Second build. Unexpected `Script run`

I'm expecting 1 message `Script run`, but I have 5 messages. If I modify 
`generate.cmake` script so it always write the file then everything 
works fine.

Ruslo


More information about the CMake mailing list