Skip to content

Guard base-n target against parent-project collision#184

Merged
bkaradzic-microsoft merged 1 commit into
BabylonJS:mainfrom
bkaradzic-microsoft:bk-fix-base-n-collision
Jun 5, 2026
Merged

Guard base-n target against parent-project collision#184
bkaradzic-microsoft merged 1 commit into
BabylonJS:mainfrom
bkaradzic-microsoft:bk-fix-base-n-collision

Conversation

@bkaradzic-microsoft
Copy link
Copy Markdown
Contributor

Problem

When JsRuntimeHost is embedded via FetchContent in a parent project that already declares its own base-n INTERFACE target — e.g. BabylonNative, which uses base-n for its Window/Canvas polyfills — configuring fails:

CMake Error at .../jsruntimehost-src/CMakeLists.txt:150 (add_library):
  add_library cannot create target "base-n" because another target with the
  same name already exists.  The existing target is an interface library
  created in source directory ".../Dependencies".

This surfaced now because the merged File / FileReader polyfill (#169) switched its base64 encoder over to the base-n dependency, and BabylonNative declares base-n before it fetches JsRuntimeHost.

Fix

Guard the base-n block with NOT TARGET base-n so that when a parent project already provides the target, JsRuntimeHost adopts it instead of redeclaring. This is the standard CMake subproject pattern and mirrors BabylonNative's own if(NOT TARGET glslang) guards. Standalone JsRuntimeHost builds are unaffected (no pre-existing target → block runs as before).

Validation

When JsRuntimeHost is embedded via FetchContent in a parent project that
already declares its own 'base-n' INTERFACE target (e.g. BabylonNative),
the unconditional add_library(base-n INTERFACE) here fails with
"add_library cannot create target 'base-n' because another target with the
same name already exists". Guard the whole block with NOT TARGET base-n so
the parent-provided target wins, matching the standard CMake subproject
pattern (and BabylonNative's own 'if(NOT TARGET glslang)' guards).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 5, 2026 17:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the top-level CMake configuration to avoid redefining the base-n target when JsRuntimeHost is included as a subproject in a parent build that already provides a base-n target (e.g., via FetchContent). This prevents CMake configure-time failures due to duplicate target names while keeping standalone builds unchanged.

Changes:

  • Guard creation of the base-n INTERFACE target behind NOT TARGET base-n when JSRUNTIMEHOST_POLYFILL_FILE is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bkaradzic-microsoft bkaradzic-microsoft merged commit 5449381 into BabylonJS:main Jun 5, 2026
23 checks passed
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.

4 participants