1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 gitUpdater,
6 buildPackages,
7 cmake,
8 pkg-config,
9 boost,
10 cairo,
11 freetype,
12 gdal,
13 harfbuzz,
14 icu,
15 libjpeg,
16 libpng,
17 libtiff,
18 libwebp,
19 libxml2,
20 proj,
21 python3,
22 sqlite,
23 zlib,
24 catch2,
25 libpq,
26 protozero,
27 sparsehash,
28}:
29
30stdenv.mkDerivation rec {
31 pname = "mapnik";
32 version = "4.0.7";
33
34 src = fetchFromGitHub {
35 owner = "mapnik";
36 repo = "mapnik";
37 rev = "v${version}";
38 hash = "sha256-gJktRWcJiSGxxjvWFt+Kl9d7g+TOSPk2PfGP0LIVxt4=";
39 fetchSubmodules = true;
40 };
41
42 passthru.updateScript = gitUpdater { rev-prefix = "v"; };
43
44 postPatch = ''
45 substituteInPlace configure \
46 --replace-fail '$PYTHON scons/scons.py' ${buildPackages.scons}/bin/scons
47 rm -r scons
48 # Remove bundled 'sparsehash' directory in favor of 'sparsehash' package
49 rm -r deps/mapnik/sparsehash
50 '';
51
52 # a distinct dev output makes python-mapnik fail
53 outputs = [ "out" ];
54
55 patches = [
56 # The lib/cmake/harfbuzz/harfbuzz-config.cmake file in harfbuzz.dev is faulty,
57 # as it provides the wrong libdir. The workaround is to just rely on
58 # pkg-config to locate harfbuzz shared object files.
59 # Upstream HarfBuzz wants to drop CMake support anyway.
60 # See discussion: https://github.com/mapnik/mapnik/issues/4265
61 ./cmake-harfbuzz.patch
62 # Account for full paths when generating libmapnik.pc
63 ./export-pkg-config-full-paths.patch
64 # Use 'sparsehash' package.
65 ./use-sparsehash-package.patch
66 ];
67
68 nativeBuildInputs = [
69 cmake
70 pkg-config
71 ];
72
73 buildInputs = [
74 boost
75 cairo
76 freetype
77 gdal
78 harfbuzz
79 icu
80 libjpeg
81 libpng
82 libtiff
83 libwebp
84 proj
85 python3
86 sqlite
87 zlib
88 libxml2
89 libpq
90 protozero
91 sparsehash
92 ];
93
94 cmakeFlags = [
95 # Save time by not building some development-related code.
96 (lib.cmakeBool "BUILD_BENCHMARK" false)
97 (lib.cmakeBool "BUILD_DEMO_CPP" false)
98 ## Would require QT otherwise.
99 (lib.cmakeBool "BUILD_DEMO_VIEWER" false)
100 # Use 'protozero' package.
101 (lib.cmakeBool "USE_EXTERNAL_MAPBOX_PROTOZERO" true)
102 # macOS builds fail when using memory mapped file cache.
103 (lib.cmakeBool "USE_MEMORY_MAPPED_FILE" (!stdenv.hostPlatform.isDarwin))
104 # don't try to download sources for catch2, use our own
105 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_CATCH2" "${catch2.src}")
106 ];
107
108 doCheck = true;
109
110 # mapnik-config is currently not build with CMake. So we use the SCons for
111 # this one. We can't add SCons to nativeBuildInputs though, as stdenv would
112 # then try to build everything with scons. C++17 is the minimum supported
113 # C++ version.
114 preBuild = ''
115 cd ..
116 env CXX_STD=17 ${buildPackages.scons}/bin/scons utils/mapnik-config
117 cd build
118 '';
119
120 preInstall = ''
121 mkdir -p $out/bin
122 cp ../utils/mapnik-config/mapnik-config $out/bin/mapnik-config
123 '';
124
125 meta = with lib; {
126 description = "Open source toolkit for developing mapping applications";
127 homepage = "https://mapnik.org";
128 maintainers = with maintainers; [
129 hrdinka
130 hummeltech
131 ];
132 teams = [ teams.geospatial ];
133 license = licenses.lgpl21Plus;
134 platforms = platforms.all;
135 };
136}