Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 4,103
    • Issues 4,103
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 19
    • Merge requests 19
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMakeCMake
  • CMakeCMake
  • Issues
  • #18399
Closed
Open
Issue created Sep 21, 2018 by Aaron Simmons@paleozogt

target_sources() doesn't recognise GENERATED property for sources added from different scope to target

target_sources doesn't work with GENERATED source files. Here is a simple example:

Top-level CMakeLists.txt:

cmake_minimum_required(VERSION 3.12)
project(foo)
add_library(foo foo.cpp) # foo.cpp is a normal pre-existing file
add_subdirectory(bar)

bar/CMakeLists.txt:

set(bar "int bar() { return 0; }")
add_custom_command(COMMAND ${CMAKE_COMMAND} -E echo "${bar}" > bar.cpp
                   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/bar.cpp
                   VERBATIM
                   )
add_custom_target(gen_bar DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/bar.cpp)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/bar.cpp PROPERTIES GENERATED 1)

add_dependencies(foo gen_bar)
target_sources(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/bar.cpp)

CMake error:

CMake Error at CMakeLists.txt:3 (add_library):
  Cannot find source file:

    /Users/paleozogt/Development/test/cmake-test/.build/bar/bar.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx
Edited Sep 22, 2018 by Craig Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking