Skip to content

Add MATSDK_HAVE_CS4 CMake option with public propagation to consumers#1476

Closed
bmehta001 wants to merge 2 commits into
microsoft:mainfrom
bmehta001:bhamehta/cs4-cmake-option
Closed

Add MATSDK_HAVE_CS4 CMake option with public propagation to consumers#1476
bmehta001 wants to merge 2 commits into
microsoft:mainfrom
bmehta001:bhamehta/cs4-cmake-option

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

Makes Common Schema 4.0 (CS4) a first-class, propagating build option instead of a raw compiler flag.

Problem

HAVE_CS4 / HAVE_CS4_FULL toggle optional CsProtocol fields whose presence changes the public struct layout (29 #ifdef HAVE_CS4 blocks in CsProtocol_types.hpp). Today CS4 can only be enabled via a raw -DCMAKE_CXX_FLAGS=-DHAVE_CS4=1 or a custom config header — both define it for the SDK build only. A consumer that includes the CS-protocol / IDecorator headers without the same define gets a mismatched layout (silent ODR/ABI hazard), and there's no first-class CMake toggle.

Change

  • New default-off options MATSDK_HAVE_CS4 and MATSDK_HAVE_CS4_FULL (the latter implies the former).
  • When enabled, HAVE_CS4 is applied as a PUBLIC compile definition on the exported MSTelemetry::mat target, so consumers inherit it automatically via INTERFACE_COMPILE_DEFINITIONS — keeping the SDK and its consumers in sync.
  • Docs updated (building-custom-SKU.md).

Default off ⇒ existing builds are unchanged.

Validation (x64-windows)

  • cmake -DMATSDK_HAVE_CS4=ON … configures cleanly.
  • The library builds with -DHAVE_CS4 (CS4 code path compiles).
  • The installed MSTelemetryTargets.cmake carries INTERFACE_COMPILE_DEFINITIONS "HAVE_CS4" — confirming propagation to consumers.

Follow-ups (not in this PR)

  • A dedicated Android -PHAVE_CS4=1 Gradle property mapping to this option (instead of the generic CXXFLAGS).
  • A cs4 feature on the cpp-client-telemetry vcpkg port.

Note for schema/collector owners: with this change, consumers linking a CS4-built MSTelemetry::mat now inherit HAVE_CS4 automatically.

HAVE_CS4 (and HAVE_CS4_FULL) toggle optional CsProtocol fields whose presence
changes the public struct layout, so the define must be consistent across the
SDK and any consumer that includes the CS-protocol / IDecorator headers.
Previously CS4 could only be enabled via a raw -DCMAKE_CXX_FLAGS=-DHAVE_CS4=1 or
a custom config header, which defines it for the SDK build only -- a consumer
that omits it gets a mismatched layout.

Add first-class, default-off options MATSDK_HAVE_CS4 / MATSDK_HAVE_CS4_FULL that
apply HAVE_CS4 as a PUBLIC compile definition on the exported MSTelemetry::mat
target, so consumers inherit it automatically. Default off => existing builds
are unchanged.

Validated on x64-windows: -DMATSDK_HAVE_CS4=ON configures, the library builds
with HAVE_CS4, and the installed MSTelemetryTargets.cmake carries
INTERFACE_COMPILE_DEFINITIONS "HAVE_CS4".

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 makes Common Schema 4.0 (CS4) support a first-class CMake configuration by introducing MATSDK_HAVE_CS4 / MATSDK_HAVE_CS4_FULL options and propagating the corresponding HAVE_CS4* preprocessor defines to consumers via the exported MSTelemetry::mat target—preventing SDK/consumer ABI mismatches due to CS4-dependent public struct layout changes.

Changes:

  • Add default-off CMake options MATSDK_HAVE_CS4 and MATSDK_HAVE_CS4_FULL.
  • Propagate HAVE_CS4 / HAVE_CS4_FULL as PUBLIC compile definitions on the mat target when enabled.
  • Update building-custom-SKU.md to document enabling CS4 via the new CMake options.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
CMakeLists.txt Adds new CMake options to control CS4/CS4_FULL builds.
lib/CMakeLists.txt Applies CS4-related compile definitions publicly on the exported mat target for consumer propagation.
docs/building-custom-SKU.md Documents how to enable CS4/CS4_FULL with the new CMake options.

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

Comment thread CMakeLists.txt
Comment thread docs/building-custom-SKU.md Outdated
CMakeLists.txt (option independence): MATSDK_HAVE_CS4_FULL now forces
MATSDK_HAVE_CS4 ON (cache FORCE) so the cache cannot be left FULL=ON/CS4=OFF;
lib/CMakeLists.txt simplified to check MATSDK_HAVE_CS4. Verified by configuring
with only -DMATSDK_HAVE_CS4_FULL=ON: it enables CS4 and defines both HAVE_CS4
and HAVE_CS4_FULL.

docs/building-custom-SKU.md: reframe HAVE_CS4 / HAVE_CS4_FULL as preprocessor
defines valid for any build system (CMake option is the CMake-preferred way), so
MSBuild/other users are not misled into thinking the defines are invalid.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@bmehta001 bmehta001 assigned bmehta001 and unassigned bmehta001 Jun 11, 2026
@bmehta001 bmehta001 closed this Jun 11, 2026
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