Created
January 5, 2023 13:34
-
-
Save yashi/f147cc961810e9ec0bf9be289a4a276c to your computer and use it in GitHub Desktop.
Interface library with a generated header file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.25) | |
project(test) | |
add_executable(hello hello.c) | |
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/foo.h | |
# Ninja always implicitly creates target directories | |
COMMAND mkdir -p include/ | |
COMMAND touch include/foo.h) | |
add_custom_target(generate_header | |
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/include/foo.h) | |
add_library(interface_lib INTERFACE) | |
# must use add_dependencies to a custom target | |
# see https://gitlab.kitware.com/cmake/cmake/-/issues/17366 | |
add_dependencies(interface_lib generate_header) | |
target_include_directories(interface_lib INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include/) | |
target_link_libraries(hello interface_lib) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment