[CMake] call already made makefile
Michael Hertling
mhertling at online.de
Fri Nov 5 05:17:42 EDT 2010
On 11/05/2010 05:23 AM, SK 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!! I missed this since the external
> makefile I need actually does have a dependency to create the makefile
> itself. So, the custom command only ran when the single explicit
> dependency was out of date. I can solve that some other way and I
> appreciate all your effort to straighten this out. I wish the
> document would have explicitly stated that the command always runs
> without a dependency, though that is the intuitive course of action.
AFAIK, a custom command without dependencies doesn't run if its OUTPUT
exists; see the following CMakeLists.txt and the generated Makefiles:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(INDEPENDCUSTOMCOMMAND C)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_BINARY_DIR}/main.h
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/main.h)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "
#include \"main.h\"
int main(void){return 0;}
")
ADD_EXECUTABLE(main main.c main.h)
The sole possibility to (re)run the custom command is to delete main.h;
if main.h exists the command never runs. You might even have a foreign
main.h: Try "cmake <path/to/source>" followed by "touch main.h" from
within an empty build directory, and you won't see the custom command
run. In ${CMAKE_BINARY_DIR}/CMakeFiles/main.dir/build.make, the related
lines are:
main.h:
...
.../cmake -E touch .../main.h
So, the commands associated with make's "main.h" target aren't executed
if make detects that main.h is already present. Thus, a dependency-less
custom command doesn't run each time; rather, it runs only if its output
doesn't exist.
Regards,
Michael
More information about the CMake
mailing list