On Mon, Oct 26, 2015 at 12:32 PM, Martin Braun <martin.br...@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 -- 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