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