Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ cmake_minimum_required(VERSION 3.15)
project(grunk VERSION 0.5.0)
set(CMAKE_CXX_STANDARD 17)

# grunk must be consumed as a pre-built dependency via find_package(grunk) - never vendored into
# another project's build via add_subdirectory()/FetchContent_MakeAvailable(). See README.md's
# "Consuming grunk" section for why (a real, previously-confirmed ODR/dispatch bug from having two
# independently-compiled copies of grunk in one process). Fail fast here with an explanation instead
# of the confusing "grunk/version.hpp: No such file or directory" this used to produce deep inside
# recipe.hpp, caused by version.hpp only ever being generated into this project's own binary dir.
if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR
"grunk cannot be configured as a CMake subproject (add_subdirectory()/FetchContent). Build "
"and install grunk on its own, then consume it from your project via find_package(grunk). "
"See this repository's README.md, \"Consuming grunk\", for why vendoring/static linking are "
"unsupported by design."
)
endif()

include(GNUInstallDirs)

# grunk_recipe/grunk_plugin (and the umbrella `grunk` target) are built as SHARED
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ int main() {

A plugin can just as well be a compiled Lua module (e.g. SWIG-generated) via `grunk::state::load_compiled_plugin`, or plain Lua source via `grunk::state::load_lua_plugin_script`/`load_lua_plugin_file` (or `grunk::plugin::load_script`) - see `grunk/plugin/loader.hpp` for the full native ABI and `grunk/dynamic/state.hpp` for all three `load_*_plugin`/`begin_plugin` methods.

## Consuming grunk

Build and install grunk, then consume it from a downstream project via `find_package(grunk)` -
**do not** vendor grunk's source into another project via `FetchContent`/`add_subdirectory`, and do not
link it statically. `grunk`/`grunk::recipe`/`grunk::plugin` are deliberately built as `SHARED` libraries
with no option to change that, so that every consumer loaded into one process - native plugins
(`grunk-occt`, `grunk-adolc`, ...), the Python bindings, a GUI - dynamically links the *same* physical
`.so`/`.dylib`/`.dll`. Two independently-compiled copies of grunk loaded into one process is a real,
previously-confirmed hazard: `std::type_index`-keyed dispatch (`grunk::dynamic`'s type/function registry)
silently fails to match across copies, since each gets its own `type_info` identity, producing
wrong-dispatch bugs that are hard to diagnose. Attempting to configure grunk as a CMake subproject fails
fast with an error pointing back here, rather than the confusing missing-header error it used to produce.

## Documentation

[Read the documentation](https://grunk-dev.github.io/grunk/) to learn more.
Expand Down
Loading