cmake: Allow overwriting the debug postfix of library filenames

Users may opt to change the debug suffix, e.g., from "d" to "_debug".

Rather than making CMAKE_DEBUG_POSTFIX a cache variable (which is
an antipattern in CMake), we introduce a new cache variable, named
PNG_DEBUG_POSTFIX.

Suggested-by: Diego Barrios Romero <eldruin@gmail.com>
This commit is contained in:
Cosmin Truta 2023-02-12 22:31:11 +02:00
parent efc96c9d59
commit e519af8b49

View File

@ -54,6 +54,13 @@ set(PNGLIB_SHARED_VERSION ${PNGLIB_ABI_VERSION}.${PNGLIB_REVISION}.${PNGLIB_SUBR
set(PNG_PREFIX "" set(PNG_PREFIX ""
CACHE STRING "Prefix to prepend to the API function names") CACHE STRING "Prefix to prepend to the API function names")
# Allow the users to override the postfix appended to debug library file names.
# Previously, we used to set CMAKE_DEBUG_POSTFIX globally. That variable should
# not be cached, however, because doing so would affect all projects processed
# after libpng, in unexpected and undesirable ways.
set(PNG_DEBUG_POSTFIX "d"
CACHE STRING "Postfix to append to library file names under the Debug configuration")
# Allow the users to import their own extra configuration settings. # Allow the users to import their own extra configuration settings.
set(DFA_XTRA "" set(DFA_XTRA ""
CACHE FILEPATH "File containing extra configuration settings") CACHE FILEPATH "File containing extra configuration settings")
@ -229,9 +236,6 @@ endif()
endif(PNG_HARDWARE_OPTIMIZATIONS) endif(PNG_HARDWARE_OPTIMIZATIONS)
# Distinguish between debug and release builds.
set(CMAKE_DEBUG_POSTFIX "d")
option(ld-version-script "Enable linker version script" ON) option(ld-version-script "Enable linker version script" ON)
if(ld-version-script AND NOT ANDROID AND NOT APPLE) if(ld-version-script AND NOT ANDROID AND NOT APPLE)
# Check if LD supports linker scripts. # Check if LD supports linker scripts.
@ -639,6 +643,7 @@ if(PNG_SHARED)
list(APPEND PNG_LIBRARY_TARGETS png_shared) list(APPEND PNG_LIBRARY_TARGETS png_shared)
set_target_properties(png_shared PROPERTIES set_target_properties(png_shared PROPERTIES
OUTPUT_NAME "${PNG_SHARED_OUTPUT_NAME}" OUTPUT_NAME "${PNG_SHARED_OUTPUT_NAME}"
DEBUG_POSTFIX "${PNG_DEBUG_POSTFIX}"
VERSION "${PNGLIB_SHARED_VERSION}" VERSION "${PNGLIB_SHARED_VERSION}"
SOVERSION "${PNGLIB_ABI_VERSION}") SOVERSION "${PNGLIB_ABI_VERSION}")
if(UNIX AND AWK) if(UNIX AND AWK)
@ -661,7 +666,8 @@ if(PNG_STATIC)
add_dependencies(png_static png_genfiles) add_dependencies(png_static png_genfiles)
list(APPEND PNG_LIBRARY_TARGETS png_static) list(APPEND PNG_LIBRARY_TARGETS png_static)
set_target_properties(png_static PROPERTIES set_target_properties(png_static PROPERTIES
OUTPUT_NAME "${PNG_STATIC_OUTPUT_NAME}") OUTPUT_NAME "${PNG_STATIC_OUTPUT_NAME}"
DEBUG_POSTFIX "${PNG_DEBUG_POSTFIX}")
target_link_libraries(png_static ${ZLIB_LIBRARIES} ${M_LIBRARY}) target_link_libraries(png_static ${ZLIB_LIBRARIES} ${M_LIBRARY})
endif() endif()