[cmake-developers] [CMake 0015681]: add_custom_command(TARGET ...) can't see in scope target
Mantis Bug Tracker
mantis at public.kitware.com
Tue Aug 4 17:18:21 EDT 2015
The following issue has been SUBMITTED.
======================================================================
http://www.cmake.org/Bug/view.php?id=15681
======================================================================
Reported By: Dan Liew
Assigned To:
======================================================================
Project: CMake
Issue ID: 15681
Category: CMake
Reproducibility: always
Severity: major
Priority: normal
Status: new
======================================================================
Date Submitted: 2015-08-04 17:18 EDT
Last Modified: 2015-08-04 17:18 EDT
======================================================================
Summary: add_custom_command(TARGET ...) can't see in scope
target
Description:
'm observing a problem with CMake's add_custom_command() when using
the TARGET version of the signature.
Code demonstrating the issue can be found at [1]
In ``test/CMakeLists.txt`` [2] I try using add_custom_command() to
build and run an executable every time the ``foolib`` library is
rebuilt. The motivation behind doing this is to have some very quick
and simple library tests run every time the library is built.
This use of add_custom_command() does not seem to work at all.
Using CMake 2.8.12.2 the requested command is not invoked when running
``make foolib``. I am aware that the custom command won't run if
``foolib`` has already been made but even if I do a clean build the
custom command specified does not run.
When using CMake 3.2.3 I get a warning about CMP0040 which complains
that the target passed to the TARGET argument in
``add_custom_command()`` doesn't exist.
```
Policy CMP0040 is not set: The target in the TARGET signature of
add_custom_command() must exist. Run "cmake --help-policy CMP0040" for
policy details. Use the cmake_policy command to set the policy and
suppress this warning.
The target name "foolib" is unknown in this context.
This warning is for project developers. Use -Wno-dev to suppress it
```
This doesn't make sense the target **clearly exists and is in scope**
because the ``simple_test`` executable links against it and also it is
possible to read properties of the target.
Seems like there's some sort of weird scope issue going on here.
[1] https://github.com/delcypher/cmake_add_custom_command_bug
[2]
https://github.com/delcypher/cmake_add_custom_command_bug/blob/master/test/CMakeLists.txt
Steps to Reproduce:
$ git clone https://github.com/delcypher/cmake_add_custom_command_bug.git
$ cd cmake_add_custom_command_bug
$ mkdir build
$ cd build
# Under new versions of CMake a warning is emitted about the "foolib" target not
being known in this context
$ cmake ../
$ make foolib VERBOSE=1
you will see that none of the custom commands are executed
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2015-08-04 17:18 Dan Liew New Issue
======================================================================
More information about the cmake-developers
mailing list