[cmake-developers] [CMake 0015116]: cmake add_custom_command issue with multiple output files

Mantis Bug Tracker mantis at public.kitware.com
Fri Aug 29 13:11:20 EDT 2014


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=15116 
====================================================================== 
Reported By:                Vijay Pradeep
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15116
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2014-08-29 13:11 EDT
Last Modified:              2014-08-29 13:11 EDT
====================================================================== 
Summary:                    cmake add_custom_command issue with multiple output
files
Description: 
I'm noticing some potential incorrect behavior in cmake when working with
add_custom_command and multiple output files. I've been able to isolate the
problem to a minimal example (see below). It seems that when I have two output
files specified in my add_custom_command, the second output file's upstream
dependencies are not being tracked correctly in some cases. The cmake
documentation clearly mentions that multiple output files are allowed. What's
interesting here is that swapping the order of the output files causes different
behavior, suggesting that the first OUTPUT file is being treated differently.

(Crossposted here:
http://stackoverflow.com/questions/24416133/cmake-add-custom-command-issue-with-multiple-output-files)

Steps to Reproduce: 
Example CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

add_library(mybaz baz.cpp)

add_custom_command(
  OUTPUT  baz2.cpp
  COMMAND cp baz.cpp baz2.cpp
  DEPENDS baz.cpp
  COMMENT "Copying baz.cpp to baz2.cpp")

add_custom_target(mytarget
  DEPENDS baz2.cpp
  COMMENT "Running mytarget")

add_dependencies(mybaz mytarget)

add_custom_command(
  OUTPUT  bar.cpp baz.cpp
  COMMAND cat a.txt > bar.cpp
  COMMAND cat a.txt > baz.cpp
  DEPENDS a.txt
  COMMENT "Generating bar.cpp and baz.cpp")

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

Below are the commands that I run:

> touch a.txt
> cmake .
    ...snip... (configuration runs fine)
> make
Scanning dependencies of target mytarget
[ 20%] Generating bar.cpp and baz.cpp
[ 40%] Copying baz.cpp to baz2.cpp
[ 60%] Running mytarget
[ 60%] Built target mytarget
Scanning dependencies of target mybaz
[ 80%] Building CXX object CMakeFiles/mybaz.dir/baz.cpp.o
Linking CXX static library libmybaz.a
[100%] Built target mybaz
  (everything looks good)

> touch a.txt
> make
[ 20%] Generating bar.cpp and baz.cpp
[ 40%] Running mytarget
[ 60%] Built target mytarget
Scanning dependencies of target mybaz
[ 80%] Building CXX object CMakeFiles/mybaz.dir/baz.cpp.o
Linking CXX static library libmybaz.a
[100%] Built target mybaz
  (I seem to be missing the 'Copying baz.cpp to baz2.cpp' line)

> make
[ 20%] Copying baz.cpp to baz2.cpp
[ 40%] Running mytarget
[ 60%] Built target mytarget
[100%] Built target mybaz
  ( The 'Copying baz.cpp to baz2.cpp' executes this time )
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2014-08-29 13:11 Vijay Pradeep  New Issue                                    
======================================================================



More information about the cmake-developers mailing list