Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

1.9 KB
Raw Blame
# embed_guide(<output.cpp> <guide dir>)
# Embeds the user guide (docs/guide: *.md, images/* and images/*/*) in the app, so Help > User Guide works the same on every
# platform and in every package, with no files to find at run time. Generates
#   namespace sf::guide_data { struct File { const char* path; const unsigned char* data; unsigned long long size; };
#                              extern const File kFiles[]; extern const int kFileCount; }
# CMake re-runs when a guide file is added, removed or edited.
function(embed_guide output dir)
  file(GLOB pages CONFIGURE_DEPENDS RELATIVE ${dir} ${dir}/*.md)
  file(GLOB images CONFIGURE_DEPENDS RELATIVE ${dir} ${dir}/images/*.jpg ${dir}/images/*.png
       ${dir}/images/*/*.jpg ${dir}/images/*/*.png) # images/<chapter>/ folders too
  list(SORT pages)
  list(SORT images)
  set(content "// Generated by cmake/EmbedGuide.cmake from docs/guide - do not edit.\nnamespace sf::guide_data {\n")
  string(APPEND content "struct File { const char* path; const unsigned char* data; unsigned long long size; };\n")
  set(table "")
  set(index 0)
  foreach(rel ${pages} ${images})
    set(file ${dir}/${rel})
    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${file})
    file(READ ${file} hex HEX)
    file(SIZE ${file} size)
    string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," bytes "${hex}")
    string(REGEX REPLACE "((0x..,){32})" "\\1\n" bytes "${bytes}")
    string(APPEND content "static const unsigned char f${index}[] = {\n${bytes}0};\n")
    string(APPEND table "  {\"${rel}\", f${index}, ${size}ull},\n")
    math(EXPR index "${index} + 1")
  endforeach()
  string(APPEND content "extern const File kFiles[] = {\n${table}  {nullptr, nullptr, 0}};\n")
  string(APPEND content "extern const int kFileCount = ${index};\n} // namespace sf::guide_data\n")
  file(WRITE ${output}.tmp "${content}")
  file(COPY_FILE ${output}.tmp ${output} ONLY_IF_DIFFERENT)
endfunction()