MantisBT - CMake
View Issue Details
0011407CMakeCMakepublic2010-11-04 19:542011-01-12 07:44
Steve King 
Brad King 
normalfeaturealways
closedfixed 
CMake-2-8 
CMake 2.8.4CMake 2.8.4 
0011407: Allow output from add_custom_target() to support external makefiles
There seems to be no satisfactory way to use cmake to drive external Makefiles as a step in a larger build process. This is due to:
1) External makefiles must always run to process their own dependencies which are invisible to CMake.
2) add_custom_target() is a natural choice to drive the external makefile. However, add_custom_target() cannot specify an output.
3) add_custom_command() can specify an output, but does not always run since it cannot see the external dependencies known only to the Makefile.
No tags attached.
Issue History
2010-11-04 19:54Steve KingNew Issue
2010-11-05 01:12Steve KingNote Added: 0022889
2010-11-05 08:10Brad KingStatusnew => assigned
2010-11-05 08:10Brad KingAssigned To => Brad King
2010-11-05 08:11Brad KingNote Added: 0022893
2010-11-05 08:11Brad KingStatusassigned => closed
2010-11-05 08:11Brad KingResolutionopen => fixed
2010-11-05 13:49Steve KingNote Added: 0022906
2010-11-05 13:49Steve KingStatusclosed => feedback
2010-11-05 13:49Steve KingResolutionfixed => reopened
2010-11-05 13:59Brad KingNote Added: 0022908
2010-11-05 16:17Steve KingNote Added: 0022925
2010-11-05 16:48Brad KingStatusfeedback => closed
2010-11-05 16:48Brad KingResolutionreopened => fixed
2011-01-12 07:44David ColeFixed in Version => CMake 2.8.4
2011-01-12 07:44David ColeTarget Version => CMake 2.8.4

Notes
(0022889)
Steve King   
2010-11-05 01:12   
add_custom_command() can be used to drive external makefiles so long as no DEPENDS statement is used. Would be nice if the documentation could explicitly state that removing DEPENDS will cause add_custom_command to always run, mentioning makefiles specifically.
(0022893)
Brad King   
2010-11-05 08:11   
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=80edcc6a [^]
(0022906)
Steve King   
2010-11-05 13:49   
My previous comment was wrong. Add_custom_command() does not always run when no DEPENDS statement is specified. So this issue remains open and add_custom_command is not able to drive an external makefile that produces an output.

The follow simple test case demonstrates this problem. For simplicity, this is an in-source build.

> cat external_makefile
bar : foo
        touch bar

> cat CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT( makefile_test )

ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/bar
        COMMAND make -f ${CMAKE_CURRENT_SOURCE_DIR}/external_makefile
        COMMENT "Running external makefile"
        )

ADD_CUSTOM_TARGET( external_target ALL
        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bar
        )


After running cmake, we see
> make
[ 0%] Running external makefile <=== Builds bar fine first time
[100%] Built target external_target
> touch foo
> make
[100%] Built target external_target <=== ERROR: DOES NOT BUILD BAR!!
> rm bar
> make
[ 0%] Running external makefile <=== Builds bar only after delete
[100%] Built target external_target
  

This behavior matches Brad's new (and useful) documentation, but does not solve the original problem.
(0022908)
Brad King   
2010-11-05 13:59   
I included a statement in the documentation that describes how to make it always build. Just don't create the file listed in the custom command OUTPUT as part of the rule. In your example the "touch bar" breaks it.
(0022925)
Steve King   
2010-11-05 16:17   
Yes, thanks Brad. The solution with the faux output works and sorry for all the gyrations on this. IMHO, the documentation covering this topic is still quite thin, but the key ingredients are at least there.