Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: for Windows builds, defaults PROJ DLL to be just 'proj_${PROJ_MAJOR_VERSION}.dll' #4167

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions cmake/ProjUtilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions cmake/ProjVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
20 changes: 20 additions & 0 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 25 additions & 2 deletions src/lib_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -410,13 +409,37 @@ target_include_directories(proj INTERFACE
$<BUILD_INTERFACE:${PROJ_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

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
Expand Down