diff --git a/cmake/ProjUtilities.cmake b/cmake/ProjUtilities.cmake index 295e3c64e5..d9cf6f830c 100644 --- a/cmake/ProjUtilities.cmake +++ b/cmake/ProjUtilities.cmake @@ -34,34 +34,6 @@ function(print_variable NAME) message(STATUS "${NAME}${varpadding} = ${${NAME}}") endfunction() -# -# Generates output name for given target depending on platform and version. -# For instance, on Windows, dynamic link libraries get ABI version suffix -# proj_X_Y.dll. -# - -function(proj_target_output_name TARGET_NAME OUTPUT_NAME) - if(NOT DEFINED TARGET_NAME) - message(SEND_ERROR "Error, the variable TARGET_NAME is not defined!") - endif() - - if(NOT DEFINED ${PROJECT_NAME}_VERSION) - message(SEND_ERROR - "Error, the variable ${${PROJECT_NAME}_VERSION} is not defined!") - endif() - - # On Windows, ABI version is specified using binary file name suffix. - # On Unix, suffix is empty and SOVERSION is used instead. - if(WIN32) - string(LENGTH "${${PROJECT_NAME}_ABI_VERSION}" abilen) - if(abilen GREATER 0) - set(SUFFIX "_${${PROJECT_NAME}_ABI_VERSION}") - endif() - endif() - - set(${OUTPUT_NAME} ${TARGET_NAME}${SUFFIX} PARENT_SCOPE) -endfunction() - # # Configure a pkg-config file proj.pc # See also ProjInstallPath.cmake diff --git a/cmake/ProjVersion.cmake b/cmake/ProjVersion.cmake index deeaa2b474..363f118972 100644 --- a/cmake/ProjVersion.cmake +++ b/cmake/ProjVersion.cmake @@ -37,16 +37,5 @@ macro(proj_version) ${${PROJECT_NAME}_VERSION_MINOR}.\ ${${PROJECT_NAME}_VERSION_PATCH}") - # Set ABI version string used to name binary output - # On Windows, ABI version is specified using binary file name suffix. - if(WIN32) - set(${PROJECT_NAME}_ABI_VERSION - "${${PROJECT_NAME}_VERSION_MAJOR}_\ -${${PROJECT_NAME}_VERSION_MINOR}") - endif() - print_variable(${PROJECT_NAME}_VERSION) - if(WIN32) - print_variable(${PROJECT_NAME}_ABI_VERSION) - endif() endmacro() diff --git a/docs/source/install.rst b/docs/source/install.rst index 3eec8a8903..192f372ddd 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -287,6 +287,26 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory. or by specifying ``--config Release`` with CMake multi-configuration build tools (see example below). +.. option:: PROJ_OUTPUT_NAME + + .. versionadded:: 9.5 + + Sets the name of the PROJ library (excluding extension). + This generally defaults to "proj", except on Windows, where this defaults to + "proj_${PROJ_MAJOR_VERSION}" if APPEND_SOVERSION is OFF. + + .. note:: + For PROJ >= 6.0 and up to 9.4.1, on Windows, this was hardcoded to + "proj_${PROJ_MAJOR_VERSION}_${PROJ_MINOR_VERSION}". + +.. option:: APPEND_SOVERSION=OFF + + .. versionadded:: 9.5 + + This variable can be set to ON for MinGW builds where BUILD_SHARED_LIBS=ON, + to add a "-${PROJ_SOVERSION}" suffix to the PROJ shared library name. + When this variable is set, PROJ_OUTPUT_NAME defaults to "proj" + .. option:: CMAKE_C_COMPILER C compiler. Ignored for some generators, such as Visual Studio. diff --git a/src/lib_proj.cmake b/src/lib_proj.cmake index 4c631c648a..40b0d8c538 100644 --- a/src/lib_proj.cmake +++ b/src/lib_proj.cmake @@ -372,7 +372,6 @@ set(ALL_LIBPROJ_SOURCES set(ALL_LIBPROJ_HEADERS ${HEADERS_LIBPROJ}) # Configuration for the core target "proj" -proj_target_output_name(proj PROJ_CORE_TARGET_OUTPUT_NAME) add_library(proj ${ALL_LIBPROJ_SOURCES} @@ -410,13 +409,37 @@ target_include_directories(proj INTERFACE $ $) +if(WIN32) + if (MINGW AND BUILD_SHARED_LIBS) + option(APPEND_SOVERSION "Whether to include shared object version as a suffix in the name of the PROJ shared library name." OFF) + endif() + if(MINGW AND BUILD_SHARED_LIBS AND APPEND_SOVERSION) + set(PROJ_OUTPUT_NAME "proj" CACHE STRING "Name of the PROJ library") + else() + # Detect major version update if re-using a CMake build directory where the + # PROJ version major number has been updated in the meantime. + math(EXPR PROJ_VERSION_MAJOR_MINUS_ONE "${PROJ_VERSION_MAJOR} - 1") + if(DEFINED PROJ_OUTPUT_NAME AND PROJ_OUTPUT_NAME STREQUAL "proj_${PROJ_VERSION_MAJOR_MINUS_ONE}") + message(WARNING "PROJ_OUTPUT_NAME was set to ${PROJ_OUTPUT_NAME}. Updating it to proj_${PROJ_VERSION_MAJOR}") + unset(PROJ_OUTPUT_NAME CACHE) + endif() + set(PROJ_OUTPUT_NAME "proj_${PROJ_VERSION_MAJOR}" CACHE STRING "Name of the PROJ library") + endif() +else() + set(PROJ_OUTPUT_NAME "proj" CACHE STRING "Name of the PROJ library") +endif() + +set_target_properties(proj PROPERTIES OUTPUT_NAME ${PROJ_OUTPUT_NAME}) + if(WIN32) set_target_properties(proj PROPERTIES VERSION "${PROJ_VERSION}" - OUTPUT_NAME "${PROJ_CORE_TARGET_OUTPUT_NAME}" ARCHIVE_OUTPUT_NAME proj CLEAN_DIRECT_OUTPUT 1) + if (MINGW AND BUILD_SHARED_LIBS AND APPEND_SOVERSION) + set_target_properties(proj PROPERTIES SUFFIX "-${PROJ_SOVERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}") + endif() elseif(BUILD_FRAMEWORKS_AND_BUNDLE) set_target_properties(proj PROPERTIES