diff --git a/include/mapnik/init_priority.hpp b/include/mapnik/init_priority.hpp new file mode 100644 index 000000000..e75be4233 --- /dev/null +++ b/include/mapnik/init_priority.hpp @@ -0,0 +1,34 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2017 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef MAPNIK_INIT_PRIORITY_HPP +#define MAPNIK_INIT_PRIORITY_HPP + +// helper macro for dealing with static variables initialising order fiasco (#3821) +#if defined(__GNUC__) || defined(__clang__) +#define MAPNIK_INIT_PRIORITY(priority) __attribute__((init_priority(priority))) +#else +#define MAPNIK_INIT_PRIORITY +// TODO: anything we can do on windows? +#endif + +#endif //MAPNIK_INIT_PRIORITY_HPP diff --git a/include/mapnik/json/generic_json_grammar_x3_def.hpp b/include/mapnik/json/generic_json_grammar_x3_def.hpp index 98ed4674e..ea4f52f3c 100644 --- a/include/mapnik/json/generic_json_grammar_x3_def.hpp +++ b/include/mapnik/json/generic_json_grammar_x3_def.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace mapnik { namespace json { namespace grammar { @@ -73,7 +74,7 @@ namespace { auto const& json_string = mapnik::json::unicode_string_grammar(); } // exported rules // start -generic_json_grammar_type const value __attribute__((init_priority(102))) ("JSON Value"); +generic_json_grammar_type const value MAPNIK_INIT_PRIORITY(102) ("JSON Value"); generic_json_key_value_type const key_value("JSON Object element"); // rules x3::rule const object("JSON Object"); diff --git a/include/mapnik/json/geojson_grammar_x3_def.hpp b/include/mapnik/json/geojson_grammar_x3_def.hpp index 407e87fdc..f5f52d5e6 100644 --- a/include/mapnik/json/geojson_grammar_x3_def.hpp +++ b/include/mapnik/json/geojson_grammar_x3_def.hpp @@ -23,10 +23,11 @@ #ifndef MAPNIK_JSON_GEOJSON_GRAMMAR_X3_DEF_HPP #define MAPNIK_JSON_GEOJSON_GRAMMAR_X3_DEF_HPP - #include #include #include +#include + #include namespace mapnik { namespace json { namespace grammar { @@ -89,8 +90,8 @@ struct geometry_type_ : x3::symbols // exported rules // start -geojson_grammar_type const value __attribute__((init_priority(106))) ("JSON Value"); -key_value_type const key_value __attribute__((init_priority(107))) ("JSON key/value"); +geojson_grammar_type const value MAPNIK_INIT_PRIORITY(106) ("JSON Value"); +key_value_type const key_value MAPNIK_INIT_PRIORITY(107) ("JSON key/value"); // rules x3::rule const object("JSON Object"); x3::rule const array("JSON Array"); diff --git a/include/mapnik/json/positions_grammar_x3_def.hpp b/include/mapnik/json/positions_grammar_x3_def.hpp index 2dec62fec..206d22251 100644 --- a/include/mapnik/json/positions_grammar_x3_def.hpp +++ b/include/mapnik/json/positions_grammar_x3_def.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace mapnik { namespace json { namespace grammar { @@ -42,7 +43,7 @@ auto assign_helper = [](auto const& ctx) } // anonymous ns // start rule -positions_grammar_type const positions __attribute__((init_priority(103))) ("Positions"); +positions_grammar_type const positions MAPNIK_INIT_PRIORITY(103) ("Positions"); // rules x3::rule const point("Position"); x3::rule const ring("Ring"); diff --git a/include/mapnik/json/topojson_grammar_x3_def.hpp b/include/mapnik/json/topojson_grammar_x3_def.hpp index f1e0481a8..54ba23963 100644 --- a/include/mapnik/json/topojson_grammar_x3_def.hpp +++ b/include/mapnik/json/topojson_grammar_x3_def.hpp @@ -26,6 +26,8 @@ #include #include #include +#include + #pragma GCC diagnostic push #include #include @@ -304,7 +306,7 @@ struct topojson_geometry_type_ : x3::symbols } topojson_geometry_type; // start rule -topojson_grammar_type const topology __attribute__((init_priority(104))) ("Topology"); +topojson_grammar_type const topology MAPNIK_INIT_PRIORITY(104) ("Topology"); // rules x3::rule const transform = "Transform"; x3::rule const bbox = "Bounding Box"; diff --git a/include/mapnik/json/unicode_string_grammar_x3_def.hpp b/include/mapnik/json/unicode_string_grammar_x3_def.hpp index 3234c73fa..2335b657b 100644 --- a/include/mapnik/json/unicode_string_grammar_x3_def.hpp +++ b/include/mapnik/json/unicode_string_grammar_x3_def.hpp @@ -24,6 +24,7 @@ #define MAPNIK_JSON_UNICODE_STRING_GRAMMAR_X3_DEF_HPP #include +#include // boost #include // @@ -109,7 +110,7 @@ x3::uint_parser const hex4 {}; x3::uint_parser const hex8 {}; // start rule -unicode_string_grammar_type const unicode_string __attribute__((init_priority(101))) ("Unicode String"); +unicode_string_grammar_type const unicode_string MAPNIK_INIT_PRIORITY(101) ("Unicode String"); // rules x3::rule const double_quoted("Double-quoted string"); x3::rule const escaped("Escaped Character");