Merge pull request #4173 from mapnik/c++17

Support for C++17 builds
This commit is contained in:
Artem Pavlenko 2020-10-09 09:34:41 +01:00 committed by GitHub
commit 7ecff4b693
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 9923 additions and 8096 deletions

View file

@ -56,8 +56,9 @@ ICU_LIBS_DEFAULT='/usr/'
DEFAULT_CC = "cc" DEFAULT_CC = "cc"
DEFAULT_CXX = "c++" DEFAULT_CXX = "c++"
DEFAULT_CXX14_CXXFLAGS = " -std=c++14 -DU_USING_ICU_NAMESPACE=0" DEFAULT_CXX_STD = "14"
DEFAULT_CXX14_LINKFLAGS = "" DEFAULT_CXX_CXXFLAGS = " -DU_USING_ICU_NAMESPACE=0"
DEFAULT_CXX_LINKFLAGS = ""
if sys.platform == 'darwin': if sys.platform == 'darwin':
# homebrew default # homebrew default
ICU_INCLUDES_DEFAULT='/usr/local/opt/icu4c/include/' ICU_INCLUDES_DEFAULT='/usr/local/opt/icu4c/include/'
@ -355,6 +356,7 @@ opts = Variables()
opts.AddVariables( opts.AddVariables(
# Compiler options # Compiler options
('CXX', 'The C++ compiler to use to compile mapnik', DEFAULT_CXX), ('CXX', 'The C++ compiler to use to compile mapnik', DEFAULT_CXX),
('CXX_STD', 'The C++ compiler standard (string).', DEFAULT_CXX_STD),
('CC', 'The C compiler used for configure checks of C libs.', DEFAULT_CC), ('CC', 'The C compiler used for configure checks of C libs.', DEFAULT_CC),
('CUSTOM_CXXFLAGS', 'Custom C++ flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir>', ''), ('CUSTOM_CXXFLAGS', 'Custom C++ flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir>', ''),
('CUSTOM_DEFINES', 'Custom Compiler DEFINES, e.g. -DENABLE_THIS', ''), ('CUSTOM_DEFINES', 'Custom Compiler DEFINES, e.g. -DENABLE_THIS', ''),
@ -487,6 +489,7 @@ opts.AddVariables(
pickle_store = [# Scons internal variables pickle_store = [# Scons internal variables
'CC', # compiler user to check if c deps compile during configure 'CC', # compiler user to check if c deps compile during configure
'CXX', # C++ compiler to compile mapnik 'CXX', # C++ compiler to compile mapnik
'CXX_STD', # C++ standard e.g 17 (as in -std=c++17)
'CFLAGS', 'CFLAGS',
'CPPDEFINES', 'CPPDEFINES',
'CPPFLAGS', # c preprocessor flags 'CPPFLAGS', # c preprocessor flags
@ -1227,28 +1230,29 @@ int main()
context.Result(ret) context.Result(ret)
return ret return ret
def supports_cxx14(context,silent=False): __cplusplus = {'14':'201402L', '17':'201703L'}
def supports_cxx_std (context, silent=False):
cplusplus_string = __cplusplus[env['CXX_STD']]
if not silent: if not silent:
context.Message('Checking if compiler (%s) supports -std=c++14 flag... ' % context.env.get('CXX','CXX')) context.Message('Checking if compiler (%s) supports -std=c++%s flag... ' % (context.env.get('CXX','CXX'), env['CXX_STD']))
ret, out = context.TryRun(""" ret, out = context.TryRun("""
int main() int main()
{ {
#if __cplusplus >= 201402L #if __cplusplus >= %s
return 0; return 0;
#else #else
return -1; return -1;
#endif #endif
} }
""", '.cpp') """ % cplusplus_string ,'.cpp')
if silent: if silent:
context.did_show_result=1 context.did_show_result=1
context.Result(ret) context.Result(ret)
return ret return ret
conf_tests = { 'prioritize_paths' : prioritize_paths, conf_tests = { 'prioritize_paths' : prioritize_paths,
'CheckPKGConfig' : CheckPKGConfig, 'CheckPKGConfig' : CheckPKGConfig,
'CheckPKG' : CheckPKG, 'CheckPKG' : CheckPKG,
@ -1270,7 +1274,7 @@ conf_tests = { 'prioritize_paths' : prioritize_paths,
'harfbuzz_with_freetype_support': harfbuzz_with_freetype_support, 'harfbuzz_with_freetype_support': harfbuzz_with_freetype_support,
'boost_regex_has_icu' : boost_regex_has_icu, 'boost_regex_has_icu' : boost_regex_has_icu,
'sqlite_has_rtree' : sqlite_has_rtree, 'sqlite_has_rtree' : sqlite_has_rtree,
'supports_cxx14' : supports_cxx14, 'supports_cxx_std' : supports_cxx_std,
'CheckBoostScopedEnum' : CheckBoostScopedEnum, 'CheckBoostScopedEnum' : CheckBoostScopedEnum,
} }
@ -1414,13 +1418,13 @@ if not preconfigured:
# set any custom cxxflags and ldflags to come first # set any custom cxxflags and ldflags to come first
if sys.platform == 'darwin' and not env['HOST']: if sys.platform == 'darwin' and not env['HOST']:
DEFAULT_CXX14_CXXFLAGS += ' -stdlib=libc++' DEFAULT_CXX_CXXFLAGS += ' -stdlib=libc++'
DEFAULT_CXX14_LINKFLAGS = ' -stdlib=libc++' DEFAULT_CXX_LINKFLAGS = ' -stdlib=libc++'
env.Append(CPPDEFINES = env['CUSTOM_DEFINES']) env.Append(CPPDEFINES = env['CUSTOM_DEFINES'])
env.Append(CXXFLAGS = DEFAULT_CXX14_CXXFLAGS) env.Append(CXXFLAGS = "-std=c++%s %s" % (env['CXX_STD'], DEFAULT_CXX_CXXFLAGS))
env.Append(CXXFLAGS = env['CUSTOM_CXXFLAGS']) env.Append(CXXFLAGS = env['CUSTOM_CXXFLAGS'])
env.Append(CFLAGS = env['CUSTOM_CFLAGS']) env.Append(CFLAGS = env['CUSTOM_CFLAGS'])
env.Append(LINKFLAGS = DEFAULT_CXX14_LINKFLAGS) env.Append(LINKFLAGS = DEFAULT_CXX_LINKFLAGS)
custom_ldflags = env.ParseFlags(env['CUSTOM_LDFLAGS']) custom_ldflags = env.ParseFlags(env['CUSTOM_LDFLAGS'])
env.Append(LINKFLAGS = custom_ldflags.pop('LINKFLAGS'), env.Append(LINKFLAGS = custom_ldflags.pop('LINKFLAGS'),
@ -1600,9 +1604,10 @@ if not preconfigured:
if env['PRIORITIZE_LINKING']: if env['PRIORITIZE_LINKING']:
conf.prioritize_paths(silent=True) conf.prioritize_paths(silent=True)
# test for C++14 support, which is required # test for CXX_STD support, which is required
if not env['HOST'] and not conf.supports_cxx14(): if not env['HOST'] and not conf.supports_cxx_std():
color_print(1,"C++ compiler does not support C++14 standard (-std=c++14), which is required. Please upgrade your compiler") color_print(1,"C++ compiler does not support C++%s standard (-std=c++%s), which is required."
" Please upgrade your compiler" % (env['CXX_STD'], env['CXX_STD']))
Exit(1) Exit(1)
if not env['HOST']: if not env['HOST']:

View file

@ -53,6 +53,10 @@
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#if __cplusplus >= 201703L
#include <execution>
#endif
namespace mapnik namespace mapnik
{ {
@ -420,19 +424,18 @@ struct is_solid_visitor
{ {
return true; return true;
} }
template <typename T> template <typename T>
bool operator() (T const & data) const bool operator() (image_view<T> const& view) const
{ {
using pixel_type = typename T::pixel_type; using pixel_type = typename T::pixel_type;
if (data.width() > 0 && data.height() > 0) if (view.width() > 0 && view.height() > 0)
{ {
pixel_type const* first_row = data.get_row(0); pixel_type const* first_row = view.get_row(0);
pixel_type const first_pixel = first_row[0]; pixel_type const first_pixel = first_row[0];
for (std::size_t y = 0; y < data.height(); ++y) for (std::size_t y = 0; y < view.height(); ++y)
{ {
pixel_type const * row = data.get_row(y); pixel_type const * row = view.get_row(y);
for (std::size_t x = 0; x < data.width(); ++x) for (std::size_t x = 0; x < view.width(); ++x)
{ {
if (first_pixel != row[x]) if (first_pixel != row[x])
{ {
@ -443,6 +446,24 @@ struct is_solid_visitor
} }
return true; return true;
} }
template <typename T>
bool operator() (T const& image) const
{
using pixel_type = typename T::pixel_type;
if (image.size() > 0)
{
pixel_type const first_p = *image.begin();
auto itr = std::find_if(/*std::execution::par_unseq,*/ // still missing on ubuntu with
// clang++10/libc++ (!)
image.begin(), image.end(),
[first_p](pixel_type const p) {
return first_p != p;
});
return (itr == image.end());
}
return true;
}
}; };
} // end detail ns } // end detail ns

File diff suppressed because it is too large Load diff

View file

@ -67,6 +67,16 @@ std::pair<mapnik::datasource_ptr,mapnik::feature_ptr> fetch_first_feature(std::s
return std::make_pair(ds,feature); return std::make_pair(ds,feature);
} }
void iterate_over_features(mapnik::featureset_ptr features)
{
auto feature = features->next();
while (feature != nullptr)
{
feature = features->next();
}
}
} }
TEST_CASE("geojson") { TEST_CASE("geojson") {
@ -673,12 +683,7 @@ TEST_CASE("geojson") {
auto fields = ds->get_descriptor().get_descriptors(); auto fields = ds->get_descriptor().get_descriptors();
mapnik::query query(ds->envelope()); mapnik::query query(ds->envelope());
auto features = ds->features(query); auto features = ds->features(query);
REQUIRE_THROWS( REQUIRE_THROWS(iterate_over_features(features));
auto feature = features->next();
while (feature != nullptr)
{
feature = features->next();
});
} }
// cleanup // cleanup

View file

@ -19,16 +19,14 @@ SECTION("test bad filter input") {
mapnik::fill(im,mapnik::color("blue")); mapnik::fill(im,mapnik::color("blue"));
mapnik::set_pixel(im, 1, 1, mapnik::color("red")); mapnik::set_pixel(im, 1, 1, mapnik::color("red"));
REQUIRE_THROWS( mapnik::filter::filter_image(im, "foo,asdfasdf()"); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "foo,asdfasdf()"));
REQUIRE_THROWS( mapnik::filter::filter_image(im, "colorize-alpha("); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "colorize-alpha("));
REQUIRE_THROWS( mapnik::filter::filter_image(im, "color-to-alpha(blue"); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "color-to-alpha(blue"));
REQUIRE_THROWS( mapnik::filter::filter_image(im, "color-to-alpha(,blue)"); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "color-to-alpha(,blue)"));
REQUIRE_THROWS( mapnik::filter::filter_image(im, "colorize-alpha()"); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "colorize-alpha()"));
REQUIRE_THROWS(
mapnik::image_rgba8 const& im2 = im; mapnik::image_rgba8 const& im2 = im;
mapnik::image_rgba8 new_im = mapnik::filter::filter_image(im2, "foo"); REQUIRE_THROWS(mapnik::filter::filter_image(im2, "foo"));
);
CHECK(im(0,0) == 0xffff0000); CHECK(im(0,0) == 0xffff0000);
CHECK(im(0,1) == 0xffff0000); CHECK(im(0,1) == 0xffff0000);
@ -158,7 +156,7 @@ SECTION("test scale-hsla 2") {
// Should not throw on values out of [0, 1] // Should not throw on values out of [0, 1]
// https://github.com/mapnik/mapnik/issues/3052 // https://github.com/mapnik/mapnik/issues/3052
REQUIRE_NOTHROW(mapnik::filter::filter_image(im, "scale-hsla(0.0,1.5,-1.0,1.0,-1.0,2.0,1.0,1.0)");); REQUIRE_NOTHROW(mapnik::filter::filter_image(im, "scale-hsla(0.0,1.5,-1.0,1.0,-1.0,2.0,1.0,1.0)"));
CHECK(im(0,0) == 0xff0000ff); CHECK(im(0,0) == 0xff0000ff);
CHECK(im(0,1) == 0xffefeff4); CHECK(im(0,1) == 0xffefeff4);

View file

@ -16,6 +16,7 @@
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/filesystem/convenience.hpp> #include <boost/filesystem/convenience.hpp>
#include <boost/optional/optional_io.hpp>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
inline void make_directory(std::string const& dir) { inline void make_directory(std::string const& dir) {
@ -65,7 +66,7 @@ SECTION("readers") {
REQUIRE( mapnik::util::exists( should_throw ) ); REQUIRE( mapnik::util::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw); type = mapnik::type_from_filename(should_throw);
REQUIRE( type ); REQUIRE( type );
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type))); REQUIRE_THROWS(mapnik::get_image_reader(should_throw,*type));
// actually a png so jpeg reader should throw // actually a png so jpeg reader should throw
should_throw = "./test/data/images/landusepattern.jpg"; should_throw = "./test/data/images/landusepattern.jpg";
@ -84,7 +85,7 @@ SECTION("readers") {
#endif #endif
REQUIRE_THROWS(mapnik::image_rgba8 im(-10,-10)); // should throw rather than overflow REQUIRE_THROWS(mapnik::image_rgba8(-10,-10)); // should throw rather than overflow
#if defined(HAVE_CAIRO) #if defined(HAVE_CAIRO)
mapnik::cairo_surface_ptr image_surface( mapnik::cairo_surface_ptr image_surface(
@ -103,13 +104,13 @@ SECTION("readers") {
REQUIRE( mapnik::util::exists( should_throw ) ); REQUIRE( mapnik::util::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw); type = mapnik::type_from_filename(should_throw);
REQUIRE( type ); REQUIRE( type );
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type))); REQUIRE_THROWS(mapnik::get_image_reader(should_throw,*type));
should_throw = "./test/data/images/xcode-CgBI.png"; should_throw = "./test/data/images/xcode-CgBI.png";
REQUIRE( mapnik::util::exists( should_throw ) ); REQUIRE( mapnik::util::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw); type = mapnik::type_from_filename(should_throw);
REQUIRE( type ); REQUIRE( type );
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type))); REQUIRE_THROWS(mapnik::get_image_reader(should_throw,*type));
#endif #endif
#if defined(HAVE_TIFF) #if defined(HAVE_TIFF)
@ -117,7 +118,7 @@ SECTION("readers") {
REQUIRE( mapnik::util::exists( should_throw ) ); REQUIRE( mapnik::util::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw); type = mapnik::type_from_filename(should_throw);
REQUIRE( type ); REQUIRE( type );
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type))); REQUIRE_THROWS(mapnik::get_image_reader(should_throw,*type));
#endif #endif
#if defined(HAVE_WEBP) #if defined(HAVE_WEBP)
@ -125,7 +126,7 @@ SECTION("readers") {
REQUIRE( mapnik::util::exists( should_throw ) ); REQUIRE( mapnik::util::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw); type = mapnik::type_from_filename(should_throw);
REQUIRE( type ); REQUIRE( type );
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type))); REQUIRE_THROWS(mapnik::get_image_reader(should_throw,*type));
#endif #endif
} }
catch (std::exception const & ex) catch (std::exception const & ex)

View file

@ -8,33 +8,22 @@
#include "cleanup.hpp" // run_cleanup() #include "cleanup.hpp" // run_cleanup()
std::string plugin_path;
inline void set_plugin_path(Catch::ConfigData&, std::string const& _plugin_path ) { int main (int argc, char** argv)
plugin_path = _plugin_path;
}
std::string working_dir;
inline void set_working_dir(Catch::ConfigData&, std::string const& _working_dir ) {
working_dir = _working_dir;
}
int main (int argc, char* const argv[])
{ {
Catch::Session session; Catch::Session session;
std::string plugin_path;
std::string working_dir;
auto cli = session.cli()
|
Catch::clara::Opt(plugin_path, "plugins")
["-p"]["--plugins"] ("path to mapnik plugins")
|
Catch::clara::Opt(working_dir, "working directory")
["-C"]["--working-directory"] ("change working directory")
;
auto & cli = session.cli(); session.cli(cli);
cli["-p"]["--plugins"]
.describe("path to mapnik plugins")
.bind(&set_plugin_path, "plugins");
cli["-C"]["--working-directory"]
.describe("change working directory")
.bind(&set_working_dir, "working directory");
int result = session.applyCommandLine(argc, argv); int result = session.applyCommandLine(argc, argv);
if (!plugin_path.empty()) if (!plugin_path.empty())