mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-14 14:26:55 +00:00
b32f723844
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.
26 lines
883 B
CMake
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)
|