|
| 1 | +--- |
| 2 | +name: gecode-cmake-consumption |
| 3 | +description: "Consume Gecode from CMake using exported package config (`find_package(Gecode CONFIG)`), aggregate/component targets, version checks, and source-fetch fallback patterns. Use when integrating Gecode into downstream CMake projects or migrating custom `FindGecode.cmake` logic. Assume Gecode 6.3.0 or newer." |
| 4 | +--- |
| 5 | + |
| 6 | +# Gecode CMake Consumption |
| 7 | + |
| 8 | +## Core |
| 9 | +- Prefer config-package consumption: `find_package(Gecode CONFIG REQUIRED)`. |
| 10 | +- Link downstream targets to `Gecode::gecode` unless explicit component granularity is required. |
| 11 | +- Require `Gecode_VERSION >= 6.3.0`; use package version checks rather than parsing `gecode/support/config.hpp`. |
| 12 | +- Hint package location with `Gecode_ROOT` or `CMAKE_PREFIX_PATH`. |
| 13 | +- Keep `cmake_minimum_required(VERSION 3.21)` or newer for parity with Gecode's build. |
| 14 | + |
| 15 | +## Canonical Patterns |
| 16 | +- Minimal integration: |
| 17 | + ```cmake |
| 18 | + find_package(Gecode CONFIG REQUIRED) |
| 19 | + target_link_libraries(app PRIVATE Gecode::gecode) |
| 20 | + ``` |
| 21 | +- Component-specific integration: |
| 22 | + ```cmake |
| 23 | + find_package(Gecode CONFIG REQUIRED COMPONENTS driver) |
| 24 | + target_link_libraries(app PRIVATE Gecode::gecodedriver) |
| 25 | + ``` |
| 26 | +- Version guard: |
| 27 | + ```cmake |
| 28 | + if(SOME_STRICT_OPTION AND Gecode_VERSION VERSION_LESS "6.3.0") |
| 29 | + message(FATAL_ERROR "Gecode >= 6.3.0 required, found ${Gecode_VERSION}") |
| 30 | + endif() |
| 31 | + ``` |
| 32 | + |
| 33 | +## Dependency Resolution Workflow |
| 34 | +- Try installed package first via `find_package(Gecode CONFIG QUIET)` when optional discovery is desired. |
| 35 | +- If not found and project policy allows vendoring, use `FetchContent` to obtain Gecode source and call `FetchContent_MakeAvailable(...)`. |
| 36 | +- Set Gecode cache options before `FetchContent_MakeAvailable(...)` to limit dependency surface (for example disable `GECODE_ENABLE_GIST`, examples, tests, or optional modules). |
| 37 | +- Require `TARGET Gecode::gecode` after resolution; fail fast with actionable error text if absent. |
| 38 | +- Mark Gecode target as `SYSTEM` in strict-warning projects to isolate third-party headers from local warning policy. |
| 39 | +- For source-pinned fallback builds, prefer stable release tags or commits over long-lived feature branches. |
| 40 | +- For migration away from custom discovery modules, remove manual imported-target composition and library probing once package config is the baseline path. |
| 41 | +- Keep strict-version toggles if desired, but enforce them against `Gecode_VERSION`. |
| 42 | + |
| 43 | +## Pitfalls |
| 44 | +- Calling `find_package(Gecode REQUIRED)` without `CONFIG` and accidentally resolving old/module-mode shims. |
| 45 | +- Assuming optional components exist without checking enabled modules in the installed build. |
| 46 | +- Mixing custom imported-target composition with package-provided targets in the same code path. |
| 47 | +- Parsing headers for version when package metadata already provides `Gecode_VERSION`. |
0 commit comments