Skip to content

Commit d6311ab

Browse files
authored
Merge pull request #4167 from rouault/fix_4151
CMake: for Windows builds, defaults PROJ DLL to be just 'proj_${PROJ_MAJOR_VERSION}.dll'
2 parents eb12b9e + 872a8d1 commit d6311ab

File tree

4 files changed

+45
-41
lines changed

4 files changed

+45
-41
lines changed

cmake/ProjUtilities.cmake

-28
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,6 @@ function(print_variable NAME)
3434
message(STATUS "${NAME}${varpadding} = ${${NAME}}")
3535
endfunction()
3636

37-
#
38-
# Generates output name for given target depending on platform and version.
39-
# For instance, on Windows, dynamic link libraries get ABI version suffix
40-
# proj_X_Y.dll.
41-
#
42-
43-
function(proj_target_output_name TARGET_NAME OUTPUT_NAME)
44-
if(NOT DEFINED TARGET_NAME)
45-
message(SEND_ERROR "Error, the variable TARGET_NAME is not defined!")
46-
endif()
47-
48-
if(NOT DEFINED ${PROJECT_NAME}_VERSION)
49-
message(SEND_ERROR
50-
"Error, the variable ${${PROJECT_NAME}_VERSION} is not defined!")
51-
endif()
52-
53-
# On Windows, ABI version is specified using binary file name suffix.
54-
# On Unix, suffix is empty and SOVERSION is used instead.
55-
if(WIN32)
56-
string(LENGTH "${${PROJECT_NAME}_ABI_VERSION}" abilen)
57-
if(abilen GREATER 0)
58-
set(SUFFIX "_${${PROJECT_NAME}_ABI_VERSION}")
59-
endif()
60-
endif()
61-
62-
set(${OUTPUT_NAME} ${TARGET_NAME}${SUFFIX} PARENT_SCOPE)
63-
endfunction()
64-
6537
#
6638
# Configure a pkg-config file proj.pc
6739
# See also ProjInstallPath.cmake

cmake/ProjVersion.cmake

-11
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,5 @@ macro(proj_version)
3737
${${PROJECT_NAME}_VERSION_MINOR}.\
3838
${${PROJECT_NAME}_VERSION_PATCH}")
3939

40-
# Set ABI version string used to name binary output
41-
# On Windows, ABI version is specified using binary file name suffix.
42-
if(WIN32)
43-
set(${PROJECT_NAME}_ABI_VERSION
44-
"${${PROJECT_NAME}_VERSION_MAJOR}_\
45-
${${PROJECT_NAME}_VERSION_MINOR}")
46-
endif()
47-
4840
print_variable(${PROJECT_NAME}_VERSION)
49-
if(WIN32)
50-
print_variable(${PROJECT_NAME}_ABI_VERSION)
51-
endif()
5241
endmacro()

docs/source/install.rst

+20
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory.
287287
or by specifying ``--config Release`` with CMake
288288
multi-configuration build tools (see example below).
289289

290+
.. option:: PROJ_OUTPUT_NAME
291+
292+
.. versionadded:: 9.5
293+
294+
Sets the name of the PROJ library (excluding extension).
295+
This generally defaults to "proj", except on Windows, where this defaults to
296+
"proj_${PROJ_MAJOR_VERSION}" if APPEND_SOVERSION is OFF.
297+
298+
.. note::
299+
For PROJ >= 6.0 and up to 9.4.1, on Windows, this was hardcoded to
300+
"proj_${PROJ_MAJOR_VERSION}_${PROJ_MINOR_VERSION}".
301+
302+
.. option:: APPEND_SOVERSION=OFF
303+
304+
.. versionadded:: 9.5
305+
306+
This variable can be set to ON for MinGW builds where BUILD_SHARED_LIBS=ON,
307+
to add a "-${PROJ_SOVERSION}" suffix to the PROJ shared library name.
308+
When this variable is set, PROJ_OUTPUT_NAME defaults to "proj"
309+
290310
.. option:: CMAKE_C_COMPILER
291311

292312
C compiler. Ignored for some generators, such as Visual Studio.

src/lib_proj.cmake

+25-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ set(ALL_LIBPROJ_SOURCES
372372
set(ALL_LIBPROJ_HEADERS ${HEADERS_LIBPROJ})
373373

374374
# Configuration for the core target "proj"
375-
proj_target_output_name(proj PROJ_CORE_TARGET_OUTPUT_NAME)
376375

377376
add_library(proj
378377
${ALL_LIBPROJ_SOURCES}
@@ -410,13 +409,37 @@ target_include_directories(proj INTERFACE
410409
$<BUILD_INTERFACE:${PROJ_SOURCE_DIR}/include>
411410
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
412411

412+
if(WIN32)
413+
if (MINGW AND BUILD_SHARED_LIBS)
414+
option(APPEND_SOVERSION "Whether to include shared object version as a suffix in the name of the PROJ shared library name." OFF)
415+
endif()
416+
if(MINGW AND BUILD_SHARED_LIBS AND APPEND_SOVERSION)
417+
set(PROJ_OUTPUT_NAME "proj" CACHE STRING "Name of the PROJ library")
418+
else()
419+
# Detect major version update if re-using a CMake build directory where the
420+
# PROJ version major number has been updated in the meantime.
421+
math(EXPR PROJ_VERSION_MAJOR_MINUS_ONE "${PROJ_VERSION_MAJOR} - 1")
422+
if(DEFINED PROJ_OUTPUT_NAME AND PROJ_OUTPUT_NAME STREQUAL "proj_${PROJ_VERSION_MAJOR_MINUS_ONE}")
423+
message(WARNING "PROJ_OUTPUT_NAME was set to ${PROJ_OUTPUT_NAME}. Updating it to proj_${PROJ_VERSION_MAJOR}")
424+
unset(PROJ_OUTPUT_NAME CACHE)
425+
endif()
426+
set(PROJ_OUTPUT_NAME "proj_${PROJ_VERSION_MAJOR}" CACHE STRING "Name of the PROJ library")
427+
endif()
428+
else()
429+
set(PROJ_OUTPUT_NAME "proj" CACHE STRING "Name of the PROJ library")
430+
endif()
431+
432+
set_target_properties(proj PROPERTIES OUTPUT_NAME ${PROJ_OUTPUT_NAME})
433+
413434
if(WIN32)
414435
set_target_properties(proj
415436
PROPERTIES
416437
VERSION "${PROJ_VERSION}"
417-
OUTPUT_NAME "${PROJ_CORE_TARGET_OUTPUT_NAME}"
418438
ARCHIVE_OUTPUT_NAME proj
419439
CLEAN_DIRECT_OUTPUT 1)
440+
if (MINGW AND BUILD_SHARED_LIBS AND APPEND_SOVERSION)
441+
set_target_properties(proj PROPERTIES SUFFIX "-${PROJ_SOVERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}")
442+
endif()
420443
elseif(BUILD_FRAMEWORKS_AND_BUNDLE)
421444
set_target_properties(proj
422445
PROPERTIES

0 commit comments

Comments
 (0)