Skip to content

Enable vcpkg manifest features based on CMake options - #42

Open
TrueBrain wants to merge 1 commit into
carbonengine:mainfrom
TrueBrain:use-vcpkg-manifest-features
Open

Enable vcpkg manifest features based on CMake options#42
TrueBrain wants to merge 1 commit into
carbonengine:mainfrom
TrueBrain:use-vcpkg-manifest-features

Conversation

@TrueBrain

@TrueBrain TrueBrain commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Currently, vcpkg installs all dependencies. Including Python3, even if you don't build the documentation. This is mostly a problem for targets (like Emscripten), that don't allow for building Python3. But this repository doesn't actually need with its default options.

Instead, use vcpkg manifest features like some other repositories already do (like mesh and resources):

  • Set the option()s before project()
  • Fill in VCPKG_MANIFEST_FEATURES

I assumed if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) was a left-over guard from the migration to GitHub, and actually has no function anymore. Do let me know if that wasn't the case.

AI assistance disclosure

Claude did a lot of triage what if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) was actually about. Otherwise: none

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup (no behaviour change)
  • Documentation
  • Build, CI, or tooling
  • Breaking change (public API or ABI)
  • Other (describe below)

Linked issue (optional)

What changed

  • Order of option()
  • vcpkg's manifest, to use features

Testing

$ cmake --preset x64-linux-debug
-- Running vcpkg install
(..)
The following packages will be built and installed:
    gtest:x64-linux-debug@1.17.0#1 -- git+https://github.com/microsoft/vcpkg.git@9ef57e3c1c7484e79ef8dd77e9cb7770f5331248
    lz4:x64-linux-debug@1.10.0 -- git+https://github.com/microsoft/vcpkg.git@4f01eec10f515a428e914107c5188366380f8dd9
  * pthreads:x64-linux-debug@3.0.0#14 -- git+https://github.com/microsoft/vcpkg.git@2e0a6df2800d3677b941dc6504f083965b7886d9
    tracy[core,delayed-init,fibers,manual-lifetime,no-callstack,no-crash-handler,on-demand]:x64-linux-debug@0.13.1#1 -- git+https://github.com/carbonengine/vcpkg-registry.git@f358e08b7d561fd61758b4be66af4dda78cef1eb
  * vcpkg-cmake:x64-linux-debug@2024-04-23 -- git+https://github.com/microsoft/vcpkg.git@e74aa1e8f93278a8e71372f1fa08c3df420eb840
  * vcpkg-cmake-config:x64-linux-debug@2024-05-23 -- git+https://github.com/microsoft/vcpkg.git@97a63e4bc1a17422ffe4eff71da53b4b561a7841

(no more Python3 in default setup)

Platforms tested

  • Windows
  • macOS
  • Linux

Screenshots / captures

Checklist

  • I've read CONTRIBUTING.md.
  • My commits follow the commit-message style described there.
  • I've added or updated tests where it made sense.
  • I've updated docs / inline API comments for any behaviour change.
  • My CLA / ICLA is signed (the bot will let you know if it isn't).

Full disclosure: I am employed by Fenris Creations, although I have no involvement with the Carbon project. I work on this in my free time under my own name.

@CCP-Aporia

Copy link
Copy Markdown
Member

Updating the vcpkg manifest file is absolutely something that should be done. Thanks for looking into this! However, no changes to the CMakeLists.txt ought to be required for this.

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) is a common CMake pattern to check if the project in the given CMakeLists.txt is the top-level project. This is useful to allow third-parties to simply add_subdirectory a project like this one, and skip building tests and documentation and such in cases where this isn't the top-level project.

Comment thread vcpkg.json
"description": "Enable memory tracking",
"dependencies": [
{
"name": "lz4",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency is generally required when building the telemetry tests, and not specific to memory tracking.

@TrueBrain

Copy link
Copy Markdown
Contributor Author

So the move of option to above project is required, as otherwise manifest doesn't work. But I can leave the rest in place. Will slim down the PR :)

@CCP-Aporia

Copy link
Copy Markdown
Member

So the move of option to above project is required, as otherwise manifest doesn't work. But I can leave the rest in place. Will slim down the PR :)

That is surprising behaviour, can you elaborate? The "features" in the manifest are purely for dependency acquisition, not for controlling the build options passed to CMake.

@TrueBrain

TrueBrain commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

So CMake and vcpkg can be friends: if you configure CMake to skip documentation, it will tell vcpkg that it doesn't need that feature, and not install those dependencies.

In order for this to work, there is one rule: do the options before your project statement, and set the manifest-features. After that, it "just works".

Which also works if core is a dependency in another project: vcpkg won't install deps for options that are disabled.

Carbonengine already uses this in for example mesh repo, as example.

Reference: https://learn.microsoft.com/en-us/vcpkg/users/buildsystems/cmake-integration#vcpkg_manifest_features

@CCP-Aporia

Copy link
Copy Markdown
Member

Ah, I wasn't aware of that feature - thanks for sharing! It may indeed be useful for building a component as a top-level project, but it's not a requirement for vcpkg per se. 😃

With that in mind, I'd still like to exclude the CMakeLists.txt changes from this PR. The reason is that our CMake "pipeline" is based on an internal template repo. The more a component deviates, the harder it is to integrate the template changes. Because it looks like a genuinely useful change for all components, I'd prefer the path of making the CMakeLists.txt changes in our internal template, and then roll it out that way. 🙂

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.

2 participants