Skip to content

Set C/C++ standard per-target instead of globally#513

Closed
xroche wants to merge 1 commit into
DataDog:mainfrom
algolia:refactor/target-scoped-cxx-standard
Closed

Set C/C++ standard per-target instead of globally#513
xroche wants to merge 1 commit into
DataDog:mainfrom
algolia:refactor/target-scoped-cxx-standard

Conversation

@xroche

@xroche xroche commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Summary

The global CMAKE_CXX_STANDARD / CMAKE_C_STANDARD in ExtendBuildTypes.cmake conflicts with toolchain-injected values when ddprof is built through a Conan toolchain or as a subdirectory of another project. Conan profiles that set C++23 with extensions OFF break ddprof's typeof usage in logging macros.

CMake's own documentation recommends setting the standard on targets rather than globally: CXX_STANDARD target property. Target-level properties take precedence over CMAKE_CXX_STANDARD, so each target compiles with the right settings regardless of what the toolchain injects.

How

Add ddprof_set_standard() and ddprof_add_library() helpers in Helperfunc.cmake. All ddprof-owned library targets now use ddprof_add_library() instead of add_library(), and add_exe() calls ddprof_set_standard() internally. This keeps the standard management in helpers rather than scattered per-target calls.

Remove the global set(CMAKE_CXX_STANDARD 20) / set(CMAKE_C_STANDARD 11) from ExtendBuildTypes.cmake.

Also move disable_clangtidy() from ClangTidy.cmake to Helperfunc.cmake so it remains available when DDPROF_ENABLE_STATIC_ANALYSIS is OFF (fixes a bug from #512).

Third-party targets (abseil, llvm-demangle) are unaffected; they set their own standard or use the compiler default.

Follow-up PR for C++23 source compatibility: #515

🤖 Generated with Claude Code

@xroche
xroche force-pushed the refactor/target-scoped-cxx-standard branch from 7f6b19a to d02de38 Compare March 19, 2026 09:16
@xroche
xroche marked this pull request as ready for review March 19, 2026 12:49
@r1viollet

Copy link
Copy Markdown
Collaborator

I think I would rather have that in the different helpers like add_exectuable, add_library instead of having it with different targets.
We should also make ddprof can compile with C++ 23. I'll have to look at that later. Thanks for raising

The global CMAKE_CXX_STANDARD / CMAKE_C_STANDARD in ExtendBuildTypes.cmake
conflicts with toolchain-injected values when ddprof is built through a
Conan toolchain or as a subdirectory of another project. Conan profiles
that set C++23 with extensions OFF break ddprof's typeof usage in logging
macros.

Add ddprof_set_standard() and ddprof_add_library() helpers in
Helperfunc.cmake. All ddprof-owned library targets now use
ddprof_add_library() instead of add_library(), and add_exe() calls
ddprof_set_standard() internally. This keeps the standard management in
helpers rather than scattered per-target calls.

Also move disable_clangtidy() from ClangTidy.cmake to Helperfunc.cmake
so it remains available when DDPROF_ENABLE_STATIC_ANALYSIS is OFF.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@xroche

xroche commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

I think I would rather have that in the different helpers like add_exectuable, add_library instead of having it with different targets.

Second version suggested pushed, let me know if this fits ?

We should also make ddprof can compile with C++ 23. I'll have to look at that later. Thanks for raising

Tentative fix:
#516

@r1viollet

Copy link
Copy Markdown
Collaborator

This is correct, I did the same changes in #515, if you think that these are OK, I'll merge them.

@r1viollet r1viollet closed this Mar 19, 2026
@xroche

xroche commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

This is correct, I did the same changes in #515, if you think that these are OK, I'll merge them.

Looks good!

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