Skip to content

Add FetchContent fallback for cnats#5

Open
joshbradshaw11 wants to merge 4 commits intomainfrom
vcpkg-or-fetchcontent
Open

Add FetchContent fallback for cnats#5
joshbradshaw11 wants to merge 4 commits intomainfrom
vcpkg-or-fetchcontent

Conversation

@joshbradshaw11
Copy link
Collaborator

@joshbradshaw11 joshbradshaw11 commented Feb 25, 2026

Summary

  • Uses find_package(cnats CONFIG QUIET) first — works when cnats is pre-installed (e.g. via vcpkg)
  • Falls back to FetchContent with SHA256-verified tarball download of cnats v3.10.1 when not found
  • Handles the target name difference (cnats::nats_static from vcpkg vs nats_static from FetchContent) via a CNATS_TARGET variable
  • Preserves all install/export targets from the vcpkg-cmake-install-targets branch

Context

Some Formlabs consumers of qtnats use vcpkg (where cnats is a port), while others don't have vcpkg and need cnats fetched automatically. This change makes qtnats work in both environments with a single CMakeLists.txt.

Test plan

  • PreForm build succeeds (vcpkg provides cnats → find_package path)
  • Standalone consumer without vcpkg builds successfully (FetchContent path)

joshbradshaw11 and others added 2 commits February 25, 2026 16:15
Remove FetchContent for cnats and use find_package(cnats CONFIG) instead.
Add proper install() rules and CMake package config so qtnats can be
consumed as a vcpkg overlay port. Update includes for cnats v3.10.1
(<nats/nats.h>) and replace private opts.h constants with hardcoded values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Allow qtnats to build both with vcpkg (where cnats is pre-installed and
found via find_package) and without vcpkg (where cnats is automatically
fetched via FetchContent). The target name difference between the two
paths (cnats::nats_static vs nats_static) is handled via a CNATS_TARGET
variable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@edelmanjm
Copy link
Collaborator

Can we test this with Mordor? I assume it works, but we should check

@edelmanjm
Copy link
Collaborator

Doesn't seem terribly happy:

CMake Error: install(EXPORT "qtnats-targets" ...) includes target "qtnats" which requires target "nats_static" that is not in this export set, but in multiple other export sets: lib/cmake/cnats/cnats-config.cmake, lib/cmake/cnats/cnats-config.cmake.
An exported target cannot depend upon another target which is exported multiple times. Consider consolidating the exports of the "nats_static" target to a single export.

cnats's CMakeLists.txt exports nats_static into multiple export sets,
causing a CMake error when qtnats's install(EXPORT) references it as a
dependency. Fix by using EXCLUDE_FROM_ALL to suppress cnats's install
rules and skipping qtnats install/export when cnats is fetched, since
FetchContent consumers use add_subdirectory and don't need install targets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@edelmanjm
Copy link
Collaborator

Still grumpy:

In file included from /tmp/tmp.NwE9fOfpzK/task_apps/cmake-build-debug-ursula-native/_deps/qtnats-src/src/qtnats/jetstream.cpp:7:
/tmp/tmp.NwE9fOfpzK/task_apps/cmake-build-debug-ursula-native/_deps/qtnats-src/src/qtnats/qtnats.h:21:10: fatal error: nats/nats.h: No such file or directory
   21 | #include <nats/nats.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

@joshbradshaw11
Copy link
Collaborator Author

joshbradshaw11 commented Feb 26, 2026 via email

Downgrade FetchContent fallback from cnats v3.10.1 to v3.3.0 with
updated SHA256 hash. Add a wrapper header shim so that
#include <nats/nats.h> resolves correctly under both vcpkg (where
headers install to include/nats/) and FetchContent (where the build
interface exposes headers directly in src/).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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