[CMake] Error message of `cmake --verbose -E copy` is misleading

Denis G. dgolubev.public at gmail.com
Sun Aug 21 11:14:05 EDT 2016


Hello,

While working with `cmake -E copy` (in a custom command for copying Qt's
qml files to the output directory) and diagnosing a problem in my
CMakeLists.txt with it, I discovered some misleading error messages. The
following examples are used outside of any CMake project for simplification.

$ cmake -E copy_if_different non_existant_source.txt target.txt
Error copying file (if different) from "non_existant_source.txt" to
"target.txt".

In the original error message without any additional flags, there was not
enough information for me to determine which location was missing (without
looking into the directories manually). The easiest was to use some kind of
verbose output:

$ cmake --verbose -E copy non_existant_source.txt target.txt
CMake Error: The source directory "/tmp/target.txt" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

The error message references the target location instead of the source
location. It is the same for `copy` and `copy_directory`. Furthermore
"source directory" is only correct for `copy_directory`. The usage output
for `copy` when using `cmake -E` indicates that the first parameter is the
source.

If the source file exists, copying fails, when the `--verbose` flag is
given:

$ touch source.txt
$ cmake --verbose -E copy_if_different source.txt target.txt
CMake Error: The source directory "/tmp/target.txt" is a file, not a
directory.
Specify --help for usage, or press the help button on the CMake GUI.

I could not find anything about `--verbose` in the man page of CMake, is
this an official flag? If not, are there any flags I can use for diagnosing
such problems in the future? Does it interfere with the `cmake -E`
invocation or should I file an issue?

I am using CMake 3.6.1 on Arch Linux (package version is "3.6.1-1").

A project as a SSCCE:

$ tree
.
├── CMakeLists.txt
└── main.cc
$ cat main.cc    # empty source file
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(cmake-copy-issue)

set(OUT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/out.txt)

# In the custom command I intentionally used the wrong source file and not
the file which is given in DEPENDS.
# This is the issue I was previously having and how I discovered this error
messages. I already added `--verbose` here.
add_custom_command(
    OUTPUT ${OUT_LOCATION}
    COMMAND ${CMAKE_COMMAND} --verbose -E copy non_existant_file.txt
${OUT_LOCATION}
    DEPENDS main.cc
    COMMENT "Copying..."
    VERBATIM
)

add_executable(test_target main.cc ${OUT_LOCATION})
$ cd ..
$ mkdir cmake-copy-issue-build
$ cd cmake-copy-issue-build
$ cmake ../cmake-copy-issue
[...]
$ make
[ 33%] Copying...
CMake Error: The source directory
"/path/to/project/parent/directory/cmake-copy-issue-build/out.txt" does not
exist.
Specify --help for usage, or press the help button on the CMake GUI.
make[2]: *** [CMakeFiles/test_target.dir/build.make:62: out.txt] Error 1
make[1]: *** [CMakeFiles/Makefile2:67: CMakeFiles/test_target.dir/all]
Error 2
make: *** [Makefile:84: all] Error 2

Regards,
Denis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160821/060bea35/attachment-0001.html>


More information about the CMake mailing list