diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ae27cb..63c8ada6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,8 +20,9 @@ avoid adding features or APIs which do not map onto the ## [Unreleased] -## [4.5.0] - 2026-06-08 +- Use `PG_MODULE_MAGIC_EXT` macro in PostgreSQL 18 and later ([#203], [Andreas Karlsson]) +## [4.5.0] - 2026-06-08 ### Project @@ -356,7 +357,9 @@ avoid adding features or APIs which do not map onto the [#192]: https://github.com/postgis/h3-pg/issues/192 [#194]: https://github.com/postgis/h3-pg/pull/194 [#197]: https://github.com/postgis/h3-pg/pull/197 +[#203]: https://github.com/postgis/h3-pg/pull/203 [Abel Vázquez Montoro]: https://github.com/AbelVM +[Andreas Karlsson]: https://github.com/jeltz [Darafei Praliaskouski]: https://github.com/Komzpa [Eric Schoffstall]: https://github.com/yocontra [Paul Ramsey]: https://github.com/pramsey diff --git a/h3/src/init.c b/h3/src/init.c index 1cd9700e..8f4940af 100644 --- a/h3/src/init.c +++ b/h3/src/init.c @@ -21,10 +21,15 @@ #include // PG_MODULE_MAGIC +#include "config.h" #include "guc.h" /* see https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-DYNLOAD */ +#if POSTGRESQL_VERSION_MAJOR >= 18 +PG_MODULE_MAGIC_EXT(.name = "h3", .version = POSTGRESQL_H3_VERSION); +#else PG_MODULE_MAGIC; +#endif void _PG_init(void) diff --git a/h3_postgis/CMakeLists.txt b/h3_postgis/CMakeLists.txt index 0ec8e22f..855ec635 100644 --- a/h3_postgis/CMakeLists.txt +++ b/h3_postgis/CMakeLists.txt @@ -45,6 +45,15 @@ PostgreSQL_add_extension(postgresql_h3_postgis sql/updates/h3_postgis--4.5.0--unreleased.sql ) +# configure +configure_file(src/config.h.in src/config.h) + +# include +target_include_directories(postgresql_h3_postgis PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/src + src +) + # link target_link_libraries(postgresql_h3_postgis PRIVATE postgresql_h3_shared h3) target_include_directories(postgresql_h3_postgis PRIVATE ${H3_INTERNAL_INCLUDE_DIR}) diff --git a/h3_postgis/src/config.h.in b/h3_postgis/src/config.h.in new file mode 100644 index 00000000..fb4bb002 --- /dev/null +++ b/h3_postgis/src/config.h.in @@ -0,0 +1,22 @@ +/* + * Copyright 2026 Andreas Karlsson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PGH3_CONFIG_H +#define PGH3_CONFIG_H + +#define POSTGRESQL_PGH3_VERSION "@INSTALL_VERSION@" + +#endif /* PGH3_CONFIG_H */ diff --git a/h3_postgis/src/init.c b/h3_postgis/src/init.c index a41447d3..b1a6676e 100644 --- a/h3_postgis/src/init.c +++ b/h3_postgis/src/init.c @@ -18,5 +18,11 @@ #include // PG_MODULE_MAGIC +#include "config.h" + /* see https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-DYNLOAD */ +#if POSTGRESQL_VERSION_MAJOR >= 18 +PG_MODULE_MAGIC_EXT(.name = "h3_postgis", .version = POSTGRESQL_PGH3_VERSION); +#else PG_MODULE_MAGIC; +#endif