diff options
Diffstat (limited to 'pw_toolchain/traits.gni')
-rw-r--r-- | pw_toolchain/traits.gni | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/pw_toolchain/traits.gni b/pw_toolchain/traits.gni new file mode 100644 index 000000000..fee99dd23 --- /dev/null +++ b/pw_toolchain/traits.gni @@ -0,0 +1,57 @@ +# Copyright 2022 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +# Constants that represent the different C++ standards. These are set to the +# value of __cplusplus, which allows for unambiguous numeric comparison of C++ +# standards. +pw_toolchain_STANDARD = { + CXX98 = 199711 + CXX11 = 201103 + CXX14 = 201402 + CXX17 = 201703 + CXX20 = 202002 +} + +if (defined(is_fuchsia_tree) && is_fuchsia_tree) { + # In the Fuchsia build, this must align with how code is actually being + # compiled in that build, which is controlled by Fuchsia's build argument. + import("//build/config/fuchsia_cxx_version.gni") + + # This is not a GN build argument at all when Pigweed is integrated into the + # Fuchsia build, just a reflection of the Fuchsia build's configuration. + # **NOTE:** This line will blow up if the value isn't one of the supported + # ones listed above. + pw_toolchain_CXX_STANDARD = pw_toolchain_STANDARD["CXX$fuchsia_cxx_version"] +} else { + declare_args() { + # Specifies the C++ standard this toolchain is compiling for. The value + # must be an integer that matches the value of the __cplusplus macro when + # compiling with that standard. Use the pw_toolchain_CXX_STANDARD_## + # constants to set this value. + pw_toolchain_CXX_STANDARD = pw_toolchain_STANDARD.CXX17 + } +} + +assert( + pw_toolchain_CXX_STANDARD == pw_toolchain_STANDARD.CXX98 || + pw_toolchain_CXX_STANDARD == pw_toolchain_STANDARD.CXX11 || + pw_toolchain_CXX_STANDARD == pw_toolchain_STANDARD.CXX14 || + pw_toolchain_CXX_STANDARD == pw_toolchain_STANDARD.CXX17 || + pw_toolchain_CXX_STANDARD == pw_toolchain_STANDARD.CXX20, + "pw_toolchain_CXX_STANDARD ($pw_toolchain_CXX_STANDARD) is an " + + "unsupported value. The toolchain must set it to one of the " + + "pw_toolchain_STANDARD constants (e.g. pw_toolchain_STANDARD.CXX17).") + +assert(pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX14, + "Pigweed requires at least C++14.") |