Skip to content

Commit

Permalink
Building MEOS library (#223)
Browse files Browse the repository at this point in the history
* Split the codebase between MEOS generic code and PostgreSQL specific code

* Generalize MF-JSON format for all temporal types

* Remove support for PostGIS 2.5

* Remove support for PostgreSQL 11

* Fixes issues #206, #224 and #225
  • Loading branch information
estebanzimanyi committed Jul 18, 2022
1 parent 2a2d25f commit 7e950c3
Show file tree
Hide file tree
Showing 685 changed files with 44,035 additions and 60,250 deletions.
24 changes: 6 additions & 18 deletions .github/workflows/pgversion.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Main Build

# 4 * 1 * 2 + 1 (coverage) = 9 jobs are triggered
# Test for supported postgres version
# - except: MobilityDB does not support 9.6
# Test for supported PosgreSQL/PostGIS versions
# 3 (PosgreSQL) * 1 (PostGIS) * 2 (Linux) + 1 (coverage) = 7 jobs are triggered
# Allow manual trigger

on:
Expand All @@ -20,19 +19,11 @@ jobs:
strategy:
fail-fast: false
matrix:
psql: [11,12,13]
postgis: [2.5]
psql: [12,13,14]
postgis: [3]
os: [ubuntu-latest, ubuntu-18.04]
coverage: [0]
include:
- psql: 12
postgis: 3
os: ubuntu-latest
coverage: 0
- psql: 13
postgis: 3
os: ubuntu-latest
coverage: 0
- psql: 14
postgis: 3
os: ubuntu-latest
Expand Down Expand Up @@ -109,11 +100,8 @@ jobs:
if: matrix.coverage == '1'
run: |
cd build
# Previous coverage before embeding liblwgeom
# lcov --capture --directory . --output-file=lcov.info
# Selecting the coverage information from only the /src directory
lcov --capture --directory . --output-file=lcov_temp.info
lcov --extract lcov_temp.info */MobilityDB/src/* --output-file=lcov.info
# Excluding MEOS-specific and other miscellaneous files
lcov --capture --directory . --exclude *_meos.c --exclude */geo_constructors.c --exclude */tpoint_datagen.c --include */MobilityDB/meos/src/* --include */MobilityDB/mobilitydb/src/* --output-file=lcov.info
- name: Coveralls
if: matrix.coverage == '1'
Expand Down
243 changes: 59 additions & 184 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
# Minimum version supporting fixtures
#-------------------------------------
# MobilityDB Main CMake file
#-------------------------------------

# Minimum Cmake version supporting fixtures
cmake_minimum_required(VERSION 3.7)

# Disallow in-source builds
if( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed.
Please make a new directory (called a build directory) and run CMake from there.
You may need to remove 'CMakeCache.txt' and 'CMakeFiles/'.")
endif()

# Specify search path for CMake modules to be loaded
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(CheckSymbolExists)

#-------------------------------------
# MobilityDB definitions
#-------------------------------------

# Option used for building the MEOS library
# Option for including network points
option(MEOS
"Set ON|OFF (default=OFF) to build the (Mobility Engine Open Source) MEOS library
"Set MEOS (default=OFF) to build the MEOS library instead of the MobilityDB
PostgreSQL extension
"
OFF
)

# Get the major/minor/micro versions from the text file
if(NOT MEOS)
# Option for including network points
option(NPOINT
"Set ON|OFF (default=ON) to include network points
"
ON
)
else()
# Set NPOINT option for excluding support for network points, which require a
# table named `ways` containing the geometries of the road network
set(NPOINT OFF)
endif()

if(NPOINT)
message(STATUS "Including network points")
add_definitions(-DNPOINT=1)
else()
message(STATUS "Excluding network points")
add_definitions(-DNPOINT=0)
endif()

# Get the MobilityDB major/minor/micro versions from the text file
file(READ mobdb_version.txt ver)
string(REGEX MATCH "MOBILITYDB_MAJOR_VERSION=([0-9]+)" _ ${ver})
set(MOBILITYDB_MAJOR_VERSION ${CMAKE_MATCH_1})
Expand All @@ -28,59 +60,48 @@ set(MOBILITYDB_MICRO_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "MOBILITYDB_MICRO_VERSION=[0-9]+(beta?[0-9]+)" _ ${ver})
set(PROJECT_VERSION_DEV ${CMAKE_MATCH_1})

# Set the name (either MEOS or MobilityDB) and version of the project
if(MEOS)
message(STATUS "Building the MEOS library")
project(MEOS VERSION ${MOBILITYDB_MAJOR_VERSION}.${MOBILITYDB_MINOR_VERSION}.${MOBILITYDB_MICRO_VERSION})
add_definitions(-DMEOS=1)
else()
message(STATUS "Building MobilityDB")
project(MobilityDB VERSION ${MOBILITYDB_MAJOR_VERSION}.${MOBILITYDB_MINOR_VERSION}.${MOBILITYDB_MICRO_VERSION})
endif()
# Set the project name and project version
project(MobilityDB VERSION ${MOBILITYDB_MAJOR_VERSION}.${MOBILITYDB_MINOR_VERSION}.${MOBILITYDB_MICRO_VERSION})
message(STATUS "Building MobilityDB version ${PROJECT_VERSION}")
# Enable testing, must follow project() call above
include(CTest)
enable_testing()

set(MOBILITYDB_VERSION "${PROJECT_VERSION}")
set(MOBILITYDB_VERSION_STR "${CMAKE_PROJECT_NAME} ${PROJECT_VERSION}${PROJECT_VERSION_DEV}")
add_definitions(-DMOBILITYDB_VERSION_STR="${MOBILITYDB_VERSION_STR}")

# Set the version and name of the library
set(MOBILITYDB_LIB_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(MOBILITYDB_LIB_NAME "${CMAKE_PROJECT_NAME}-${MOBILITYDB_LIB_VERSION}")

# Set the name of the PostgreSQL extension and of the internal extension used for testing
string(TOLOWER ${CMAKE_PROJECT_NAME} MOBILITYDB_LOWERCASE_NAME)
set(MOBILITYDB_EXTENSION_FILE "${MOBILITYDB_LOWERCASE_NAME}--${PROJECT_VERSION}.sql")
set(MOBILITYDB_TEST_EXTENSION_FILE "${CMAKE_BINARY_DIR}/test_${MOBILITYDB_EXTENSION_FILE}")

# Comment out code used for debugging purposes so it is not concerned by the coverage
if(CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
add_definitions(-DDEBUG_BUILD)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CheckSymbolExists)

include(CTest)
enable_testing()

#-------------------------------------
# Set compiler flags
#-------------------------------------

# Generate position-independent code (PIC)
include(CheckCCompilerFlag)
if(NOT WIN32)
CHECK_C_COMPILER_FLAG("-fPIC" C_COMPILER_SUPPORTS_FPIC)
if(C_COMPILER_SUPPORTS_FPIC)
message(STATUS "Compiling into position-independent code (PIC)")
add_definitions(-fPIC)
endif()
endif()

# FFSL functions for finding the first (least significant) bit
check_symbol_exists(ffsl "string.h" HAS_FFSL)
if(NOT HAS_FFSL)
add_definitions(-DNO_FFSL)
endif()

# add_definitions(-Wall -Wextra -std=gnu1x -Wno-unused-parameter)
# MobilityDB compiler flags
add_definitions(-Wall -Wextra -std=gnu1x -Wunused-parameter)
# add_definitions(-Wall -Wextra -std=gnu1x -Wno-unused-parameter)

# Code coverage
if(CMAKE_COMPILER_IS_GNUCC)
if(WITH_COVERAGE)
message(STATUS "Generating code coverage")
Expand All @@ -89,56 +110,11 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif()
endif()

# Disable compiler optimizations for debugging
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")

#-------------------------------------
# Verify PostgreSQL Version
#-------------------------------------

if(NOT MEOS)
set(PG_MIN_MAJOR_VERSION "11")
set(PG_MAX_MAJOR_VERSION "14")
find_package(POSTGRESQL ${PG_MIN_MAJOR_VERSION} REQUIRED)
if(NOT POSTGRES_VERSION VERSION_LESS PG_MAX_MAJOR_VERSION)
message(FATAL_ERROR "Not supporting PostgreSQL ${POSTGRESQL_VERSION}")
endif()
math(EXPR POSTGIS_PGSQL_VERSION "${POSTGRESQL_VERSION_MAJOR} * 10 + ${POSTGRESQL_VERSION_MINOR}")
else()
set(POSTGRESQL_VERSION_STRING "PostgreSQL 14.2")
set(POSTGRESQL_VERSION_NUMBER "140200")
endif()
add_definitions(-DPOSTGRESQL_VERSION_STRING="${POSTGRESQL_VERSION_STRING}")
add_definitions(-DPOSTGRESQL_VERSION_NUMBER=${POSTGRESQL_VERSION_NUMBER})

if(MEOS)
message(STATUS "Building MEOS: Including embedded PostgreSQL files")
include_directories("postgres")
add_subdirectory("postgres")
else()
include_directories(SYSTEM ${POSTGRESQL_INCLUDE_DIR})
if(WIN32)
include_directories(SYSTEM ${POSTGRESQL_INCLUDE_DIR}/port/win32)
if(MSVC)
include_directories(SYSTEM ${POSTGRESQL_INCLUDE_DIR}/port/win32_msvc/)
endif()
link_directories(${POSTGRESQL_LIBRARIES})
link_libraries(postgres)
endif()
endif()

#-------------------------------------
# Verify PostGIS Version
#-------------------------------------

if(NOT MEOS)
find_package(POSTGIS REQUIRED)
else()
set(POSTGIS_VERSION_STR "PostGIS 3.2.1")
set(POSTGIS_VERSION_NUMBER "30201")
endif()
add_definitions(-DPOSTGIS_VERSION_STR="${POSTGIS_VERSION_STR}")
add_definitions(-DPOSTGIS_VERSION_NUMBER=${POSTGIS_VERSION_NUMBER})

# Check machine architecture: big endian vs. little endian
# Needed for WKB support in MobilityDB and PostGIS (file postgis_config.h.in)
include(TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
Expand All @@ -151,116 +127,15 @@ else()
set(DEF_WORDS_BIGENDIAN "#undef")
endif()

#--------------------------------
# Other dependencies
#--------------------------------

if(NOT MEOS)
# Link liblwgeom library for PostGIS 2.5.5
if(POSTGIS_VERSION_NUMBER LESS 30000)
find_package(LWGEOM REQUIRED)
include_directories(SYSTEM ${LWGEOM_INCLUDE_DIRS})
endif()

find_package(GSL REQUIRED)
include_directories(SYSTEM ${GSL_INCLUDE_DIRS})
endif()

find_package(PROJ REQUIRED)
include_directories(SYSTEM ${PROJ_INCLUDE_DIRS})
math(EXPR POSTGIS_PROJ_VERSION "${PROJ_VERSION_MAJOR} * 10 + ${PROJ_VERSION_MINOR}")
message(STATUS "POSTGIS_PROJ_VERSION: ${POSTGIS_PROJ_VERSION}")

find_package(GEOS REQUIRED)
include_directories(SYSTEM ${GEOS_INCLUDE_DIR})
math(EXPR POSTGIS_GEOS_VERSION "${GEOS_VERSION_MAJOR} * 10 + ${GEOS_VERSION_MINOR}")
message(STATUS "POSTGIS_GEOS_VERSION: ${POSTGIS_GEOS_VERSION}")

find_package(JSON-C REQUIRED)
include_directories(SYSTEM ${JSON-C_INCLUDE_DIRS})

#--------------------------------
# Belongs to MobilityDB
# Must go before target_link_libraries

# Embed liblwgeom library for PostGIS 3
if(POSTGIS_VERSION_NUMBER GREATER_EQUAL 30000)
configure_file(postgis/postgis_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/postgis/postgis_config.h)
include_directories("postgis/liblwgeom")
if(NOT MEOS)
include_directories("postgis/libpgcommon")
endif()
include_directories("postgis")
add_subdirectory("postgis")
endif()

include_directories("include")
add_subdirectory("src")

# Build the library
set(PROJECT_OBJECTS "$<TARGET_OBJECTS:general>")
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:point>")
if(MEOS)
message(STATUS "Building MEOS: Network points not included")
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:common>")
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:port>")
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:timezone>")
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:utils>")
else()
message(STATUS "Building MobilityDB: Including network points")
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:npoint>")
endif()
if(POSTGIS_VERSION_NUMBER GREATER_EQUAL 30000)
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:liblwgeom>")
if(MEOS)
message(STATUS "Building MEOS: postgis/libpgcommon not included")
else()
message(STATUS "Building MobilityDB: Including postgis/libpgcommon")
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:libpgcommon>")
endif()
set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:ryu>")
endif()
add_library(${MOBILITYDB_LIB_NAME} MODULE ${PROJECT_OBJECTS})

if(APPLE)
set_target_properties(${MOBILITYDB_LIB_NAME} PROPERTIES
LINK_FLAGS "-Wl,-undefined,dynamic_lookup -bundle_loader /usr/local/bin/postgres")
endif()

#--------------------------------
# Specify libraries to link
#--------------------------------

target_link_libraries(${MOBILITYDB_LIB_NAME} ${JSON-C_LIBRARIES})
if(MEOS)
target_link_libraries(${MOBILITYDB_LIB_NAME} ${GEOS_LIBRARY})
target_link_libraries(${MOBILITYDB_LIB_NAME} ${PROJ_LIBRARIES})
else()
if(POSTGIS_VERSION_NUMBER LESS 30000)
target_link_libraries(${MOBILITYDB_LIB_NAME} ${LWGEOM_LIBRARIES})
endif()
target_link_libraries(${MOBILITYDB_LIB_NAME} ${GSL_LIBRARY})
target_link_libraries(${MOBILITYDB_LIB_NAME} ${GSL_CBLAS_LIBRARY})
endif()
#-------------------------------------
# Build either MobilityDB or MEOS
#-------------------------------------

#--------------------------------
# Belongs to MobilityDB
#--------------------------------

if(MEOS)
message(STATUS "Building MEOS: SQL definitions and tests not included")
install(TARGETS ${MOBILITYDB_LIB_NAME} DESTINATION "/usr/local/lib")
message(STATUS "Building MEOS: Destination library is '/usr/local/lib'")
add_subdirectory(meos)
else()
message(STATUS "Building MobilityDB: Including SQL definitions and tests")
add_subdirectory(sql)
add_subdirectory(test)
add_custom_target(sqlscript ALL DEPENDS ${CMAKE_BINARY_DIR}/${MOBILITYDB_EXTENSION_FILE})
add_custom_target(control ALL DEPENDS ${CMAKE_BINARY_DIR}/mobilitydb.control)
install(
FILES "${CMAKE_BINARY_DIR}/mobilitydb.control" "${CMAKE_BINARY_DIR}/${MOBILITYDB_EXTENSION_FILE}"
DESTINATION "${POSTGRESQL_SHARE_DIR}/extension")
install(TARGETS ${MOBILITYDB_LIB_NAME} DESTINATION "${POSTGRESQL_DYNLIB_DIR}")
add_subdirectory(mobilitydb)
endif()

#-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions cmake/FindPOSTGIS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ else()
endif()
endif()

message(STATUS "Looking for postgis.control file in ${POSTGRESQL_SHARE_DIR}/extension")
find_file(POSTGIS_CONTROL postgis.control
PATHS "${POSTGRESQL_SHARE_DIR}/extension")

Expand Down
2 changes: 2 additions & 0 deletions cmake/FindPROJ.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ find_package_handle_standard_args(PROJ
FAIL_MESSAGE "Could NOT find proj")

if (PROJ_FOUND)
MESSAGE(STATUS "Found PROJ: ${PROJ_LIBRARIES} (${PROJ_VERSION_MAJOR}.${PROJ_VERSION_MINOR}.${PROJ_VERSION_PATCH})")
MESSAGE(STATUS "PROJ_INCLUDE_DIRS: ${PROJ_INCLUDE_DIRS}")
mark_as_advanced(PROJ_INCLUDE_DIRS PROJ_LIBRARIES)
endif()
5 changes: 1 addition & 4 deletions doc/es/introduction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ git clone --branch develop https://github.com/MobilityDB/MobilityDB
shared_preload_libraries = 'postgis-3'
max_locks_per_transaction = 128
</programlisting>
<para>
Puede reemplazar <varname>postgis-2.5</varname> arriba si desea usar PostGIS 2.5.
</para>

<para>
Si no carga previamente la biblioteca PostGIS, no podrá cargar la biblioteca MobilityDB y obtendrá un mensaje de error como el siguiente:
Expand Down Expand Up @@ -226,7 +223,7 @@ CREATE EXTENSION mobilitydb CASCADE;
<listitem><para>Compilador GNU C (<filename>gcc</filename>). Se pueden usar algunos otros compiladores ANSI C, pero pueden causar problemas al compilar algunas dependencias como PostGIS.</para></listitem>
<listitem><para>GNU Make (<filename>gmake</filename> o <filename>make</filename>) versión 3.1 o superior. Para muchos sistemas, GNU make es la versión predeterminada de make. Verifique la versión invocando <filename>make -v</filename>.</para></listitem>
<listitem><para>PostgreSQL versión 11 o superior. PostgreSQL está disponible en <ulink url="http://www.postgresql.org">http://www.postgresql.org</ulink>.</para></listitem>
<listitem><para>PostGIS versión 2.5 o superior. PostGIS está disponible en <ulink url="https://postgis.net/">https://postgis.net/</ulink>.</para></listitem>
<listitem><para>PostGIS versión 3 o superior. PostGIS está disponible en <ulink url="https://postgis.net/">https://postgis.net/</ulink>.</para></listitem>
<listitem><para>Biblioteca científica GNU (GSL). GSL está disponible en <ulink url="https://www.gnu.org/software/gsl/">https://www.gnu.org/software/gsl/</ulink>. GSL se utiliza para los generadores de números aleatorios.</para></listitem>
</itemizedlist>
<para>
Expand Down

0 comments on commit 7e950c3

Please sign in to comment.