Skip to content

feat(deps-cmake): build_shared_libs passes BUILD_SHARED_LIBS to the subproject - #63

Open
NopeCharon wants to merge 1 commit into
mcpp-community:mainfrom
NopeCharon:feat/deps-cmake-build-shared-libs
Open

NopeCharon wants to merge 1 commit into
mcpp-community:mainfrom
NopeCharon:feat/deps-cmake-build-shared-libs

Conversation

@NopeCharon

Copy link
Copy Markdown

Closes #50.

options::shared only tells mcpp what a CMake subproject installs: which library file names to link, and whether the prefix's shared-library directory reaches mcpp run and mcpp pack. It never reaches CMake. So a subproject that follows CMake's convention and lets BUILD_SHARED_LIBS decide the library kind still builds static archives, and the link then fails on a lib<name>.so that was never built. The only workaround was a hand-written -DBUILD_SHARED_LIBS=ON in cache_args.

This adds options::build_shared_libs, a std::optional<bool>:

mcpp::deps::cmake::options o;
o.source            = "3rdParty/widgets";
o.libraries         = { "widgets" };
o.shared            = true;   // what mcpp links and deploys
o.build_shared_libs = true;   // what CMake builds: -DBUILD_SHARED_LIBS=ON
  • Unset (the default): nothing is passed. Existing build programs configure and key their installations exactly as before.
  • true / false: passes -DBUILD_SHARED_LIBS=ON / OFF to the configure step. The argument is part of the recipe, so a shared build and a static build get different installation cache keys.
  • Also given in cache_args: if cache_args defines BUILD_SHARED_LIBS too (joined, spaced or typed), the member refuses with a message naming both and declares no action. Neither of the two conflicting values wins silently.

shared keeps its meaning. The two options are separate, and they usually agree. docs/deps.md lists the new option in the deps-cmake table.

Tests

  • plugin-logic has four new cases:
    • ON reaches both the configure step and the key's recipe.
    • OFF reaches the configure step.
    • Leaving it unset passes nothing, even with shared = true.
    • The conflict is refused with its reason and no action.
  • The cmake-consumer fixture's greet library no longer hard-codes SHARED. It is built shared because the build program sets build_shared_libs = true. check-deps-and-qt.sh cmake-consumer now checks for BUILD_SHARED_LIBS=ON in the subproject's CMakeCache.txt. That lane now tests the option end to end on every host.

Validation (Linux aarch64, mcpp 2026.11.7.1, its default LLVM toolchain)

  • check-deps-and-qt.sh plugin-logic: 52 of 52 on main. With only the new cases applied, the build program fails to compile (no member named 'build_shared_libs'). With the change: 56 of 56.
  • check-deps-and-qt.sh cmake-consumer: passes. The installation holds lib/libgreet.so, and every existing assertion in the function still passes (no re-run, rebuild after an edit, re-run after an added file). xim:cmake has no aarch64 artifact, so this run pointed [xlings.overrides] at a local CMake 4.4.5; that change was not committed.
  • The same lane with the build_shared_libs = true line removed fails to link (no such file or directory: .../install/lib/libgreet.so). So the fixture really depends on the option.

…ubproject

`options::shared` only tells mcpp what the subproject installs -- which
library file names to link and whether the prefix's shared-library
directory reaches `mcpp run` and `mcpp pack`. It never reached CMake, so a
subproject that follows CMake's convention and leaves the kind of library
to `BUILD_SHARED_LIBS` still built static archives, and the link then
failed on a `lib<name>.so` that was never produced. The only way out was a
hand-written `-DBUILD_SHARED_LIBS=ON` in `cache_args`.

`options::build_shared_libs` (a `std::optional<bool>`) states it:

- unset, the default, passes nothing, so every existing build program
  configures, and keys its installation, exactly as before;
- `true` or `false` passes `-DBUILD_SHARED_LIBS=ON` or `OFF` to the
  configure step. The argument is part of the recipe, so an installation
  built shared and one built static have different cache keys;
- together with a `BUILD_SHARED_LIBS` in `cache_args` (joined, spaced or
  typed) the member refuses, naming both, and declares nothing, rather
  than silently letting one of two contradictory statements win.

`shared` keeps its meaning; the two are separate statements that usually
agree.

Tests:

- plugin-logic gains four cases: ON reaches the configure step and the
  key, OFF reaches the configure step, unset passes nothing even with
  `shared = true`, and the conflict is refused with its reason and no
  action. They do not compile without this change; with it 56 of 56
  cases pass.
- The cmake-consumer fixture's library no longer hard-codes SHARED: it is
  built shared because the build program sets `build_shared_libs = true`,
  and check-deps-and-qt.sh asserts BUILD_SHARED_LIBS=ON in the
  subproject's CMakeCache.txt. Without the option the fixture fails to
  link its missing libgreet.so, so the lane now exercises the option end
  to end.

docs/deps.md lists the option in the deps-cmake table.

Closes mcpp-community#50
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.

o.shared="shared"api无法控制构建target类别

1 participant