On Thu, Nov 18, 2010 at 1:08 PM, Denis Scherbakov
<denis_scherba...@yahoo.com> wrote:
> Here is a sample CMakeLists.txt to illustrate that two custom targets cannot 
> depend on each other:
>
> PROJECT(BUG C)
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
>
> ADD_CUSTOM_COMMAND(
>  OUTPUT  "${CMAKE_CURRENT_BINARY_DIR}/fileOne"
>  COMMAND "${CMAKE_COMMAND}"
>     ARGS "-E"
>          "touch"
>          "${CMAKE_CURRENT_BINARY_DIR}/fileOne")
>
> ADD_CUSTOM_TARGET(targetFileOne DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/fileOne")
>
> ADD_CUSTOM_COMMAND(
>  OUTPUT  "${CMAKE_CURRENT_BINARY_DIR}/fileOne-s"
>  COMMAND "${CMAKE_COMMAND}"
>     ARGS "-E"
>          "touch"
>          "${CMAKE_CURRENT_BINARY_DIR}/fileOne-s")
>
> ADD_CUSTOM_TARGET(targetFileOneS ALL DEPENDS targetFileOne 
> "${CMAKE_CURRENT_BINARY_DIR}/fileOne-s")
>
> $ gmake
> Scanning dependencies of target targetFileOne
> [  0%] Generating fileOne
> [ 50%] Built target targetFileOne
> Scanning dependencies of target targetFileOneS
> gmake[2]: *** No rule to make target `targetFileOne', needed by 
> `CMakeFiles/targetFileOneS'.  Stop.
> gmake[1]: *** [CMakeFiles/targetFileOneS.dir/all] Error 2
> gmake: *** [all] Error 2
>
> So I am back to my problem that I cannot compile my project in parallel.
> The question is: How to implement mutexes in CMake scripts?
>
> Denis
>
> --- On Thu, 11/18/10, David Cole <david.c...@kitware.com> wrote:
>
>> From: David Cole <david.c...@kitware.com>
>> Subject: Re: [CMake] Problems with parallel builds
>> To: "Denis Scherbakov" <denis_scherba...@yahoo.com>
>> Cc: cmake@cmake.org
>> Date: Thursday, November 18, 2010, 6:43 AM
>> Try:
>> ADD_CUSTOM_TARGET(MyHeaders ALL DEPENDS MyFile.hh)
>>
>> Without the "ALL" your target is not included in the set of
>> targets
>> built by a "make" or a "make all" -- without your target
>> included in
>> "make" there is nothing for the subsequent targets to
>> depend on.
>> Perhaps we should add a warning to add_dependencies if
>> expressing a
>> dependency on something not in "all" by default....
>>
>>
>> On Thu, Nov 18, 2010 at 9:33 AM, Denis Scherbakov
>> <denis_scherba...@yahoo.com>
>> wrote:
>> > Hi, David,
>> >
>> > I did as you suggested:
>> >
>> > ADD_CUSTOM_COMMAND(OUTPUT MyFile.hh ...)
>> > ADD_CUTSOM_TARGET(MyHeaders DEPENDS MyFile.hh)
>> >
>> > ADD_LIBRARY(MYLIB ${MYLIB_SRCS})
>> > ADD_DEPENDENCIES(MYLIB  MyHeaders)
>> >
>> > ADD_LIBRARY(MYLIBpic ${MYLIB_SRCS})
>> > ADD_DEPENDENCIES(MYLIBpic  MyHeaders)
>> >
>> > Didn't work. Target "MyHeaders" is build two times
>> when I do "gmake -j2"
>> > I see two "Generating MyFile.hh" lines and MyFile.hh
>> has duplicate lines.
>> >
>> > Denis
>> >
>> >> David Cole wrote:
>> >>
>> >> The easiest way to make this work is to have a
>> separate
>> >> custom target
>> >> that depends on the output of the custom command,
>> and then
>> >> to have the
>> >> two libraries depend on that custom target with
>> >> add_dependencies...
>> >>
>> >
>> >
>> >
>> >
>>
>
>
>
>

Instead of:
> ADD_CUSTOM_TARGET(targetFileOneS ALL DEPENDS targetFileOne 
> "${CMAKE_CURRENT_BINARY_DIR}/fileOne-s")

Try:
ADD_CUSTOM_TARGET(targetFileOneS ALL DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/fileOne-s")
ADD_DEPENDENCIES(targetFileOneS targetFileOne)

And you cannot specify more than one target name to parallel make and
expect it to work. It only works if you do "make" or "make
singleTarget".
_______________________________________________
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://www.cmake.org/mailman/listinfo/cmake

Reply via email to