[cmake-developers] [CMake 0015844]: Custom command executing for file the target doesn't depend on

Mantis Bug Tracker mantis at public.kitware.com
Wed Nov 11 15:04:05 EST 2015


The following issue has been SUBMITTED. 
====================================================================== 
https://public.kitware.com/Bug/view.php?id=15844 
====================================================================== 
Reported By:                Роман Донченко
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15844
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2015-11-11 15:04 EST
Last Modified:              2015-11-11 15:04 EST
====================================================================== 
Summary:                    Custom command executing for file the target doesn't
depend on
Description: 
If two targets have the same sources, it's possible for one of them to execute a
custom command for a file that it doesn't depend on.

Steps to Reproduce: 
Create foo1.txt and foo2.txt with any contents and the following CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)

set(S "${CMAKE_CURRENT_SOURCE_DIR}")
set(B "${CMAKE_CURRENT_BINARY_DIR}")

add_custom_command(OUTPUT bar1.txt
                   COMMAND "${CMAKE_COMMAND}" -E md5sum
                       "${S}/foo1.txt" "${S}/foo2.txt" > "${B}/bar1.txt"
                   MAIN_DEPENDENCY "${S}/foo1.txt"
                   DEPENDS "${S}/foo2.txt"
                   VERBATIM)

add_custom_target(bar1 DEPENDS "${B}/bar1.txt"
                  SOURCES "${S}/foo1.txt" "${S}/foo2.txt")

add_custom_command(OUTPUT bar2.txt
                   COMMAND "${CMAKE_COMMAND}" -E md5sum
                       "${S}/foo2.txt" "${S}/foo1.txt" > "${B}/bar2.txt"
                   MAIN_DEPENDENCY "${S}/foo2.txt"
                   DEPENDS "${S}/foo1.txt"
                   VERBATIM)

add_custom_target(bar2 DEPENDS "${B}/bar2.txt"
                  SOURCES "${S}/foo1.txt" "${S}/foo2.txt")

Now:

$ /opt/cmake-3.3.2/bin/cmake /source/dir
[...]
-- Build files have been written to: /build/dir
$ make bar1
Scanning dependencies of target bar1
[ 50%] Generating bar1.txt
[100%] Generating bar2.txt
[100%] Built target bar1

Even though bar1 doesn't depend on bar2.txt, it gets generated anyway.
Similarly, if you make bar2, it will generate bar1.txt.

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-11-11 15:04 Роман Донченко New Issue                          
         
======================================================================



More information about the cmake-developers mailing list