On 2010-11-05 14:12-0400 David Cole wrote:

On Fri, Nov 5, 2010 at 2:00 PM, SK <s...@metrokings.com> wrote:
On Thu, Nov 4, 2010 at 9:23 PM, SK <s...@metrokings.com> wrote:
On Thu, Nov 4, 2010 at 6:09 PM, Alan W. Irwin <ir...@beluga.phys.uvic.ca> wrote:
then the custom make command
should always be run (since it has no DEPENDS option),

Alan, you are absolutely right!!

No, sorry.  Only if the add_custom_command output does not exist as
other have mentioned too.  My build is so ridiculously complex I'm
fooling myself right and left.  Here's a small test case to show this.
 Hopefully other suggestions on this thread will work.

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 <=== DOES NOT BUILD BAR!!
rm bar
make
[ 0%] Running external makefile <=== Builds bar only after delete
[100%] Built target external_target
_______________________________________________
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




Change it to this:

ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/NO_SUCH_FILE_AS_bar
...
ADD_CUSTOM_TARGET( external_target ALL
       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/NO_SUCH_FILE_AS_bar

Now, because NO_SUCH_FILE_AS_bar NEVER exists, ever... the command
will always run, because the custom target is always out of date.
Then, when your makefile actually runs, *it* will decide (hopefully
correctly) whether or not it needs to build 'bar'.

Non-obvious, I know. I struggled with this over and over while
developing ExternalProject... But it does work.

I agree the above idea should work, but dropping add_custom_command
completely and moving the COMMAND to add_custom_target instead (and
dropping all file DEPENDS for the custom target) is even a simpler way
to insure COMMAND gets executed every time the custom target is
built.  This situation is summarized in the documentation.

add_custom_target
   Add a target with no output so it will always be built.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
_______________________________________________
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