Hi, I have a project that lives in a subdirectory example
of another project, can’t figure out why it keeps on complaining that:
No rule to make target ‘example/linkerscript.ld’, needed by ‘example/example’. Stop.
Here’s the code
cmake_minimum_required(VERSION 3.8)
project("example" LANGUAGES C)
add_executable(example main.c)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/linkerscript.ld
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/generate_linkerscript.sh
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate_linkerscript.sh ${CMAKE_LINKER} ${CMAKE_CURRENT_BINARY_DIR}/linkerscript.ld
COMMENT Generates linkerscript with custom sections
)
add_custom_target(linkerscript DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/linkerscript.ld)
set_target_properties(example PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/linkerscript.ld)
target_link_options(example PRIVATE -T${CMAKE_CURRENT_BINARY_DIR}/linkerscript.ld)
Here’s the tree of the directory:
├── example
│ ├── CMakeLists.txt
│ ├── generate_linkerscript.sh
│ └── main.c
If I manually build the target linkerscript
, then building example
succeeds, however if I clean and just try building example
I’m getting the error from the beginning.
This should have been pretty simple but it’s really frustrating.
Any help would be welcome!