[CMake] add_dependencies being ignored for add_custom_command?
Iosif Neitzke
iosif.neitzke+cmake at gmail.com
Mon Oct 26 15:51:33 EDT 2015
On Mon, Oct 26, 2015 at 12:32 PM, Martin Braun <martin.braun at ettus.com> wrote:
> What exactly is a target? I thought if I do add_library(foo ${sources}),
> then 'foo' is a target? You seem to suggest otherwise, which means I'm
> misunderstanding some concepts.
You are correct, "foo" is a target, but in one of your previous
examples you had listed:
add_dependencies(baz ${CMAKE_BINARY_DIR}/path/to/foo.hpp)
Which should generate a warning like:
"CMake Warning (dev) at CMakeLists.txt: (add_dependencies):
Policy CMP0046 is not set: Error on non-existent dependency in
add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "/tmp/path/to/foo.hpp" of target "baz" does not exist.
This warning is for project developers. Use -Wno-dev to suppress it."
Here is the simplest code I can think of that creates files required
by a target:
add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Header.hpp
${CMAKE_CURRENT_BINARY_DIR}/Header.cpp
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/Header.cpp
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/Header.hpp
COMMENT "Running pre-build step for a target" )
add_library( somelib ${CMAKE_CURRENT_BINARY_DIR}/Header.hpp
${CMAKE_CURRENT_BINARY_DIR}/Header.cpp source.cpp )
target_include_directories( somelib PRIVATE ${CMAKE_CURRENT_BINARY_DIR} )
Which outputs:
make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/iosif/tmp/prebuild_header_ex
[ 33%] Running pre-build step for a target
Scanning dependencies of target somelib
[ 66%] Building CXX object CMakeFiles/Headers.dir/Header.cpp.o
[100%] Building CXX object CMakeFiles/Headers.dir/source.cpp.o
Linking CXX static library libsomelib.a
[100%] Built target somelib
More information about the CMake
mailing list