1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2015 The Chromium Authors 2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file. 4*3ac0a46fSAndroid Build Coastguard Worker 5*3ac0a46fSAndroid Build Coastguard Worker #ifndef BUILD_BUILDFLAG_H_ 6*3ac0a46fSAndroid Build Coastguard Worker #define BUILD_BUILDFLAG_H_ 7*3ac0a46fSAndroid Build Coastguard Worker 8*3ac0a46fSAndroid Build Coastguard Worker // These macros un-mangle the names of the build flags in a way that looks 9*3ac0a46fSAndroid Build Coastguard Worker // natural, and gives errors if the flag is not defined. Normally in the 10*3ac0a46fSAndroid Build Coastguard Worker // preprocessor it's easy to make mistakes that interpret "you haven't done 11*3ac0a46fSAndroid Build Coastguard Worker // the setup to know what the flag is" as "flag is off". Normally you would 12*3ac0a46fSAndroid Build Coastguard Worker // include the generated header rather than include this file directly. 13*3ac0a46fSAndroid Build Coastguard Worker // 14*3ac0a46fSAndroid Build Coastguard Worker // This is for use with generated headers. See build/buildflag_header.gni. 15*3ac0a46fSAndroid Build Coastguard Worker 16*3ac0a46fSAndroid Build Coastguard Worker // This dance of two macros does a concatenation of two preprocessor args using 17*3ac0a46fSAndroid Build Coastguard Worker // ## doubly indirectly because using ## directly prevents macros in that 18*3ac0a46fSAndroid Build Coastguard Worker // parameter from being expanded. 19*3ac0a46fSAndroid Build Coastguard Worker #define BUILDFLAG_CAT_INDIRECT(a, b) a ## b 20*3ac0a46fSAndroid Build Coastguard Worker #define BUILDFLAG_CAT(a, b) BUILDFLAG_CAT_INDIRECT(a, b) 21*3ac0a46fSAndroid Build Coastguard Worker 22*3ac0a46fSAndroid Build Coastguard Worker // Accessor for build flags. 23*3ac0a46fSAndroid Build Coastguard Worker // 24*3ac0a46fSAndroid Build Coastguard Worker // To test for a value, if the build file specifies: 25*3ac0a46fSAndroid Build Coastguard Worker // 26*3ac0a46fSAndroid Build Coastguard Worker // ENABLE_FOO=true 27*3ac0a46fSAndroid Build Coastguard Worker // 28*3ac0a46fSAndroid Build Coastguard Worker // Then you would check at build-time in source code with: 29*3ac0a46fSAndroid Build Coastguard Worker // 30*3ac0a46fSAndroid Build Coastguard Worker // #include "foo_flags.h" // The header the build file specified. 31*3ac0a46fSAndroid Build Coastguard Worker // 32*3ac0a46fSAndroid Build Coastguard Worker // #if BUILDFLAG(ENABLE_FOO) 33*3ac0a46fSAndroid Build Coastguard Worker // ... 34*3ac0a46fSAndroid Build Coastguard Worker // #endif 35*3ac0a46fSAndroid Build Coastguard Worker // 36*3ac0a46fSAndroid Build Coastguard Worker // There will no #define called ENABLE_FOO so if you accidentally test for 37*3ac0a46fSAndroid Build Coastguard Worker // whether that is defined, it will always be negative. You can also use 38*3ac0a46fSAndroid Build Coastguard Worker // the value in expressions: 39*3ac0a46fSAndroid Build Coastguard Worker // 40*3ac0a46fSAndroid Build Coastguard Worker // const char kSpamServerName[] = BUILDFLAG(SPAM_SERVER_NAME); 41*3ac0a46fSAndroid Build Coastguard Worker // 42*3ac0a46fSAndroid Build Coastguard Worker // Because the flag is accessed as a preprocessor macro with (), an error 43*3ac0a46fSAndroid Build Coastguard Worker // will be thrown if the proper header defining the internal flag value has 44*3ac0a46fSAndroid Build Coastguard Worker // not been included. 45*3ac0a46fSAndroid Build Coastguard Worker #define BUILDFLAG(flag) (BUILDFLAG_CAT(BUILDFLAG_INTERNAL_, flag)()) 46*3ac0a46fSAndroid Build Coastguard Worker 47*3ac0a46fSAndroid Build Coastguard Worker #endif // BUILD_BUILDFLAG_H_ 48*3ac0a46fSAndroid Build Coastguard Worker 49