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