• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/buildflag_header.gni")
6import("//cef/libcef/features/features.gni")
7
8# This file is in a separate directory so all targets in the build can refer to
9# the buildflag header to get the necessary preprocessor defines without
10# bringing in any CEF targets. Other targets can depend on this target
11# regardless of whether CEF is being built. Set the `enable_cef=false` GN arg to
12# disable the CEF changes when building Chrome.
13#
14# Example usage:
15#
16# 1. An existing GN configuration file at path/to/foo/BUILD.gn:
17#
18#    # Import the `enable_cef` arg.
19#    import("//cef/libcef/features/features.gni")
20#    ...
21#
22#    # An existing target that is modified for CEF.
23#    # The target type might instead be `component`, `source_set`, etc.
24#    static_library("foo") {
25#      sources = [ ... ]
26#
27#      deps = [
28#        # Always include the CEF features.
29#        "//cef/libcef/features",
30#        ...
31#      ]
32#
33#      if (enable_cef) {
34#        # Actions to perform when the CEF build is enabled.
35#
36#        # Optionally include CEF source files directly in this target. This
37#        # approach is required for targets that are either directly or
38#        # indirectly included in a `component` target (otherwise
39#        # `is_component_build=true` builds will fail). Keep in mind that these
40#        # files are part of this target instead of the `libcef_static` target
41#        # and therefore subject to any target-specific configuration settings
42#        # such as include paths, defines, compiler flags, etc.
43#        sources += [
44#          "//cef/libcef/browser/foo_helper.cc",
45#          "//cef/libcef/browser/foo_helper.h",
46#        ]
47#
48#        # Always include the CEF configuration.
49#        configs += [ "//cef/libcef/features:config" ]
50#     }
51#     ...
52#   }
53#
54# 2. An existing C++ source file at path/to/foo/foo.cc:
55#
56#    // Include the `BUILDFLAG(ENABLE_CEF)` definition.
57#    #include "cef/libcef/features/features.h"
58#    ...
59#
60#    #if BUILDFLAG(ENABLE_CEF)
61#    // CEF headers here...
62#    #include "cef/libcef/browser/foo_helper.h"
63#    #else
64#    // Chrome headers here...
65#    #endif
66#
67#    // An existing function that is modified for CEF.
68#    void DoFoo() {
69#    #if BUILDFLAG(ENABLE_CEF)
70#      // CEF implementation here...
71#      cef_foo_helper::DoFoo();
72#    #else
73#      // Chrome implementation here...
74#    #endif  // !BUILDFLAG(ENABLE_CEF)
75#    }
76#    ...
77#
78
79buildflag_header("features") {
80  header = "features.h"
81
82  flags = [
83    "ENABLE_CEF=$enable_cef",
84    "IS_CEF_SANDBOX_BUILD=$is_cef_sandbox_build",
85  ]
86}
87
88# Configuration for all targets that include CEF source code library-side.
89config("config") {
90  # CEF sources use includes relative to the CEF root directory.
91  include_dirs = [
92    "//cef",
93
94    # CEF generates some header files that also need to be discoverable.
95    "$root_build_dir/includes",
96  ]
97  defines = [
98    "BUILDING_CEF_SHARED",
99    "USING_CHROMIUM_INCLUDES",
100  ]
101}
102