Skip to content

CMakeLists: drop EXACT from find_package(Lua X.Y EXACT REQUIRED) - #1755

Open
ShuangLiu1992 wants to merge 1 commit into
ThePhD:developfrom
ShuangLiu1992:fix/lua-no-exact-version
Open

CMakeLists: drop EXACT from find_package(Lua X.Y EXACT REQUIRED)#1755
ShuangLiu1992 wants to merge 1 commit into
ThePhD:developfrom
ShuangLiu1992:fix/lua-no-exact-version

Conversation

@ShuangLiu1992

Copy link
Copy Markdown

Motivation

Each of the per-version branches (5.1, 5.2, 5.3, 5.4) currently calls
find_package(Lua X.Y EXACT REQUIRED). The EXACT keyword requires the
FOUND version to match the requested version exactly, which is overly
restrictive — and silently broken when Lua is supplied by a CMake-config
package (Conan, vcpkg) rather than CMake's bundled FindLua module.

Real-world failures

  • Config-mode providers: a package's LuaConfigVersion.cmake reports
    PACKAGE_VERSION_COMPATIBLE=TRUE for major-version-compatible queries
    but only sets PACKAGE_VERSION_EXACT=TRUE when the FOUND version
    string equals the requested string exactly. For find_package(Lua 5.4 EXACT)
    this needs PACKAGE_VERSION = "5.4" exactly — providers usually
    report "5.4.7" (or a SHA / build identifier), so the EXACT match
    fails and find_package silently falls through.

  • Module mode: CMake's bundled FindLua reads lua.h and reports a
    3-component version like "5.4.7". EXACT 5.4 still matches via
    component-prefix semantics, so this path mostly works — but the
    asymmetry between Module and Config mode is fragile.

Change

Drop the EXACT keyword from all four per-version branches. The
find_package(Lua X.Y) call still constrains the Lua major.minor
release to what the user asked for via SOL2_LUA_VERSION (default
5.4.4) — sol2 still binds to a specific Lua major. The patch-version
exactness was effectively a CMake quirk, not a correctness requirement:
sol2's bindings work cleanly against any 5.4.x.

Notes

  • The behavior change is bounded: with EXACT removed, find_package(Lua 5.4)
    accepts any 5.4.x, which is exactly the same set of Lua releases sol2
    supports per-major (no patch-version-specific binding code).
  • No test or build script changes needed — lualib,
    LUA_LIBRARIES, LUA_INCLUDE_DIR all behave the same.
  • Caught while integrating sol2 into a Conan-based dependency tree where
    Lua is provided as lua/<sha>; this PR makes that wiring work
    upstream too.

Each of the per-version branches (5.1, 5.2, 5.3, 5.4) calls find_package
with the EXACT keyword. EXACT requires the FOUND version to match the
requested version exactly, which is overly restrictive for two
real-world configurations:

  - CMake's bundled FindLua reads `lua.h` and reports a 3-component
    version (e.g. "5.4.7"). EXACT 5.4 requires the FOUND major.minor
    components to match; that works on most systems, but pinning
    `SOL2_LUA_VERSION=5.4.4` (sol2's default) causes the EXACT check
    to silently accept any 5.4.x — which is the same behavior as
    dropping EXACT — while making 5.4.7 → match harder if a stricter
    version comparison is applied.

  - When Lua is provided by a CMake-config package (e.g. Conan, vcpkg)
    rather than CMake's bundled FindLua, the package's
    `LuaConfigVersion.cmake` controls compat. EXACT requires its
    `PACKAGE_VERSION_EXACT` flag to be set, which providers don't
    usually do for major.minor-style queries. The non-EXACT call
    simply requires `PACKAGE_VERSION_COMPATIBLE`, which is the
    sensible default.

Removing EXACT keeps the major.minor version constraint via the
trailing `X.Y` argument — sol2 still binds to the requested Lua major
release. The patch-version exactness was effectively a CMake quirk,
not a correctness requirement: sol2's bindings work for any 5.4.x.

This unblocks providing Lua via CMake-config packages (any Conan or
vcpkg setup), which previously failed at the EXACT check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant