object-introspection/resources/CMakeLists.txt
Jake Hillion b32f723844 resources: manage headers properly
Previously we had an `R"(` string in `OITraceCode.cpp` which allowed us
to include the file as a string. Instead, keep `OITraceCode.cpp` a fully
formed C++ file and utilise the build system to turn it into a string.
This will be used for more header files that are needed both as valid
headers and as strings for JIT compilation in the Typed TreeBuilder
work.
2023-05-18 16:04:13 +02:00

26 lines
883 B
CMake

add_library(resources headers.cpp)
target_include_directories(resources PRIVATE ../)
function(embed_headers output)
file(WRITE ${output} "#include \"oi/Headers.h\"\n\n")
file(APPEND ${output} "namespace ObjectIntrospection {\n")
file(APPEND ${output} "namespace headers {\n\n")
set(HEADERS
../oi/OITraceCode.cpp
)
foreach(header ${HEADERS})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${header})
get_filename_component(filename ${header} NAME)
string(MAKE_C_IDENTIFIER ${filename} varname)
file(READ ${header} contents)
file(APPEND ${output} "const std::string_view ${varname} = R\"CONTENTS(${contents})CONTENTS\";\n\n")
endforeach()
file(APPEND ${output} "} // namespace headers\n")
file(APPEND ${output} "} // namespace ObjectIntrospection\n")
endfunction()
embed_headers(${CMAKE_BINARY_DIR}/resources/headers.cpp)