Repository navigation
Conversation
…nitions The tool had one configuration macro, __DEBUG__, and it sat on the Debug flag line while the Dev line read that variable, so Dev carried Debug's definitions as a side effect of CMake's variable semantics rather than by any decision, and a source file had no way to ask "am I not Release". This replaces it with one macro per configuration, each written on its own flag line, each line reading only its own variable: DEBUG_BUILD=1 on CMAKE_CXX_FLAGS_DEBUG with -g -O0, DEV_BUILD=1 on CMAKE_CXX_FLAGS_DEV with -g -O1, RELEASE_BUILD=1 on CMAKE_CXX_FLAGS_RELEASE with -O3. The effective flags are what the inherited form produced; only the definitions are now each configuration's own, so #if DEV_BUILD and #if !RELEASE_BUILD say exactly what they mean. precompileDefinitionsDebug, precompileDefinitionsDev and precompileDefinitionsRelease append -D tokens to those same three lines for definitions that are not about the configuration itself - a project that compiles its test bodies into Debug and Dev writes the same value into the first two keys and leaves the third empty. Plain precompileDefinitions is an add_compile_definitions and so keeps belonging to all three configurations. BuildConfig gains a GetValues passthrough; ConfigParser already split on space, comma, semicolon and colon, and AddConfigDefinitions joins AddOptimizeLevel beside the other emitters.
mooming
force-pushed
the
per-config-precompile-definitions
branch
from
October 4, 2026 08:08
2781d62 to
34dfc7d
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
.project.config's only definition knob wasprecompileDefinitions, which becomes anadd_compile_definitionsand therefore belongs to every configuration. The single per-configuration macro the template carried was a hardcoded-D__DEBUG__on the Debug flag line — and the Dev line read${CMAKE_CXX_FLAGS_DEBUG}, so Dev received that define (and anything else written there) as a side effect of CMake's variable semantics rather than by any decision. A host project that needs a definition in one configuration had no input file for it: its only route was-DCMAKE_CXX_FLAGSon the configure command line, which a plaincmake -B buildsilently drops.Neither of the tool's existing input files can express it:
.module.config'sprecompileDefinitionsadd_compile_definitions, so it covers every configurationcustomCMake.txt, project rootadd_subdirectory, so children were already generated without it — measured: a postludeadd_compile_definitionsreaches the directory's own targets and no childcustomCMake.txt, one moduleWhat
One macro per configuration, each on its own flag line:
DEBUG_BUILD=1CMAKE_CXX_FLAGS_DEBUG-g -O0DEV_BUILD=1CMAKE_CXX_FLAGS_DEV-g -O1RELEASE_BUILD=1CMAKE_CXX_FLAGS_RELEASE-O3Each line reads only the variable it assigns, so definitions no longer travel between configurations. Dev's effective flags are unchanged: reading the Debug line produced
-g -O0followed by-O1, and the later-Owins, so the result is spelled out rather than derived.Source can now ask which configuration it is in (
#if DEV_BUILD) and, just as usefully, whether it is the shipping build (#if !RELEASE_BUILD= Debug and Dev). That pair is exactly the set the old__DEBUG__covered, which is what made the host project's rename a pure rename.precompileDefinitionsDebug,precompileDefinitionsDev,precompileDefinitionsReleaseappend-Dtokens to those same three lines, for definitions that are not about the configuration itself — a project compiling its test bodies into Debug and Dev writes the same value into the first two keys and leaves the third empty. Values are bare names (BUILD_TESTS BUILD_TESTSstyle:__TEST__ __UNIT_TEST__), the-Dis the emitter's, matchingprecompileDefinitions. PlainprecompileDefinitionskeeps meaning "all three configurations".BuildConfig::GetValuesis a passthrough toConfigParser::GetValues, which already split on space, comma, semicolon and colon;AddConfigDefinitionsjoins theAddOptimizeLevelemitters in the anonymous namespace. The code carries no explanatory comments —README.mdgained two sections ("Configuration macros", "Per-configuration definitions") and--helplists the keys.Verification
grep -c 'DDEBUG_BUILD'→ 151 lines inimpl-Debug.ninjaonly;DDEV_BUILD→ 151 inimpl-Dev.ninjaonly;DRELEASE_BUILD→ 151 inimpl-Release.ninjaonly__TEST__via the Debug/Dev keys__DEBUG__sites to#if !RELEASE_BUILDEngineTestruns 375 testlets in Debug and Dev and reports the same single pre-existing failure before and after the rename./generate_cmake_files.shrun twiceclang-format --dry-run -Werroron the four changed sourcesmakebuild --test-run03_external_libraryfails ontest_sdk.hnot found; reproduced with this change stashed, so pre-existing and unrelatedCo-Authored-By: Claude noreply@anthropic.com