[CMake] call already made makefile

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Nov 5 15:59:23 EDT 2010


On 2010-11-05 11:00-0700 SK wrote:

> On Thu, Nov 4, 2010 at 9:23 PM, SK <sk at metrokings.com> wrote:
>> On Thu, Nov 4, 2010 at 6:09 PM, Alan W. Irwin <irwin at 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
>        )

I confirm your conclusion.  So much for my memory of how to do this.
:-)

However, I found this even simpler test case works fine for me:

irwin at raven> cat CMakeLists.txt 
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT( makefile_test NONE)

ADD_CUSTOM_TARGET( external_target ALL
   COMMAND make -f ${CMAKE_CURRENT_SOURCE_DIR}/external_makefile
   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
   )

(I have used WORKING_DIRECTORY because I tested this with a separate
build directory).  Note also, the external make command complains (at
least on my Debian testing system) unless foo exists in
WORKING_DIRECTORY.

The external make command is run every time you run "make VERBOSE=1"
and does the right thing.  If foo exists in the WORKING_DIRECTORY it
touches bar the first time in WORKING_DIRECTORY.  After that first try
it doesn't touch bar unless you touch foo in the
WORKING_DIRECTORY.

I think you have previously rejected this simple scenario because it
didn't work for you.  If the above test works for you (as it should),
then probably your previous test of using add_custom_target without a
corresponding add_custom_command was obfuscated by some other error.

Of course, if you use this simple scenario to build an external
library, then you will need independent knowledge of
full_path_to_external_library and the correct working directory for
the external make command, but you needed that knowledge in any case
for my previous scenario with separate add_custom_command.

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
__________________________


More information about the CMake mailing list