This document describes the CMake build, install, and package-consumption flow for Gecode.
- CMake 3.21 or newer
- A C++17-capable compiler
uvonPATHfor generated-script paths: documentation generation,GECODE_REGENERATE_VARIMP=ON, and manual helper execution. Ordinary CMake builds can use the checked-in generated headers withoutuv.- Python 3.11 or newer for helper scripts run through
uv. - Optional dependencies based on enabled modules:
- MPFR for float support with MPFR
- Qt 6 Core, or Qt 5.15+ Core, for FlatZinc plugin support when Qt support is enabled or auto-detected
- Qt 6 Gui, Widgets, and PrintSupport, or the matching Qt 5.15+ components, for Gist
Single-config generators (Unix Makefiles / Ninja):
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
cmake --build build --target check
cmake --install build --prefix /path/to/installMulti-config generators (Visual Studio / Xcode):
cmake -S . -B build
cmake --build build --config Release
cmake --build build --config Release --target check
cmake --install build --config Release --prefix /path/to/installThis repository includes a vcpkg manifest (vcpkg.json) and CMake presets
for a ready-to-run Visual Studio path with MPFR enabled.
Prerequisites:
- Visual Studio 2022 with C++ toolchain
- CMake 3.21 or newer
VCPKG_ROOTset to your vcpkg checkout
Preset flow:
cmake --preset vs2022-vcpkg
cmake --build --preset vs2022-vcpkg-release
cmake --build --preset vs2022-vcpkg-checkEquivalent command-line flow (without presets):
cmake -S . -B build/vs2022-vcpkg -G "Visual Studio 17 2022" -A x64 `
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" `
-DVCPKG_TARGET_TRIPLET=x64-windows `
-DGECODE_ENABLE_MPFR=ON -DGECODE_ENABLE_QT=OFF -DGECODE_ENABLE_GIST=OFF
cmake --build build/vs2022-vcpkg --config Release
cmake --build build/vs2022-vcpkg --config Release --target check
cmake --install build/vs2022-vcpkg --config Release --prefix C:/path/to/installVisual Studio is a multi-config generator, so use --config Release (or
Debug) for build/install/check commands rather than CMAKE_BUILD_TYPE.
BUILD_SHARED_LIBS: conventional default selectorONdefault behavior:GECODE_BUILD_SHARED=ON,GECODE_BUILD_STATIC=OFFOFFdefault behavior:GECODE_BUILD_SHARED=OFF,GECODE_BUILD_STATIC=ON
BUILD_TESTING: controls whethergecode-testis built and whethercheckruns the test subset. Thechecktarget still exists when tests are disabled, but reports that checks are skipped.CMAKE_BUILD_TYPE/ multi-config--config: standard build mode control
GECODE_BUILD_SHARED,GECODE_BUILD_STATIC: explicit library variants- If set directly, these override
BUILD_SHARED_LIBS-based defaults.
- If set directly, these override
GECODE_INSTALL: enables install/export/package rules- Defaults to
ONwhen Gecode is top-level; defaults toOFFas subproject.
- Defaults to
GECODE_ENABLE_*: module toggles (search/int/set/float/minimodel/driver/flatzinc/gist, etc.)- Higher-level modules force their required lower-level modules on. For example, examples and FlatZinc require the core modeling modules, and minimodel requires int, set, and search support.
GECODE_REGENERATE_VARIMP: regenerate checked-in var-imp headers during build
GECODE_ENABLE_QT:AUTO,ON, orOFF.AUTOuses Qt-backed FlatZinc plugin support when Qt Core is found.ONrequires Qt and fails configuration if supported Qt is missing.OFFdisables Qt. Qt 6 is preferred; Qt 5.15 or newer is accepted for legacy environments. This can add a public Qt Core dependency toGecode::gecodeflatzinc.GECODE_ENABLE_GIST:AUTO,ON, orOFF.AUTObuilds Gist when a usable Qt GUI stack is available.ONrequires Gist dependencies and fails configuration if they are unavailable. Gist requires Qt Gui, Widgets, and PrintSupport in addition to Qt Core.GECODE_ENABLE_FAULT_INJECTION: builds deterministic allocation and copy failpoints together with theFault::*regression suite. This facility is test-only, process-global, isolated to the dedicated single-threaded fault test executable, CMake-only, and disabled by default.GECODE_SANITIZER: selectsaddress,undefined,address-undefined, orthreadinstrumentation. These modes currently require a compiler that accepts GCC/Clang sanitizer flags.GECODE_DOC_DOT,GECODE_DOC_SEARCH,GECODE_DOC_TAGFILE: configure the Doxygendoctarget. Building docs requires Doxygen 1.17.0 or newer anduv; Graphvizdotis used when available andGECODE_DOC_DOT=ON.
Top-level defaults:
GECODE_ENABLE_EXAMPLES=ONBUILD_TESTING=ONGECODE_INSTALL=ON
Subproject defaults (add_subdirectory):
GECODE_ENABLE_EXAMPLES=OFFBUILD_TESTING=OFF(unless enabled by parent project)GECODE_INSTALL=OFF
Fault injection is test-only and process-global. Its tests run in a dedicated, isolated single-threaded executable and must not share a test process with ordinary tests. The CMake targets enforce this:
cmake -S . -B build-fault -DGECODE_ENABLE_FAULT_INJECTION=ON
cmake --build build-fault --target check-faultThe ordinary check target also runs check-fault when fault injection is
enabled. CTest registers the fault suite as a separate process with
-threads 1 and serializes it with the fault-injection resource lock. The
FailPoint facility is not a supported application API.
For a sanitizer build, configure a separate build directory. For example:
cmake -S . -B build-asan-ubsan \
-DGECODE_SANITIZER=address-undefined
cmake --build build-asan-ubsan --target checkGecode::gecode links the exported aggregate target. Use it unless the
consumer needs explicit module linkage.
find_package(Gecode CONFIG REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE Gecode::gecode)Canonical component names:
support,kernel,search,int,set,float,minimodel,driver,flatzinc,gist
Example:
find_package(Gecode CONFIG REQUIRED COMPONENTS driver)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE Gecode::gecodedriver)Legacy component spellings are also accepted in COMPONENTS:
gecodesupport,gecodekernel,gecodesearch,gecodeint,gecodeset,gecodefloat,gecodeminimodel,gecodedriver,gecodeflatzinc,gecodegist
Use one of:
-DCMAKE_PREFIX_PATH=/path/to/install-DGecode_ROOT=/path/to/install
Packagers that want to avoid any Qt dependency in the exported package should configure with:
cmake -S . -B build -DGECODE_ENABLE_QT=OFF -DGECODE_ENABLE_GIST=OFFUse Gecode_VERSION from package config:
find_package(Gecode CONFIG REQUIRED)
message(STATUS "Gecode version: ${Gecode_VERSION}")Do not rely on parsing installed headers such as config.hpp for version checks.
| Deprecated | Replacement |
|---|---|
ENABLE_THREADS |
GECODE_ENABLE_THREAD |
ENABLE_GIST |
GECODE_ENABLE_GIST |
BUILD_EXAMPLES |
GECODE_ENABLE_EXAMPLES |
ENABLE_CPPROFILER |
GECODE_ENABLE_CPPROFILER |
Deprecation horizon:
- These aliases are accepted for the 6.x line to preserve migration compatibility.
- New configurations should use the
GECODE_*names.
Target "..." links to Gecode::gecode but the target was not found:- Ensure you are using an installation built with this CMake export layout.
- Check
CMAKE_PREFIX_PATH/Gecode_ROOTpoints to the intended install.
find_package(Gecode COMPONENTS ...)fails:- Verify requested component is enabled in the installed build.
- For optional modules (
flatzinc,gist,floatwith MPFR), ensure dependencies were available.
- Qt/Gist issues:
GECODE_ENABLE_QT=ONandGECODE_ENABLE_GIST=ONare requirement modes; useAUTOwhen dependency discovery should be best-effort.GECODE_ENABLE_GIST=ONrequires Qt discovery and a usable Qt link interface.- Gecode requires Qt 5.15 or newer. Qt 6 is preferred for new builds.
- On macOS, Gist defaults to
OFF; enable it explicitly once the local Qt/OpenGL framework setup is known to link. Current macOS SDKs require a current Qt 6 build; older Qt packages can still reference removed system frameworks.
- MPFR issues:
- Use
CMAKE_PREFIX_PATH,MPFR_ROOT, or toolchain include/link paths sofind_package(MPFR)succeeds. - Installed packages built with MPFR first try config-mode MPFR discovery,
then the installed
FindMPFR.cmake. vcpkg consumers can rely on the active vcpkg toolchain orVCPKG_ROOT/VCPKG_TARGET_TRIPLETto provide the MPFR and GMP roots.
- Use