Index: build/build_header.h |
diff --git a/build/build_header.h b/build/build_header.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e4f5304cdf9e7804801a7fe59589ecae04b5fd03 |
--- /dev/null |
+++ b/build/build_header.h |
@@ -0,0 +1,44 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
Mark Mentovai
2015/11/24 14:33:33
Optional, do it if you like it to prevent direct #
brettw
2015/11/24 23:36:01
I think directly including this file is both usele
|
+#ifndef BUILD_BUILD_HEADER_H_ |
+#define BUILD_BUILD_HEADER_H_ |
+ |
+// These macros un-mangle the names of the build flags in a way that looks |
+// natural, and gives errors if the flag is not defined. Normally in the |
+// preprocessor it's easy to make mistakes that interpret "you haven't done |
+// the setup to know what the flag is" as "flag is off". Normally you would |
+// include the generated header rather than include this file directly. |
+// |
+// This is for use with generated headers. See build/build_header.gni. |
+ |
+// This dance of two macros does a concatenation of two preprocessor args using |
+// ## doubly indirectly because using ## directly prevents macros in that |
+// parameter from being expanded. |
+#define BUILDFLAG_CAT_INDIRECT(a, b) a ## b |
+#define BUILDFLAG_CAT(a, b) BUILDFLAG_CAT_INDIRECT(a, b) |
+ |
+// Accessor for build flags. |
Mark Mentovai
2015/11/24 14:33:33
Since the former BUILDVAR is now covered by this,
|
+// |
+// To test for a value, if the build file specifies: |
+// |
+// ENABLE_FOO=true |
+// |
+// Then you would check at build-time in source code with: |
+// |
+// #include "foo_flags.h" // The header the build file specified. |
+// |
+// #if BUILDFLAG(ENABLE_FOO) |
+// ... |
+// #endif |
+// |
+// There will no #define called ENABLE_FOO so if you accidentally test for |
+// whether that is defined, it will always be negative. |
+// |
+// Because the flag is accessed as a preprocessor macro with (), an error |
+// will be thrown if the proper header defining the internal flag value has |
+// not been included. |
+#define BUILDFLAG(flag) (BUILDFLAG_CAT(BUILDFLAG_INTERNAL_, flag)()) |
Mark Mentovai
2015/11/24 14:33:33
I think that this can be buildflag.h now that the
brettw
2015/11/24 23:36:01
Done. I renamed the build scripts buildflag_header
|
+ |
+#endif // BUILD_BUILD_HEADER_H_ |