From 98c425fce7e1582630755505aebaaa2f46ac0119 Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Sun, 19 Nov 2023 11:12:36 +0100 Subject: [PATCH] Have matching SOVERSION for CMake and autotools * Avoid hard-coded SOVERSION=1, but determine from version info c:r:a * Some minor layout adaptions --- CMakeLists.txt | 102 +++++++++++++++++++------------------------- cmake/contrib.cmake | 22 +++++----- 2 files changed, 56 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd36e30..9a04569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,25 +1,11 @@ # Top-level CMakeLists.txt for the CMake-based build and test system # of the shapelib software. - -# Copyright (C) 2012-2013 Alan W. Irwin - -# See README.CMake - -# This file is free software; you can redistribute it and/or modify -# it under the terms of the GNU Library General Public License as published -# by the Free Software Foundation; version 2 of the License. # -# This file is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Library General Public License for more details. +# Copyright (C) 2012-2013, Alan W. Irwin # -# You should have received a copy of the GNU Library General Public License -# along with this file; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -# It is a fatal error if no working C compiler is available to build -# the shapelib library and utilities +# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +# +# See README.CMake # Version 3.7 or above of cmake is currently required for all platforms. cmake_minimum_required(VERSION 3.7) @@ -28,10 +14,11 @@ project(shapelib C CXX) message(STATUS "CMake version = ${CMAKE_VERSION}") message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}") -set (PROJECT_VERSION_MAJOR 1) -set (PROJECT_VERSION_MINOR 5) -set (PROJECT_VERSION_PATCH 0) -set (PROJECT_VERSION +set(PROJECT_VERSION_MAJOR 1) +set(PROJECT_VERSION_MINOR 5) +set(PROJECT_VERSION_PATCH 0) +set(shp_LIB_VERSIONINFO "3:0:1") +set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -45,15 +32,15 @@ option(BUILD_SHAPELIB_CONTRIB "Build utilities (from contrib)" ON) # Use rpath? if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # No rpath on Darwin. Setting it will only cause trouble. -else(CMAKE_SYSTEM_NAME STREQUAL "Darwin") +else() option(USE_RPATH "Use -rpath when linking libraries, executables" ON) -endif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") +endif() # In windows all created dlls are gathered in the dll directory # if you add this directory to your PATH all shared libraries are available if(BUILD_SHARED_LIBS AND WIN32 AND NOT CYGWIN) set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dll) -endif(BUILD_SHARED_LIBS AND WIN32 AND NOT CYGWIN) +endif() set(PACKAGE shp) @@ -83,12 +70,12 @@ file(RELATIVE_PATH RELATIVE_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} ) -message (STATUS "CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}") +message(STATUS "CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}") if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) # Set a default build type for single-configuration cmake generators # if no build type is set. - set (CMAKE_BUILD_TYPE Release) + set(CMAKE_BUILD_TYPE Release) endif() # Export build information to help other projects link installed @@ -104,7 +91,7 @@ install(EXPORT targets if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) -endif(MSVC) +endif() set(lib_SRC shpopen.c @@ -117,8 +104,7 @@ set(lib_SRC option(SHP_DROP_UNABLE_TO_OPEN_MSG "Drop \"unable to open\" error messages" ON) if(SHP_DROP_UNABLE_TO_OPEN_MSG) #define the SHP_DROP_UNABLE_TO_OPEN_MSG C macro for this source file. - set_source_files_properties(shpopen.c - PROPERTIES + set_source_files_properties(shpopen.c PROPERTIES COMPILE_DEFINITIONS SHP_DROP_UNABLE_TO_OPEN_MSG ) endif() @@ -136,34 +122,36 @@ if(NOT MSVC) endif() if(WIN32 AND NOT CYGWIN) - set_target_properties(${PACKAGE} - PROPERTIES + set_target_properties(${PACKAGE} PROPERTIES COMPILE_DEFINITIONS SHAPELIB_DLLEXPORT ) -endif(WIN32 AND NOT CYGWIN) +endif() if(UNIX) find_library(M_LIB m) if(M_LIB) target_link_libraries(${PACKAGE} -lm) endif() -endif(UNIX) +endif() -set(shp_SOVERSION 1) +# Convert shp_LIB_VERSIONINFO libtool version format into SOVERSION +# Convert from ":" separated into CMake list format using ";" +string(REPLACE ":" ";" shp_LIB_VERSIONINFO ${shp_LIB_VERSIONINFO}) +list(GET shp_LIB_VERSIONINFO 0 shp_LIB_VERSION_CURRENT) +list(GET shp_LIB_VERSIONINFO 2 shp_LIB_VERSION_AGE) +math(EXPR shp_SOVERSION "${shp_LIB_VERSION_CURRENT} - ${shp_LIB_VERSION_AGE}") set(shp_VERSION ${PROJECT_VERSION}) -set_target_properties(${PACKAGE} - PROPERTIES +set_target_properties(${PACKAGE} PROPERTIES SOVERSION ${shp_SOVERSION} VERSION ${shp_VERSION} INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}" ) if(USE_RPATH) - set_target_properties(${PACKAGE} - PROPERTIES + set_target_properties(${PACKAGE} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}" ) -endif(USE_RPATH) +endif() install(TARGETS ${PACKAGE} EXPORT targets @@ -196,9 +184,9 @@ find_program(BASH_EXECUTABLE bash) find_program(SED_EXECUTABLE sed) if(BASH_EXECUTABLE AND SED_EXECUTABLE) set(BUILD_TESTING ON CACHE BOOL "") -else(BASH_EXECUTABLE AND SED_EXECUTABLE) +else() message(STATUS "WARNING: sed or bash not available so disabling testing") -endif(BASH_EXECUTABLE AND SED_EXECUTABLE) +endif() # For the first series of tests, the user needs to have downloaded # from http://dl.maptools.org/dl/shapelib/shape_eg_data.zip, unpacked @@ -207,37 +195,37 @@ endif(BASH_EXECUTABLE AND SED_EXECUTABLE) if(BUILD_TESTING) if(EG_DATA) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?/u/www/projects/shapelib/eg_data?${EG_DATA}?\n") - else(EG_DATA) + else() file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sed "") message(STATUS "WARNING: EG_DATA:PATH not set to point to downloaded eg_data directory so the eg_data part of testing will be ignored.") - endif(EG_DATA) + endif() endif() -if (NOT MSVC) +if(NOT MSVC) # Set the run time path for shared libraries for non-Windows machines. - set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # See also INSTALL_RPATH property on the tools. - set (CMAKE_MACOSX_RPATH ON) - else () + set(CMAKE_MACOSX_RPATH ON) + else() # Use relative path so that package is relocatable - set (CMAKE_INSTALL_RPATH "\$ORIGIN/${RELATIVE_LIBDIR}") - endif () -endif () + set(CMAKE_INSTALL_RPATH "\$ORIGIN/${RELATIVE_LIBDIR}") + endif() +endif() foreach(executable ${executables}) add_executable(${executable} ${executable}.c) target_link_libraries(${executable} ${PACKAGE}) - if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # Ensure that the package is relocatable - set_target_properties (${TOOLS} PROPERTIES + set_target_properties(${TOOLS} PROPERTIES INSTALL_RPATH "@loader_path/${RELATIVE_LIBDIR}") - endif () + endif() if(BUILD_TESTING) get_target_property(${executable}_LOC ${executable} LOCATION) file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?\\./${executable}?${${executable}_LOC}?\n") endif() - if (NOT MSVC) + if(NOT MSVC) target_compile_options(${executable} PRIVATE -Wall -Wextra) endif() endforeach(executable ${executables}) @@ -288,7 +276,7 @@ if(BUILD_TESTING) NAME test1 COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test1.sh ) - endif(EG_DATA) + endif() # These tests correspond to everything in test2.sh add_test( NAME test2 diff --git a/cmake/contrib.cmake b/cmake/contrib.cmake index d834761..400066a 100644 --- a/cmake/contrib.cmake +++ b/cmake/contrib.cmake @@ -6,47 +6,47 @@ if(BUILD_SHAPELIB_CONTRIB) add_executable(dbfcat ${PROJECT_SOURCE_DIR}/contrib/dbfcat.c) target_link_libraries(dbfcat shp) set_target_properties(dbfcat PROPERTIES FOLDER "contrib") - + add_executable(dbfinfo ${PROJECT_SOURCE_DIR}/contrib/dbfinfo.c) target_link_libraries(dbfinfo shp) set_target_properties(dbfinfo PROPERTIES FOLDER "contrib") - + add_executable(shpcat ${PROJECT_SOURCE_DIR}/contrib/shpcat.c) target_link_libraries(shpcat shp) set_target_properties(shpcat PROPERTIES FOLDER "contrib") - + add_executable(shpdxf ${PROJECT_SOURCE_DIR}/contrib/shpdxf.c) target_link_libraries(shpdxf shp) set_target_properties(shpdxf PROPERTIES FOLDER "contrib") - + add_executable(shpfix ${PROJECT_SOURCE_DIR}/contrib/shpfix.c) target_link_libraries(shpfix shp) set_target_properties(shpfix PROPERTIES FOLDER "contrib") - + add_executable(shpsort ${PROJECT_SOURCE_DIR}/contrib/shpsort.c) target_link_libraries(shpsort shp) set_target_properties(shpsort PROPERTIES FOLDER "contrib") - + add_executable(Shape_PointInPoly ${PROJECT_SOURCE_DIR}/contrib/Shape_PointInPoly.cpp) target_link_libraries(Shape_PointInPoly shp) set_target_properties(Shape_PointInPoly PROPERTIES FOLDER "contrib" LINKER_LANGUAGE CXX) - + add_executable(shpcentrd ${PROJECT_SOURCE_DIR}/contrib/shpcentrd.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.h) target_link_libraries(shpcentrd shp) set_target_properties(shpcentrd PROPERTIES FOLDER "contrib") - + add_executable(shpdata ${PROJECT_SOURCE_DIR}/contrib/shpcentrd.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.h) target_link_libraries(shpdata shp) set_target_properties(shpdata PROPERTIES FOLDER "contrib") - + add_executable(shpinfo ${PROJECT_SOURCE_DIR}/contrib/shpcentrd.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.h) target_link_libraries(shpinfo shp) set_target_properties(shpinfo PROPERTIES FOLDER "contrib") - + add_executable(shpwkb ${PROJECT_SOURCE_DIR}/contrib/shpcentrd.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.c ${PROJECT_SOURCE_DIR}/contrib/shpgeo.h) target_link_libraries(shpwkb shp) set_target_properties(shpwkb PROPERTIES FOLDER "contrib") - + install( TARGETS csv2shp