[CMake] call already made makefile
David Cole
david.cole at kitware.com
Fri Nov 5 14:12:27 EDT 2010
On Fri, Nov 5, 2010 at 2:00 PM, SK <sk at metrokings.com> 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
> )
>
>
> 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.
Good luck,
David
More information about the CMake
mailing list