From 0a2388bcc564cd5284d28658d6ab8184361a0f02 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 14 Sep 2020 17:52:34 -0700 Subject: [PATCH] Define _USE_MATH_DEFINES on Windows where needed On Windows, to enable constants like M_PI in cmath/math.h the symbol _USE_MATH_DEFINES must be defined. It's easy to forget, and needs to be defined before the first (transitive) import of cmath, so instead we define in the build targets in which it's used. --- flow/BUILD.gn | 8 ++++++++ flow/matrix_decomposition_unittests.cc | 2 -- lib/ui/BUILD.gn | 9 ++++++++- lib/ui/painting/canvas.cc | 2 -- lib/ui/painting/gradient.cc | 2 -- lib/ui/painting/path.cc | 2 -- lib/ui/painting/path_measure.cc | 2 -- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/flow/BUILD.gn b/flow/BUILD.gn index 63f1fe529108b..70544c675af91 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -174,6 +174,14 @@ if (enable_unittests) { "//third_party/skia", ] + if (!defined(defines)) { + defines = [] + } + if (is_win) { + # Required for M_PI and others. + defines += [ "_USE_MATH_DEFINES" ] + } + if (is_fuchsia && flutter_enable_legacy_fuchsia_embedder) { sources += [ "layers/fuchsia_layer_unittests.cc" ] diff --git a/flow/matrix_decomposition_unittests.cc b/flow/matrix_decomposition_unittests.cc index ab0adc172bb31..bf23937415fb4 100644 --- a/flow/matrix_decomposition_unittests.cc +++ b/flow/matrix_decomposition_unittests.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#define _USE_MATH_DEFINES - #include "flutter/flow/matrix_decomposition.h" #include diff --git a/lib/ui/BUILD.gn b/lib/ui/BUILD.gn index 6c72102c2d9b8..841a6afa9c766 100644 --- a/lib/ui/BUILD.gn +++ b/lib/ui/BUILD.gn @@ -129,8 +129,15 @@ source_set("ui") { "//third_party/skia", ] + if (!defined(defines)) { + defines = [] + } if (flutter_enable_skshaper) { - defines = [ "FLUTTER_ENABLE_SKSHAPER" ] + defines += [ "FLUTTER_ENABLE_SKSHAPER" ] + } + if (is_win) { + # Required for M_PI and others. + defines += [ "_USE_MATH_DEFINES" ] } if (is_fuchsia && flutter_enable_legacy_fuchsia_embedder) { diff --git a/lib/ui/painting/canvas.cc b/lib/ui/painting/canvas.cc index c066ee3cf772f..68ae4898c176a 100644 --- a/lib/ui/painting/canvas.cc +++ b/lib/ui/painting/canvas.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#define _USE_MATH_DEFINES - #include "flutter/lib/ui/painting/canvas.h" #include diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index e242258e4ddb7..d71e75a495f94 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#define _USE_MATH_DEFINES - #include "flutter/lib/ui/painting/gradient.h" #include "third_party/tonic/converter/dart_converter.h" diff --git a/lib/ui/painting/path.cc b/lib/ui/painting/path.cc index b4b7ab55af84b..d0898a4ca283c 100644 --- a/lib/ui/painting/path.cc +++ b/lib/ui/painting/path.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#define _USE_MATH_DEFINES - #include "flutter/lib/ui/painting/path.h" #include diff --git a/lib/ui/painting/path_measure.cc b/lib/ui/painting/path_measure.cc index 16d3de021906f..af9e0e9837e1d 100644 --- a/lib/ui/painting/path_measure.cc +++ b/lib/ui/painting/path_measure.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#define _USE_MATH_DEFINES - #include "flutter/lib/ui/painting/path_measure.h" #include