Hi!

I just noticed that add_custom_command() "taints" the main dependency file,
a behavior that in counter-intuitive and does not correspond to the
description in the CMake manual.

The following files demonstrates the problem:

---- CMakeLists.txt
cmake_minimum_required(VERSION 3.1)

add_custom_command(
  MAIN_DEPENDENCY input.c
  COMMENT "Generating ${CMAKE_CURRENT_BINARY_DIR}/output.c"
  COMMAND
  ${CMAKE_COMMAND} -E copy
  ${CMAKE_CURRENT_SOURCE_DIR}/input.c
  ${CMAKE_CURRENT_BINARY_DIR}/output.c
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/output.c
  VERBATIM)

add_executable(foo ${CMAKE_CURRENT_BINARY_DIR}/output.c)

add_executable(bar input.c)
---- input.c:
int main() { return 0; }
----

In this case, I expect "bar" to simply include a plain "input.c" Instead,
it gets an "input.c" with a custom rule. This doesn't work since 1: "bar"
generates "output.c" (which is shouldn't) and 2: "input.c" isn't compiled
and included in the project.

I've tested this using CMake 3.1 using Visual Studio 2008 and using CMake
3.2.1 on UNIX using Makefile:s.


My specific use case is that I create two targets and after each target is
created I create a custom command and add the output files to the target.
(The path of the output file contains the ARCHIVE_OUTPUT_DIRECTORY target
property.)

In my case, what happens is that second target includes rules for building
the output file of the first target, as well as rules for building it's own.

    Sincerely,
         Anders Lindgren
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to