Set C/C++ standard per-target instead of globally#513
Conversation
7f6b19a to
d02de38
Compare
|
I think I would rather have that in the different helpers like |
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]>
d02de38 to
e55f545
Compare
Second version suggested pushed, let me know if this fits ?
Tentative fix: |
|
This is correct, I did the same changes in #515, if you think that these are OK, I'll merge them. |
Looks good! |
Summary
The global
CMAKE_CXX_STANDARD/CMAKE_C_STANDARDinExtendBuildTypes.cmakeconflicts 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'stypeofusage 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()andddprof_add_library()helpers inHelperfunc.cmake. All ddprof-owned library targets now useddprof_add_library()instead ofadd_library(), andadd_exe()callsddprof_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)fromExtendBuildTypes.cmake.Also move
disable_clangtidy()fromClangTidy.cmaketoHelperfunc.cmakeso it remains available whenDDPROF_ENABLE_STATIC_ANALYSISis 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