diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 00000000..436e45df --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,59 @@ +name: Windows + +on: + push: + branches: [cmake] + pull_request: + branches: [cmake] + +# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md +jobs: + tests: + strategy: + matrix: + #os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-22.04, windows-2022] + #config: [Release, Debug] + config: [Release] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + + - name: Install PostgreSQL server headers + run: | + sudo apt update + sudo apt-get install postgresql-server-dev-14 + if: runner.os == 'Linux' + + - name: Configure PATH + run: echo "$PGBIN" >> $GITHUB_PATH + if: runner.os == 'Windows' + + - name: Generate + run: cmake -B build . + + - name: Build + working-directory: build + run: cmake --build . --config ${{ matrix.config }} + + - name: Install with sudo + working-directory: build + run: sudo cmake --install . --component extension --config ${{ matrix.config }} + if: runner.os == 'Linux' + + - name: Install without sudo + working-directory: build + run: cmake --install . --component extension --config ${{ matrix.config }} + if: runner.os == 'Windows' + + - name: Test + continue-on-error: true + run: | + ctest --output-on-failure --build-config ${{ matrix.config }} + cat D:/a/h3-pg/h3-pg/build/log/initdb.log + +defaults: + run: + shell: bash diff --git a/.gitignore b/.gitignore index 8a84eaea..7562e02a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +build + # C *.o *.bc diff --git a/.tmp-tools/Dockerfile b/.tmp-tools/Dockerfile new file mode 100644 index 00000000..8cf975a7 --- /dev/null +++ b/.tmp-tools/Dockerfile @@ -0,0 +1,56 @@ +ARG UBUNTU=focal +FROM ubuntu:${UBUNTU} +ARG UBUNTU + +# set timezone +RUN ln --symbolic --no-dereference --force \ + /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime + +RUN apt-get update && apt-get install -y \ + build-essential \ + #cmake \ + git \ + pgxnclient + +# H3 requires CMake 3.20, which has not landed in ubuntu +# as of writing. So we setup cmake apt repository +RUN if [ "$UBUNTU" != "impish" ] ; then apt-key adv --fetch-keys https://apt.kitware.com/keys/kitware-archive-latest.asc ; fi +RUN if [ "$UBUNTU" != "impish" ] ; then echo "deb https://apt.kitware.com/ubuntu/ ${UBUNTU} main" >> /etc/apt/sources.list.d/pgdg.list ; fi +RUN apt-get update && apt-get install -y cmake +# we can remove the block above when 3.20 lands + +# setup postgresql apt repository +RUN apt-key adv --fetch-keys https://www.postgresql.org/media/keys/ACCC4CF8.asc +RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ ${UBUNTU}-pgdg main" >> /etc/apt/sources.list.d/pgdg.list + +ARG POSTGRESQL=14 +ARG POSTGIS=3 + +# install postgresql and postgis +RUN apt-get update && apt-get install -y \ + postgresql-${POSTGRESQL}-postgis-${POSTGIS}-scripts \ + postgresql-${POSTGRESQL}-postgis-${POSTGIS} \ + postgresql-server-dev-${POSTGRESQL} \ + postgresql-${POSTGRESQL} + +# install pg_validate_extupgrade +RUN apt-get update && apt install -y cargo +RUN git clone https://github.com/rjuju/pg_validate_extupgrade.git +WORKDIR pg_validate_extupgrade +RUN cargo fetch --locked +RUN RUSTUP_TOOLCHAIN=stable CARGO_TARGET_DIR=target \ + cargo build --frozen --release --all-features +RUN ./target/release/pg_validate_extupgrade --version +RUN cp ./target/release/pg_validate_extupgrade /usr/bin/ +# For some reason i need this to run pg_validate_extupgrade +RUN echo "local all postgres peer" > /etc/postgresql/${POSTGRESQL}/main/pg_hba.conf +RUN echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/${POSTGRESQL}/main/pg_hba.conf + +# install sudo +RUN apt-get update && apt-get install -y \ + sudo + +# run it! +WORKDIR /github/workspace +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.tmp-tools/build-with-cmake.sh b/.tmp-tools/build-with-cmake.sh new file mode 100755 index 00000000..bfb1bc04 --- /dev/null +++ b/.tmp-tools/build-with-cmake.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -e +set -u + + +BASEDIR=$(dirname $(realpath "$0")) + +cd $BASEDIR + +sudo rm -rf ../build +mkdir ../build + +docker build -t tmp . +docker run --rm -v "$PWD"/..:/github/workspace tmp \ No newline at end of file diff --git a/.tmp-tools/entrypoint.sh b/.tmp-tools/entrypoint.sh new file mode 100755 index 00000000..9fe8e90a --- /dev/null +++ b/.tmp-tools/entrypoint.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env sh +set -e + +chmod -R a+w build + +service postgresql start + + +# first regular cmake +su postgres -p -c "cmake -B build ." + +cd build +su postgres -p -c "cmake --build . --config Release" +cmake --install . --component extension # sudo +su postgres -p -c "ctest --output-on-failure" + +cd .. +rm -rf build + +# also try makefile pgxn wrapper +#sudo -u postgres make all +#make install # sudo +#sudo -u postgres make test \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..4f3d2153 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.14) # FetchContent_MakeAvailable (CMake 3.14) + +project(h3-pg VERSION 4.0.1 + DESCRIPTION "Bindings for H3" + LANGUAGES C) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +# enable testing and set BUILD_TESTING if no parent project +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + message(STATUS "Testing enabled") + include(CTest) +endif() + +find_package(PostgreSQL REQUIRED) + +add_subdirectory(h3) +add_subdirectory(h3_postgis) \ No newline at end of file diff --git a/Makefile b/Makefile index 93ec40d9..d277ce6a 100644 --- a/Makefile +++ b/Makefile @@ -12,126 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -EXTENSION = h3 h3_postgis +# this file only exists to support pgxnclient -# extract extension version from .control file -EXTVERSION = $(shell grep default_version h3.control | \ - sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/") +all: cmake + cmake --build build -# h3 core library version to clone and statically link -LIBH3_VERSION = v4.0.1 -# directory that h3 core repository is cloned into -LIBH3_SOURCE = libh3-$(LIBH3_VERSION) -# h3 static library location -LIBH3_BUILD = $(LIBH3_SOURCE)/build -# sql files used for installation, update and testing -SQL_INSTALLS = $(wildcard h3/sql/install/*.sql) -SQL_UPDATES = $(wildcard h3/sql/updates/*.sql) -SQL_TESTS = $(wildcard h3/test/sql/*.sql) -SQL_FULLINSTALL = h3--$(EXTVERSION).sql +cmake: + cmake -S . -B build -# postgis extension -SQL_INSTALLS_H3_POSTGIS = $(wildcard h3_postgis/sql/install/*.sql) -SQL_UPDATES_H3_POSTGIS = $(wildcard h3_postgis/sql/updates/*.sql) -SQL_FULLINSTALL_H3_POSTGIS = h3_postgis--$(EXTVERSION).sql +install: + cmake --install build --component extension -# a shared library to build from multiple source files -MODULE_big = h3 -# object files to be linked together -OBJS = $(patsubst %.c,%.o,$(wildcard h3/src/*.c)) -# random files to install into $PREFIX/share/$MODULEDIR -DATA = $(SQL_UPDATES) $(SQL_UPDATES_H3_POSTGIS) -DATA_built = $(SQL_FULLINSTALL) $(SQL_FULLINSTALL_H3_POSTGIS) -# will be added to MODULE_big link line -SHLIB_LINK += -lh3 -L$(LIBH3_BUILD)/lib -# will be added to CPPFLAGS -PG_CPPFLAGS += -I$(LIBH3_BUILD)/src/h3lib/include -Ih3/src -# list of regression test cases (without suffix) -REGRESS = $(basename $(notdir $(SQL_TESTS))) -# additional switches to pass to pg_regress -REGRESS_OPTS = \ - --inputdir=h3/test \ - --outputdir=h3/test \ - --load-extension=h3 -# extra files to remove in make clean -EXTRA_CLEAN += \ - $(LIBH3_SOURCE) \ - $(DATA_built) \ - h3/src/extension.h \ - $(wildcard h3/test/sql/ci-*.sql) \ - $(wildcard h3/test/expected/ci-*.out) \ - $(wildcard *.BAK) \ - /tmp/extra-functions \ - /tmp/excluded-functions \ - h3/test/regression.diffs h3/test/regression.out h3/test/results \ - h3-*.zip +installcheck: + cmake --build build --target installcheck -PG_CONFIG = pg_config - -# additional flags -CFLAGS_ADD := -PG_CC := $(shell $(PG_CONFIG) --cc) -CHECK_FLAG_CMD := echo 'int main() { return 0; }' | $(PG_CC) -x c - -o /dev/null {flag} 2>&1 1>/dev/null; echo $$? - -# add -mpc64 flag is supported -CHECK_FLAG_MPC64 := $(shell $(subst {flag},-mpc64,$(CHECK_FLAG_CMD))) -ifeq ($(CHECK_FLAG_MPC64),0) - CFLAGS_ADD += -mpc64 -endif - -# PGXS boilerplate -CUSTOM_COPT=-flto $(CFLAGS_ADD) -PGXS := $(shell $(PG_CONFIG) --pgxs) -include $(PGXS) - -########################################################################### -# Non-standard PGXS stuff below -########################################################################### - -$(OBJS): $(LIBH3_BUILD) h3/src/extension.h - -# targets for building H3 library internals -$(LIBH3_SOURCE): - git clone --branch $(LIBH3_VERSION) --depth 1 \ - https://github.com/uber/h3 $(LIBH3_SOURCE) -$(LIBH3_BUILD): $(LIBH3_SOURCE) - mkdir -p $(LIBH3_BUILD) - cd $(LIBH3_BUILD) && cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_C_FLAGS="-fPIC -fvisibility=hidden -flto -fwrapv $(CFLAGS_ADD)" \ - -DBUILD_TESTING=OFF \ - -DENABLE_COVERAGE=OFF \ - -DENABLE_DOCS=OFF \ - -DENABLE_FORMAT=OFF \ - -DENABLE_LINTING=OFF \ - .. - cmake --build $(LIBH3_BUILD) --target h3 - cmake --build $(LIBH3_BUILD) --target binding-functions - -# generate header file with extension version baked in -h3/src/extension.h: h3/src/extension.in.h - sed -e 's/@EXTVERSION@/$(EXTVERSION)/g' \ - $< > $@ - -# generate full installation sql (from uninstalled to latest) -$(SQL_FULLINSTALL): $(sort $(SQL_INSTALLS)) - cat $^ > $@ -$(SQL_FULLINSTALL_H3_POSTGIS): $(sort $(SQL_INSTALLS_H3_POSTGIS)) - cat $^ > $@ - -# package for distribution -dist: $(SQL_FULLINSTALL) $(SQL_FULLINSTALL_H3_POSTGIS) - git archive --prefix=h3-$(EXTVERSION)/ \ - --output h3-${EXTVERSION}.zip \ - --add-file=$(SQL_FULLINSTALL) \ - --add-file=$(SQL_FULLINSTALL_H3_POSTGIS) \ - HEAD +.PHONY: cmake format ########################################################################### # Extra CI testing targets ########################################################################### -format: clean +format: pgindent # Run on dev using: @@ -139,90 +40,3 @@ format: clean docs/api.md: $(SQL_INSTALLS) python .github/documentation/generate.py "h3/sql/install/*" > $@ npx doctoc $@ - -# functions which we have decided not to provide bindings for -EXCLUDED_BINDING_FUNCTIONS = \ - degs_to_rads \ - rads_to_degs \ - to_string \ - string_to_h3 - -# functions provided that are not part of expected binding functions -EXTRA_BINDING_FUNCTIONS = \ - get_extension_version \ - cell_to_children_slow \ - cell_to_geo_boundary_geography \ - cell_to_geo_boundary_geometry \ - cell_to_geography \ - cell_to_geometry \ - cell_to_boundary_wkb - -/tmp/excluded-functions: - echo "$(EXCLUDED_BINDING_FUNCTIONS)" | tr " " "\n" > $@ - -/tmp/extra-functions: - echo "$(EXTRA_BINDING_FUNCTIONS)" | tr " " "\n" > $@ - -ARCH_SQL = "SELECT typbyval FROM pg_type WHERE typname = 'h3index';" - -ifeq ($(ARCH),amd64) - ARCH_BOOL:=t -endif -ifndef ARCH_BOOL - ARCH_BOOL:=f -endif - -# rules for testing if arch determines pass by value/reference -h3/test/sql/ci-arch-$(ARCH).sql: $(SQL_FULLINSTALL) - echo $(ARCH_SQL) > $@ -h3/test/expected/ci-arch-$(ARCH).out: $(SQL_UPDATES) - psql -c "DROP DATABASE IF EXISTS pg_regress;" - psql -c "CREATE DATABASE pg_regress;" - psql -d pg_regress -c "CREATE EXTENSION postgis;" - psql -d pg_regress -c "CREATE EXTENSION h3;" - echo $(ARCH_SQL) > $@ - psql -d pg_regress -c $(ARCH_SQL) | sed '3 s/.*/ ${ARCH_BOOL}/' - >> $@ - psql -c "DROP DATABASE pg_regress;" - - -PRINT_FUNCTIONS_SQL = "SELECT proname, proisstrict, provolatile, proparallel, prosrc FROM pg_proc WHERE proname LIKE '%h3%' ORDER BY proname, prosrc;" - -# rules for testing the update path against full install -h3/test/expected/ci-install.out: $(SQL_UPDATES) - psql -c "DROP DATABASE IF EXISTS pg_regress;" - psql -c "CREATE DATABASE pg_regress;" - psql -d pg_regress -c "CREATE EXTENSION h3;" - echo $(PRINT_FUNCTIONS_SQL) >> $@ - psql -d pg_regress -c $(PRINT_FUNCTIONS_SQL) >> $@ - psql -c "DROP DATABASE pg_regress;" - -# generate expected bindings from h3 generated binding function list -h3/test/expected/ci-bindings.out: $(LIBH3_BUILD)/binding-functions /tmp/excluded-functions - psql -c "DROP DATABASE IF EXISTS pg_regress;" - psql -c "CREATE DATABASE pg_regress;" - echo "\\\echo '$(shell \ - cat ${LIBH3_BUILD}/binding-functions \ - | sed -r 's/\bh3//g' \ - | sed -r 's/([A-Z]|[0-9]+)/_\L\1/g' | sed 's/^_//' \ - | sed -r 's/h_3/h3/g' \ - | sed -r 's/i_i_i/iii/g' \ - | sed -e 's/\(.*\)/\L\1/' \ - | grep -v -x -F -f /tmp/excluded-functions \ - | sort | uniq \ - )'" > /tmp/ci-bindings.out - cat /tmp/ci-bindings.out > $@ - psql -d pg_regress -f /tmp/ci-bindings.out >> $@ - psql -c "DROP DATABASE pg_regress;" - -# generate actual bindings from installed extension -h3/test/sql/ci-bindings.sql: h3/test/expected/ci-install.out /tmp/extra-functions - echo "\\\echo '$(shell \ - cat h3/test/expected/ci-install.out \ - | grep -o '^ h3_\w*' \ - | sed -r 's/ \bh3_//g' \ - | grep -v -x -F -f /tmp/extra-functions \ - | sort | uniq \ - )'" > $@ - -ci: h3/test/sql/ci-arch-$(ARCH).sql h3/test/expected/ci-arch-$(ARCH).out h3/test/sql/ci-bindings.sql h3/test/expected/ci-bindings.out -.PHONY: ci format \ No newline at end of file diff --git a/cmake/FetchH3.cmake b/cmake/FetchH3.cmake new file mode 100644 index 00000000..3e0915a0 --- /dev/null +++ b/cmake/FetchH3.cmake @@ -0,0 +1,26 @@ +include(FetchContent) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE INTERNAL "") +set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "") + + +# Avoid building tooling we won't need for release +set(BUILD_ALLOC_TESTS OFF CACHE BOOL "" FORCE) +set(BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE) +set(BUILD_FILTERS OFF CACHE BOOL "" FORCE) +set(BUILD_GENERATORS OFF CACHE BOOL "" FORCE) +#set(BUILD_TESTING OFF CACHE BOOL "" FORCE) +set(BUILD_FUZZERS OFF CACHE BOOL "" FORCE) +set(ENABLE_LIBFUZZER OFF CACHE BOOL "" FORCE) +set(ENABLE_COVERAGE OFF CACHE BOOL "" FORCE) +set(ENABLE_DOCS OFF CACHE BOOL "" FORCE) +set(ENABLE_FORMAT OFF CACHE BOOL "" FORCE) +set(ENABLE_LINTING OFF CACHE BOOL "" FORCE) + +FetchContent_Declare(h3 + URL https://github.com/uber/h3/archive/refs/tags/v4.0.1.tar.gz + URL_HASH SHA256=01891901707c6430caaea7e645ff5ac6980cae166094a6f924ded197e5774a19 +) +FetchContent_MakeAvailable(h3) + +set(H3_INCLUDE_DIR ${h3_BINARY_DIR}/src/h3lib/include) \ No newline at end of file diff --git a/cmake/FindPostgreSQL.cmake b/cmake/FindPostgreSQL.cmake new file mode 100644 index 00000000..e674fa1b --- /dev/null +++ b/cmake/FindPostgreSQL.cmake @@ -0,0 +1,55 @@ +find_program(PostgreSQL_PG_CONFIG pg_config + PATH + /usr/local/pgsql/bin + /opt/PostgreSQL/*/bin + /Library/PostgreSQL/*/bin + $ENV{ProgramFiles}/PostgreSQL/*/bin + $ENV{SystemDrive}/PostgreSQL/*/bin + DOC "Path to the pg_config executable" +) + +function(get_pg_config var) + execute_process( + COMMAND ${PostgreSQL_PG_CONFIG} ${ARGN} + OUTPUT_VARIABLE out + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "${var}: ${out}") + set(${var} ${out} PARENT_SCOPE) +endfunction() + +get_pg_config(PostgreSQL_VERSION_STRING --version) +# linux: PostgreSQL 13.0 (Ubuntu 13.0-1.pgdg20.04+1) +# win32: PostgreSQL 13.0 +get_pg_config(PostgreSQL_INCLUDE_DIR --includedir) +# linux: /usr/include/postgresql +# win32: C:/PROGRA~1/POSTGR~1/13/include +get_pg_config(PostgreSQL_INCLUDE_SERVER_DIR --includedir-server) +# linux: /usr/include/postgresql/13/server +# win32: C:/PROGRA~1/POSTGR~1/13/include/server +get_pg_config(PostgreSQL_LIBRARY_DIR --libdir) +# linux: /usr/lib/x86_64-linux-gnu +# win32: C:/PROGRA~1/POSTGR~1/13/lib +get_pg_config(PostgreSQL_PKG_LIBRARY_DIR --pkglibdir) +# linux: /usr/lib/postgresql/13/lib +# win32: C:/PROGRA~1/POSTGR~1/13/lib +get_pg_config(PostgreSQL_SHARE_DIR --sharedir) +# linux: /usr/share/postgresql/13 +# win32: C:/PROGRA~1/POSTGR~1/13/share + +# below not set on WIN32: +get_pg_config(PostgreSQL_CPP_FLAGS --cppflags) +get_pg_config(PostgreSQL_C_FLAGS --cflags) +get_pg_config(PostgreSQL_LD_FLAGS --ldflags) +get_pg_config(PostgreSQL_LIBS --libs) + + +# from timescaledb: +# Only Windows and FreeBSD need the base include/ dir instead of include/server/ +set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_SERVER_DIR}) +if(WIN32) + list(APPEND PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR}) + list(APPEND PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_SERVER_DIR}/port/win32) + if(MSVC) + list(APPEND PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_SERVER_DIR}/port/win32_msvc) + endif(MSVC) +endif(WIN32) \ No newline at end of file diff --git a/h3/CMakeLists.txt b/h3/CMakeLists.txt new file mode 100644 index 00000000..b5191d3f --- /dev/null +++ b/h3/CMakeLists.txt @@ -0,0 +1,25 @@ +set(EXT_NAME h3) + +add_subdirectory(sql) +add_subdirectory(src) + +# if(BUILD_TESTING) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + message(STATUS "add tests subdir") + add_subdirectory(test) + + add_test(NAME "ValidateUpgrade" + COMMAND pg_validate_extupgrade + --extname h3 + --from 0.1.0 + --to 4.0.1) +endif() + +set(EXT_CONTROL_FILE ${EXT_NAME}.control) +configure_file(${EXT_CONTROL_FILE} ${EXT_CONTROL_FILE}) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXT_CONTROL_FILE} + DESTINATION "${PostgreSQL_SHARE_DIR}/extension" + COMPONENT extension +) \ No newline at end of file diff --git a/h3.control b/h3/h3.control similarity index 60% rename from h3.control rename to h3/h3.control index 4607ce85..58042f82 100644 --- a/h3.control +++ b/h3/h3.control @@ -1,3 +1,3 @@ comment = 'H3 bindings for PostgreSQL' -default_version = 'unreleased' +default_version = '@PROJECT_VERSION@' relocatable = true diff --git a/h3/pg_validate_extupgrade.toml b/h3/pg_validate_extupgrade.toml deleted file mode 100644 index 4c63bf9d..00000000 --- a/h3/pg_validate_extupgrade.toml +++ /dev/null @@ -1,6 +0,0 @@ -extname = 'h3' -from = '0.1.0' -to = 'unreleased' -extra_queries = [ - "SELECT COUNT(*) FROM pg_class WHERE relname = 'dump_0'" -] diff --git a/h3/sql/CMakeLists.txt b/h3/sql/CMakeLists.txt new file mode 100644 index 00000000..3488bd09 --- /dev/null +++ b/h3/sql/CMakeLists.txt @@ -0,0 +1,61 @@ +set(EXT_SQL_FILE ${CMAKE_CURRENT_BINARY_DIR}/${EXT_NAME}--${PROJECT_VERSION}.sql) + +set(INSTALL_SQL_FILES + install/00-type.sql + install/01-indexing.sql + install/02-inspection.sql + install/03-traversal.sql + install/04-hierarchy.sql + install/05-regions.sql + install/06-edge.sql + install/07-vertex.sql + install/08-miscellaneous.sql + install/10-operators.sql + install/11-opclass_btree.sql + install/12-opclass_hash.sql + install/20-casts.sql + install/30-extension.sql + install/31-wkb.sql + install/99-deprecated.sql +) + +set(UPDATE_SQL_FILES + updates/h3--0.1.0.sql + updates/h3--0.1.0--0.2.0.sql + updates/h3--0.2.0--0.3.0.sql + updates/h3--0.3.0--0.3.1.sql + updates/h3--0.3.1--0.3.2.sql + updates/h3--0.3.2--0.4.0.sql + updates/h3--0.4.0--1.0.0.sql + updates/h3--1.0.0--1.0.1.sql + updates/h3--1.0.1--1.0.2.sql + updates/h3--1.0.2--1.0.3.sql + updates/h3--1.0.3--1.0.4.sql + updates/h3--1.0.4--1.0.5.sql + updates/h3--1.0.5--1.0.6.sql + updates/h3--1.0.6--3.4.0.sql + updates/h3--3.4.0--3.4.1.sql + updates/h3--3.4.1--3.5.0.sql + updates/h3--3.5.0--3.6.0.sql + updates/h3--3.6.0--3.6.1.sql + updates/h3--3.6.1--3.6.2.sql + updates/h3--3.6.2--3.6.3.sql + updates/h3--3.6.3--3.6.4.sql + updates/h3--3.6.4--3.6.5.sql + updates/h3--3.6.5--3.7.0.sql + updates/h3--3.7.0--3.7.1.sql + updates/h3--3.7.1--3.7.2.sql + updates/h3--3.7.2--4.0.0.sql + updates/h3--4.0.0--4.0.1.sql +) + +foreach(file ${INSTALL_SQL_FILES}) + file(READ ${file} CONTENTS) + file(APPEND ${EXT_SQL_FILE} "${CONTENTS}") +endforeach() + +install( + FILES ${EXT_SQL_FILE} ${UPDATE_SQL_FILES} + DESTINATION "${PostgreSQL_SHARE_DIR}/extension" + COMPONENT extension +) \ No newline at end of file diff --git a/h3/src/CMakeLists.txt b/h3/src/CMakeLists.txt new file mode 100644 index 00000000..614dd576 --- /dev/null +++ b/h3/src/CMakeLists.txt @@ -0,0 +1,61 @@ +include(FetchH3) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(SYSTEM ${PostgreSQL_INCLUDE_DIRS}) +message(STATUS "INCLUDING ${PostgreSQL_INCLUDE_DIRS}") + +if(UNIX) + set(CMAKE_C_STANDARD 11) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${PostgreSQL_LIBRARY_DIR}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L${PostgreSQL_LIBRARY_DIR}") + set(CMAKE_C_FLAGS "${PostgreSQL_C_FLAGS} ${CMAKE_C_FLAGS}") + set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${PostgreSQL_CPP_FLAGS}") +endif() + +if(WIN32) + string(APPEND CMAKE_MODULE_LINKER_FLAGS " ${PostgreSQL_PKG_LIBRARY_DIR}/postgres.lib") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " ws2_32.lib Version.lib") + set(CMAKE_C_FLAGS "-D_CRT_SECURE_NO_WARNINGS") + + message(CMAKE_MODULE_LINKER_FLAGS) +endif (WIN32) + +if(PG_LDFLAGS) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PG_LDFLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PG_LDFLAGS}") +endif() + +configure_file(extension.in.h extension.h) + +add_library(${PROJECT_NAME} MODULE + extension.h + edge.c + extension.c + hierarchy.c + indexing.c + inspection.c + miscellaneous.c + opclass_btree.c + opclass_hash.c + operators.c + regions.c + traversal.c + type.c + vertex.c + wkb_indexing.c + wkb_vect3.c + wkb.c +) + +target_link_libraries(${PROJECT_NAME} h3) + +set_target_properties(${PROJECT_NAME} PROPERTIES + OUTPUT_NAME ${EXT_NAME} + PREFIX "" +) + +install( + TARGETS ${PROJECT_NAME} + DESTINATION ${PostgreSQL_PKG_LIBRARY_DIR} + COMPONENT extension +) \ No newline at end of file diff --git a/h3/src/extension.in.h b/h3/src/extension.in.h index a85aea27..f680dede 100644 --- a/h3/src/extension.in.h +++ b/h3/src/extension.in.h @@ -32,7 +32,7 @@ typedef struct #define MAX_H3_RES 15 /* configure extension version in makefile */ -#define EXTVERSION "@EXTVERSION@" +#define EXTVERSION "@PROJECT_VERSION@" /* * DatumGetH3Index diff --git a/h3/test/CMakeLists.txt b/h3/test/CMakeLists.txt new file mode 100644 index 00000000..2ead2538 --- /dev/null +++ b/h3/test/CMakeLists.txt @@ -0,0 +1,42 @@ +find_program(PG_REGRESS pg_regress + HINTS + "${PostgreSQL_PKG_LIBRARY_DIR}/pgxs/src/test/regress/" + REQUIRED) + +set(TESTS + extension + hierarchy + indexing + inspection + miscellaneous + opclass_btree + opclass_hash + #postgis + #regions + traversal + type + edge +) + +add_custom_target(installcheck + COMMAND ${CMAKE_COMMAND} -E env + ${PG_REGRESS} + --temp-instance=${CMAKE_BINARY_DIR}/tmp + --user=user_regress + #--load-extension postgis + --load-extension h3 + --inputdir=${PROJECT_SOURCE_DIR}/h3/test + --outputdir=${CMAKE_BINARY_DIR} + ${TESTS} + USES_TERMINAL) + +add_test(NAME regress + COMMAND + ${PG_REGRESS} + --temp-instance=${CMAKE_BINARY_DIR}/tmp + --user=user_regress + #--load-extension postgis + --load-extension h3 + --inputdir=${PROJECT_SOURCE_DIR}/h3/test + --outputdir=${CMAKE_BINARY_DIR} + ${TESTS}) \ No newline at end of file diff --git a/h3_postgis/CMakeLists.txt b/h3_postgis/CMakeLists.txt new file mode 100644 index 00000000..dde94cda --- /dev/null +++ b/h3_postgis/CMakeLists.txt @@ -0,0 +1,21 @@ +set(EXT_NAME h3_postgis) + +add_subdirectory(sql) + +# if(BUILD_TESTING) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + add_test(NAME "ValidateUpgrade" + COMMAND pg_validate_extupgrade + --extname ${EXT_NAME} + --from 4.0.0 + --to 4.0.1) +endif() + +set(EXT_CONTROL_FILE ${EXT_NAME}.control) +configure_file(${EXT_CONTROL_FILE} ${EXT_CONTROL_FILE}) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXT_CONTROL_FILE} + DESTINATION "${PostgreSQL_SHARE_DIR}/extension" + COMPONENT extension +) \ No newline at end of file diff --git a/h3_postgis.control b/h3_postgis/h3_postgis.control similarity index 67% rename from h3_postgis.control rename to h3_postgis/h3_postgis.control index 50c94577..6737f55b 100644 --- a/h3_postgis.control +++ b/h3_postgis/h3_postgis.control @@ -1,4 +1,4 @@ comment = 'H3 PostGIS integration' -default_version = 'unreleased' +default_version = '@PROJECT_VERSION@' relocatable = true requires = 'h3, postgis' diff --git a/h3_postgis/pg_validate_extupgrade.toml b/h3_postgis/pg_validate_extupgrade.toml deleted file mode 100644 index 4494922d..00000000 --- a/h3_postgis/pg_validate_extupgrade.toml +++ /dev/null @@ -1,6 +0,0 @@ -extname = 'h3_postgis' -from = '4.0.0' -to = 'unreleased' -extra_queries = [ - "SELECT COUNT(*) FROM pg_class WHERE relname = 'dump_0'" -] diff --git a/h3_postgis/sql/CMakeLists.txt b/h3_postgis/sql/CMakeLists.txt new file mode 100644 index 00000000..94bdf180 --- /dev/null +++ b/h3_postgis/sql/CMakeLists.txt @@ -0,0 +1,25 @@ +set(EXT_SQL_FILE ${CMAKE_CURRENT_BINARY_DIR}/${EXT_NAME}--${PROJECT_VERSION}.sql) + +set(INSTALL_SQL_FILES + install/01-indexing.sql + install/05-regions.sql + install/20-casts.sql + install/99-deprecated.sql +) + +set(UPDATE_SQL_FILES + updates/h3_postgis--4.0.0.sql + updates/h3_postgis--4.0.0--4.0.1.sql + updates/h3_postgis--4.0.1--unreleased.sql +) + +foreach(file ${INSTALL_SQL_FILES}) + file(READ ${file} CONTENTS) + file(APPEND ${EXT_SQL_FILE} "${CONTENTS}") +endforeach() + +install( + FILES ${EXT_SQL_FILE} ${UPDATE_SQL_FILES} + DESTINATION "${PostgreSQL_SHARE_DIR}/extension" + COMPONENT extension +) \ No newline at end of file