Files
CMake/Tests/RunCMake/Codegen/min-graph-1.cmake
Juan Ramos 197cb419d1 add_custom_command: Add CODEGEN support
By specifying CODEGEN as an argument to add_custom_command the
custom command will be added to a codegen build target.

The intent is to provide a convenient way for users to get
their generated files without having to build the whole project.

This can be helpful for code analysis tools which can be useful
for IDEs and CI.
2024-07-01 12:02:49 -04:00

27 lines
641 B
CMake

add_executable(foobar main.c)
add_custom_command(
TARGET foobar POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
${CMAKE_CURRENT_BINARY_DIR}/foobar.txt
)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/generated.h
COMMAND
${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
${CMAKE_CURRENT_BINARY_DIR}/generated.h
COMMAND
# Generate a header file that requires foobar
foobar
CODEGEN
)
add_library(errorlib
# If this library is built error.c will cause the build to fail
error.c
${CMAKE_CURRENT_BINARY_DIR}/generated.h
)