portfile.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. vcpkg_fail_port_install(ON_ARCH "arm")
  2. # NOTE: update the version and checksum for new GDAL release
  3. set(GDAL_VERSION_STR "3.2.2")
  4. set(GDAL_VERSION_PKG "322")
  5. set(GDAL_PACKAGE_SUM "ce319e06c78bd076228b3710c127cdbd37c7d6fb23966b47df7287eaffe86a05d4ddcc78494c8bfcaf4db98a71f2ed50a01fb3ca2fe1c10cf0d2e812683c8e53")
  6. vcpkg_download_distfile(ARCHIVE
  7. URLS "http://download.osgeo.org/gdal/${GDAL_VERSION_STR}/gdal${GDAL_VERSION_PKG}.zip"
  8. FILENAME "gdal${GDAL_VERSION_PKG}.zip"
  9. SHA512 ${GDAL_PACKAGE_SUM}
  10. )
  11. set(GDAL_PATCHES
  12. 0001-Fix-debug-crt-flags.patch
  13. 0002-Fix-build.patch
  14. 0004-Fix-cfitsio.patch
  15. 0005-Fix-configure.patch
  16. )
  17. if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
  18. list(APPEND GDAL_PATCHES 0003-Fix-static-build.patch)
  19. else()
  20. list(APPEND GDAL_PATCHES 0006-Fix-mingw-dllexport.patch)
  21. endif()
  22. vcpkg_extract_source_archive_ex(
  23. ARCHIVE "${ARCHIVE}"
  24. OUT_SOURCE_PATH SOURCE_PATH
  25. PATCHES ${GDAL_PATCHES}
  26. )
  27. set(GDAL_EXES
  28. gdal_contour
  29. gdal_create
  30. gdal_grid
  31. gdal_rasterize
  32. gdal_translate
  33. gdal_viewshed
  34. gdaladdo
  35. gdalbuildvrt
  36. gdaldem
  37. gdalenhance
  38. gdalinfo
  39. gdallocationinfo
  40. gdalmanage
  41. gdalmdiminfo
  42. gdalmdimtranslate
  43. gdalsrsinfo
  44. gdaltindex
  45. gdaltransform
  46. gdalwarp
  47. gnmanalyse
  48. gnmmanage
  49. nearblack
  50. ogr2ogr
  51. ogrinfo
  52. ogrlineref
  53. ogrtindex
  54. testepsg
  55. )
  56. if (VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
  57. set(NATIVE_DATA_DIR "${CURRENT_PACKAGES_DIR}/share/gdal")
  58. set(NATIVE_HTML_DIR "${CURRENT_PACKAGES_DIR}/share/gdal/html")
  59. include("${CMAKE_CURRENT_LIST_DIR}/dependency_win.cmake")
  60. find_dependency_win()
  61. set(NMAKE_OPTIONS "")
  62. set(NMAKE_OPTIONS_REL "")
  63. set(NMAKE_OPTIONS_DBG "")
  64. if("mysql-libmysql" IN_LIST FEATURES OR "mysql-libmariadb" IN_LIST FEATURES)
  65. list(APPEND NMAKE_OPTIONS "MYSQL_INC_DIR=${MYSQL_INCLUDE_DIR}")
  66. list(APPEND NMAKE_OPTIONS_REL "MYSQL_LIB=${MYSQL_LIBRARY_REL}")
  67. list(APPEND NMAKE_OPTIONS_DBG "MYSQL_LIB=${MYSQL_LIBRARY_DBG}")
  68. endif()
  69. list(APPEND NMAKE_OPTIONS
  70. "DATADIR=${NATIVE_DATA_DIR}"
  71. "HTMLDIR=${NATIVE_HTML_DIR}"
  72. "GEOS_DIR=${GEOS_INCLUDE_DIR}"
  73. "GEOS_CFLAGS=-I${GEOS_INCLUDE_DIR} -DHAVE_GEOS"
  74. "PROJ_INCLUDE=-I${PROJ_INCLUDE_DIR}"
  75. "EXPAT_DIR=${EXPAT_INCLUDE_DIR}"
  76. "EXPAT_INCLUDE=-I${EXPAT_INCLUDE_DIR}"
  77. "CURL_INC=-I${CURL_INCLUDE_DIR}"
  78. "SQLITE_INC=-I${SQLITE_INCLUDE_DIR} ${HAVE_SPATIALITE}"
  79. "PG_INC_DIR=${PGSQL_INCLUDE_DIR}"
  80. OPENJPEG_ENABLED=YES
  81. "OPENJPEG_CFLAGS=-I${OPENJPEG_INCLUDE_DIR}"
  82. OPENJPEG_VERSION=20100
  83. WEBP_ENABLED=YES
  84. "WEBP_CFLAGS=-I${WEBP_INCLUDE_DIR}"
  85. "LIBXML2_INC=-I${XML2_INCLUDE_DIR}"
  86. PNG_EXTERNAL_LIB=1
  87. "PNGDIR=${PNG_INCLUDE_DIR}"
  88. "ZLIB_INC=-I${ZLIB_INCLUDE_DIR}"
  89. ZLIB_EXTERNAL_LIB=1
  90. ACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1
  91. MSVC_VER=1900
  92. )
  93. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  94. list(APPEND NMAKE_OPTIONS WIN64=YES)
  95. endif()
  96. if (VCPKG_LIBRARY_LINKAGE STREQUAL "static")
  97. list(APPEND NMAKE_OPTIONS CURL_CFLAGS=-DCURL_STATICLIB)
  98. list(APPEND NMAKE_OPTIONS DLLBUILD=0)
  99. list(APPEND NMAKE_OPTIONS "PROJ_FLAGS=-DPROJ_STATIC -DPROJ_VERSION=5")
  100. else()
  101. # Enables PDBs for release and debug builds
  102. list(APPEND NMAKE_OPTIONS WITH_PDB=1)
  103. list(APPEND NMAKE_OPTIONS DLLBUILD=1)
  104. endif()
  105. if (VCPKG_CRT_LINKAGE STREQUAL "static")
  106. set(LINKAGE_FLAGS "/MT")
  107. else()
  108. set(LINKAGE_FLAGS "/MD")
  109. endif()
  110. list(APPEND NMAKE_OPTIONS_REL
  111. ${NMAKE_OPTIONS}
  112. "GDAL_HOME=${CURRENT_PACKAGES_DIR}"
  113. "CXX_CRT_FLAGS=${LINKAGE_FLAGS}"
  114. "PROJ_LIBRARY=${PROJ_LIBRARY_REL}"
  115. "PNG_LIB=${PNG_LIBRARY_REL}"
  116. "GEOS_LIB=${GEOS_LIBRARY_REL}"
  117. "EXPAT_LIB=${EXPAT_LIBRARY_REL}"
  118. "CURL_LIB=${CURL_LIBRARY_REL} wsock32.lib wldap32.lib winmm.lib"
  119. "SQLITE_LIB=${SQLITE_LIBRARY_REL} ${SPATIALITE_LIBRARY_REL}"
  120. "OPENJPEG_LIB=${OPENJPEG_LIBRARY_REL}"
  121. "WEBP_LIBS=${WEBP_LIBRARY_REL}"
  122. "LIBXML2_LIB=${XML2_LIBRARY_REL} ${ICONV_LIBRARY_REL} ${LZMA_LIBRARY_REL}"
  123. "ZLIB_LIB=${ZLIB_LIBRARY_REL}"
  124. "PG_LIB=${PGSQL_LIBRARY_REL} Secur32.lib Shell32.lib Advapi32.lib Crypt32.lib Gdi32.lib ${OPENSSL_LIBRARY_REL}"
  125. )
  126. list(APPEND NMAKE_OPTIONS_DBG
  127. ${NMAKE_OPTIONS}
  128. "GDAL_HOME=${CURRENT_PACKAGES_DIR}/debug"
  129. "CXX_CRT_FLAGS=${LINKAGE_FLAGS}d"
  130. "PROJ_LIBRARY=${PROJ_LIBRARY_DBG}"
  131. "PNG_LIB=${PNG_LIBRARY_DBG}"
  132. "GEOS_LIB=${GEOS_LIBRARY_DBG}"
  133. "EXPAT_LIB=${EXPAT_LIBRARY_DBG}"
  134. "CURL_LIB=${CURL_LIBRARY_DBG} wsock32.lib wldap32.lib winmm.lib"
  135. "SQLITE_LIB=${SQLITE_LIBRARY_DBG} ${SPATIALITE_LIBRARY_DBG}"
  136. "OPENJPEG_LIB=${OPENJPEG_LIBRARY_DBG}"
  137. "WEBP_LIBS=${WEBP_LIBRARY_DBG}"
  138. "LIBXML2_LIB=${XML2_LIBRARY_DBG} ${ICONV_LIBRARY_DBG} ${LZMA_LIBRARY_DBG}"
  139. "ZLIB_LIB=${ZLIB_LIBRARY_DBG}"
  140. "PG_LIB=${PGSQL_LIBRARY_DBG} Secur32.lib Shell32.lib Advapi32.lib Crypt32.lib Gdi32.lib ${OPENSSL_LIBRARY_DBG}"
  141. DEBUG=1
  142. )
  143. # Begin build process
  144. vcpkg_install_nmake(
  145. SOURCE_PATH "${SOURCE_PATH}"
  146. TARGET devinstall
  147. OPTIONS_RELEASE
  148. "${NMAKE_OPTIONS_REL}"
  149. OPTIONS_DEBUG
  150. "${NMAKE_OPTIONS_DBG}"
  151. )
  152. if(NOT VCPKG_LIBRARY_LINKAGE STREQUAL "static")
  153. file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/share/gdal/html")
  154. endif()
  155. if (VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
  156. vcpkg_copy_tools(TOOL_NAMES ${GDAL_EXES} AUTO_CLEAN)
  157. else()
  158. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
  159. endif()
  160. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/share/gdal/html")
  161. vcpkg_copy_pdbs()
  162. if(NOT VCPKG_LIBRARY_LINKAGE STREQUAL "static")
  163. file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/gdal204.pdb")
  164. endif()
  165. else()
  166. # See https://github.com/microsoft/vcpkg/issues/16990
  167. file(TOUCH "${SOURCE_PATH}/config.rpath")
  168. set(CONF_OPTS
  169. --with-hide-internal-symbols=yes
  170. --with-perl=no
  171. --with-python=no
  172. --with-java=no
  173. )
  174. set(CONF_CHECKS "")
  175. function(add_config option check)
  176. list(APPEND CONF_OPTS "${option}")
  177. set(CONF_OPTS "${CONF_OPTS}" PARENT_SCOPE)
  178. list(APPEND CONF_CHECKS "${check}")
  179. set(CONF_CHECKS "${CONF_CHECKS}" PARENT_SCOPE)
  180. endfunction()
  181. # parameters in the same order as the dependencies in vcpkg.json
  182. add_config("--with-cfitsio=yes" "CFITSIO support: external")
  183. add_config("--with-curl=yes" "cURL support .wms/wcs/....:yes")
  184. add_config("--with-expat=yes" "Expat support: yes")
  185. add_config("--with-geos=yes" "GEOS support: yes")
  186. add_config("--with-gif=yes" "LIBGIF support: external")
  187. add_config("--with-hdf5=yes" "HDF5 support: yes")
  188. add_config("--with-libjson=yes" "checking for JSONC... yes")
  189. add_config("--with-geotiff=yes" "LIBGEOTIFF support: external")
  190. add_config("--with-jpeg=yes" "LIBJPEG support: external")
  191. add_config("--with-liblzma=yes" "LIBLZMA support: yes")
  192. add_config("--with-png=yes" "LIBPNG support: external")
  193. add_config("--with-pg=yes" "PostgreSQL support: yes")
  194. add_config("--with-webp=yes" "WebP support: yes")
  195. add_config("--with-xml2=yes" "libxml2 support: yes")
  196. add_config("--with-netcdf=yes" "NetCDF support: yes")
  197. add_config("--with-openjpeg=yes" "OpenJPEG support: yes")
  198. add_config("--with-proj=yes" "PROJ >= 6: yes")
  199. add_config("--with-sqlite3=yes" "SQLite support: yes")
  200. add_config("--with-libtiff=yes" "LIBTIFF support: external")
  201. add_config("--with-libz=yes" "LIBZ support: external")
  202. add_config("--with-zstd=yes" "ZSTD support: yes")
  203. if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
  204. list(APPEND CONF_OPTS --without-libtool --without-ld-shared)
  205. endif()
  206. if("system-libraries" IN_LIST FEATURES)
  207. set(DISABLE_SYSTEM_LIBRARIES OFF)
  208. else()
  209. set(DISABLE_SYSTEM_LIBRARIES ON)
  210. endif()
  211. if ("libspatialite" IN_LIST FEATURES)
  212. add_config("--with-spatialite=yes" "SpatiaLite support: yes")
  213. elseif(DISABLE_SYSTEM_LIBRARIES)
  214. add_config("--with-spatialite=no" "SpatiaLite support: no")
  215. endif()
  216. if ("mysql-libmariadb" IN_LIST FEATURES)
  217. add_config("--with-mysql=yes" "MySQL support: yes")
  218. elseif(DISABLE_SYSTEM_LIBRARIES)
  219. add_config("--with-mysql=no" "MySQL support: no")
  220. endif()
  221. if(DISABLE_SYSTEM_LIBRARIES)
  222. list(APPEND CONF_OPTS
  223. # Too much: --disable-all-optional-drivers
  224. # alphabetical order
  225. --with-armadillo=no
  226. --with-charls=no
  227. --with-crypto=no
  228. --with-cryptopp=no
  229. --with-dds=no
  230. --with-dods-root=no
  231. --with-ecw=no
  232. --with-epsilon=no
  233. --with-exr=no
  234. --with-fgdb=no
  235. --with-fme=no
  236. --with-freexl=no
  237. --with-grass=no
  238. --with-gta=no
  239. --with-hdf4=no
  240. --with-hdfs=no
  241. --with-heif=no
  242. --with-idb=no
  243. --with-ingres=no
  244. --with-jasper=no
  245. --with-jp2lura=no
  246. --with-kakadu=no
  247. --with-kea=no
  248. --with-libdeflate=no
  249. --with-libgrass=no
  250. --with-libkml=no
  251. --with-mdb=no
  252. --with-mrsid=no
  253. --with-mrsid_lidar=no
  254. --with-msg=no
  255. --with-mongocxx=no
  256. --with-mongocxxv3=no
  257. --with-oci=no
  258. --with-odbc=no
  259. --with-ogdi=no
  260. --with-opencl=no
  261. --with-pcidsk=no
  262. --with-pcraster=no
  263. --with-pcre=no
  264. --with-pdfium=no
  265. --with-podofo=no
  266. --with-poppler=no
  267. --with-qhull=no
  268. --with-rasdaman=no
  269. --with-rasterlite2=no
  270. --with-rdb=no
  271. --with-sfcgal=no
  272. --with-sosi=no
  273. --with-teigha=no
  274. --with-tiledb=no
  275. --with-xerces=no
  276. )
  277. endif()
  278. # proj needs a C++ runtime library
  279. if(VCPKG_TARGET_IS_OSX)
  280. list(APPEND CONF_OPTS "--with-proj-extra-lib-for-test=-lc++")
  281. else()
  282. list(APPEND CONF_OPTS "--with-proj-extra-lib-for-test=-lstdc++")
  283. endif()
  284. vcpkg_configure_make(
  285. SOURCE_PATH "${SOURCE_PATH}"
  286. AUTOCONFIG
  287. COPY_SOURCE
  288. OPTIONS
  289. ${CONF_OPTS}
  290. OPTIONS_DEBUG
  291. --enable-debug
  292. )
  293. # Verify configuration results (tightly coupled to vcpkg_configure_make)
  294. function(check_config logfile)
  295. set(failed_checks "")
  296. file(READ "${logfile}" log)
  297. foreach(check IN LISTS CONF_CHECKS)
  298. if(NOT log MATCHES "${check}")
  299. string(APPEND failed_checks "\n ${check}")
  300. endif()
  301. endforeach()
  302. if(failed_checks)
  303. get_filename_component(file "${logfile}" NAME_WE)
  304. message(FATAL_ERROR "${file}: Configuration failed for ${failed_checks}")
  305. endif()
  306. endfunction()
  307. foreach(suffix IN ITEMS rel dbg)
  308. set(log "${CURRENT_BUILDTREES_DIR}/config-${TARGET_TRIPLET}-${suffix}-out.log")
  309. if(EXISTS "${log}")
  310. check_config("${log}")
  311. endif()
  312. endforeach()
  313. vcpkg_install_make(MAKEFILE GNUmakefile)
  314. file(REMOVE_RECURSE
  315. "${CURRENT_PACKAGES_DIR}/lib/gdalplugins"
  316. "${CURRENT_PACKAGES_DIR}/debug/lib/gdalplugins"
  317. "${CURRENT_PACKAGES_DIR}/debug/share"
  318. )
  319. vcpkg_fixup_pkgconfig()
  320. set(pc_file_debug "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/gdal.pc")
  321. if(EXISTS "${pc_file_debug}")
  322. vcpkg_replace_string("${pc_file_debug}" "${prefix}/../../include" "${prefix}/../include")
  323. vcpkg_replace_string("${pc_file_debug}" "${exec_prefix}/include" "${prefix}/../include")
  324. endif()
  325. endif()
  326. file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
  327. configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY)
  328. # Handle copyright
  329. file(INSTALL "${SOURCE_PATH}/LICENSE.TXT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
  330. set(GDAL_EXES_RELEASE ${GDAL_EXES})
  331. set(GDAL_EXES_DEBUG ${GDAL_EXES})
  332. list(TRANSFORM GDAL_EXES_RELEASE PREPEND "${CURRENT_PACKAGES_DIR}/tools/gdal/bin/")
  333. list(TRANSFORM GDAL_EXES_DEBUG PREPEND "${CURRENT_PACKAGES_DIR}/tools/gdal/debug/bin/")
  334. file(REMOVE ${GDAL_EXES_RELEASE} ${GDAL_EXES_DEBUG})