From f0879bc8e67151eafd57f183c56c80d755d2d111 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Wed, 10 Jun 2026 23:02:27 -0500 Subject: [PATCH 1/2] Add MATSDK_HAVE_CS4 CMake option with PUBLIC propagation to consumers 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> --- CMakeLists.txt | 8 ++++++++ docs/building-custom-SKU.md | 4 ++-- lib/CMakeLists.txt | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dea843b23..8109c9995 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -293,6 +293,14 @@ option(LINK_STATIC_DEPENDS "Link dependencies for static build" YES) # Enable Azure Monitor / Application Insights end-point support option(BUILD_AZMON "Build for Azure Monitor" YES) +# Common Schema 4.0 (CS4) protocol support (CS3 by default). HAVE_CS4 toggles +# optional CsProtocol fields whose presence changes the public struct layout, so +# it is applied as a PUBLIC compile definition on the exported target (see +# lib/CMakeLists.txt) to keep the SDK and its consumers in sync. HAVE_CS4_FULL +# adds server/service extensions and implies HAVE_CS4. +option(MATSDK_HAVE_CS4 "Build with Common Schema 4.0 (CS4) support" OFF) +option(MATSDK_HAVE_CS4_FULL "Build with CS4 plus server/service extensions" OFF) + if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") option(BUILD_APPLE_HTTP "Build Apple HTTP client" YES) endif() diff --git a/docs/building-custom-SKU.md b/docs/building-custom-SKU.md index 0668fbe3f..461cd212e 100644 --- a/docs/building-custom-SKU.md +++ b/docs/building-custom-SKU.md @@ -30,8 +30,8 @@ Build recipe must contain the following preprocessor definitions: | HAVE_MAT_STORAGE | on | Enable SQLite persistent offline storage | | HAVE_MAT_NETDETECT | on | _Win32 Desktop only_: Use NLM COM object for network cost detection on Windows 8+ | | HAVE_MAT_SHORT_NS | off | Use short "MAT::" namespace instead of "Microsoft::Applications::Events::" to reduce the .DLL size | -| HAVE_CS4 | off | Build with Common Schema 4.0 support. Current default is `off`, i.e. building with Common Schema 3.0 support | -| HAVE_CS4_FULL | off | Enable additional Common Schema 4.0 protocol features needed by server / services SDK | +| HAVE_CS4 | off | Build with Common Schema 4.0 support (CS3 by default). Enable via the `-DMATSDK_HAVE_CS4=ON` CMake option, which defines `HAVE_CS4` as a PUBLIC compile definition on the exported `MSTelemetry::mat` target so consumers stay in sync (`HAVE_CS4` changes the public CsProtocol struct layout and must match across the SDK and its consumers). | +| HAVE_CS4_FULL | off | Enable additional Common Schema 4.0 protocol features needed by server / services SDK. Enable via `-DMATSDK_HAVE_CS4_FULL=ON` (implies `HAVE_CS4`). | | COMPACT_SDK | off | Built-in build recipe for smallest possible SDK. Turns most features off. Includes_mat/config-compact.h_ | ## Building custom SDK SKU: MSBuild example diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 533144c06..b4da509fe 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -338,6 +338,18 @@ target_include_directories(mat ${CMAKE_CURRENT_SOURCE_DIR}/utils ) +# Common Schema 4.0 support. HAVE_CS4 toggles optional CsProtocol fields whose +# presence changes the public struct layout, so it must be defined consistently +# across the SDK and its consumers. Expose it as a PUBLIC (propagating) compile +# definition on the exported target rather than a raw build flag, so consumers +# linking MSTelemetry::mat inherit it automatically. HAVE_CS4_FULL implies HAVE_CS4. +if(MATSDK_HAVE_CS4 OR MATSDK_HAVE_CS4_FULL) + target_compile_definitions(mat PUBLIC HAVE_CS4) +endif() +if(MATSDK_HAVE_CS4_FULL) + target_compile_definitions(mat PUBLIC HAVE_CS4_FULL) +endif() + if(APPLE AND BUILD_OBJC_WRAPPER) if(MATSDK_OBJC_PRIVACYGUARD_AVAILABLE) target_compile_definitions(mat PRIVATE MATSDK_OBJC_PRIVACYGUARD_AVAILABLE=1) From 4dd67aa56660d29eb26e087d1e65d1dd00df8427 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Wed, 10 Jun 2026 23:26:59 -0500 Subject: [PATCH 2/2] cs4: address Copilot round-1 - reconcile CS4 options + clarify docs 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> --- CMakeLists.txt | 7 +++++++ docs/building-custom-SKU.md | 4 ++-- lib/CMakeLists.txt | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8109c9995..d54eb58ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,6 +300,13 @@ option(BUILD_AZMON "Build for Azure Monitor" YES) # adds server/service extensions and implies HAVE_CS4. option(MATSDK_HAVE_CS4 "Build with Common Schema 4.0 (CS4) support" OFF) option(MATSDK_HAVE_CS4_FULL "Build with CS4 plus server/service extensions" OFF) +# CS4_FULL requires CS4. Force the options consistent so the cache state and any +# downstream checks of MATSDK_HAVE_CS4 are reliable (rather than relying on a +# downstream OR). +if(MATSDK_HAVE_CS4_FULL AND NOT MATSDK_HAVE_CS4) + message(STATUS "MATSDK_HAVE_CS4_FULL implies MATSDK_HAVE_CS4; enabling MATSDK_HAVE_CS4.") + set(MATSDK_HAVE_CS4 ON CACHE BOOL "Build with Common Schema 4.0 (CS4) support" FORCE) +endif() if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") option(BUILD_APPLE_HTTP "Build Apple HTTP client" YES) diff --git a/docs/building-custom-SKU.md b/docs/building-custom-SKU.md index 461cd212e..8e5722ffb 100644 --- a/docs/building-custom-SKU.md +++ b/docs/building-custom-SKU.md @@ -30,8 +30,8 @@ Build recipe must contain the following preprocessor definitions: | HAVE_MAT_STORAGE | on | Enable SQLite persistent offline storage | | HAVE_MAT_NETDETECT | on | _Win32 Desktop only_: Use NLM COM object for network cost detection on Windows 8+ | | HAVE_MAT_SHORT_NS | off | Use short "MAT::" namespace instead of "Microsoft::Applications::Events::" to reduce the .DLL size | -| HAVE_CS4 | off | Build with Common Schema 4.0 support (CS3 by default). Enable via the `-DMATSDK_HAVE_CS4=ON` CMake option, which defines `HAVE_CS4` as a PUBLIC compile definition on the exported `MSTelemetry::mat` target so consumers stay in sync (`HAVE_CS4` changes the public CsProtocol struct layout and must match across the SDK and its consumers). | -| HAVE_CS4_FULL | off | Enable additional Common Schema 4.0 protocol features needed by server / services SDK. Enable via `-DMATSDK_HAVE_CS4_FULL=ON` (implies `HAVE_CS4`). | +| HAVE_CS4 | off | Preprocessor define enabling Common Schema 4.0 (CS3 by default). Any build system can define it (e.g. via a custom config header or compiler flag); CMake builds should prefer `-DMATSDK_HAVE_CS4=ON`, which defines `HAVE_CS4` and propagates it to consumers via the exported `MSTelemetry::mat` target. It changes the public CsProtocol struct layout and must match across the SDK and its consumers. | +| HAVE_CS4_FULL | off | Preprocessor define adding the Common Schema 4.0 server / services extensions (implies `HAVE_CS4`). CMake builds should use `-DMATSDK_HAVE_CS4_FULL=ON`. | | COMPACT_SDK | off | Built-in build recipe for smallest possible SDK. Turns most features off. Includes_mat/config-compact.h_ | ## Building custom SDK SKU: MSBuild example diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b4da509fe..ad771e067 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -342,8 +342,9 @@ target_include_directories(mat # presence changes the public struct layout, so it must be defined consistently # across the SDK and its consumers. Expose it as a PUBLIC (propagating) compile # definition on the exported target rather than a raw build flag, so consumers -# linking MSTelemetry::mat inherit it automatically. HAVE_CS4_FULL implies HAVE_CS4. -if(MATSDK_HAVE_CS4 OR MATSDK_HAVE_CS4_FULL) +# linking MSTelemetry::mat inherit it automatically. MATSDK_HAVE_CS4_FULL forces +# MATSDK_HAVE_CS4 on in the root CMakeLists, so checking MATSDK_HAVE_CS4 suffices. +if(MATSDK_HAVE_CS4) target_compile_definitions(mat PUBLIC HAVE_CS4) endif() if(MATSDK_HAVE_CS4_FULL)