Skip to content

Commit

Permalink
Use CMake 3.5 features
Browse files Browse the repository at this point in the history
1. Set `cmake_minimum_required` to 3.5 (see https://cmake.org/cmake/help/latest/release/3.27.html#id17)
2. Specify the version of CMake project
3. `cmake_policy` is called implicitly by `cmake_minimum_required` (remove its call)
4. Use `CMAKE_INSTALL_BINDIR` and `CMAKE_INSTALL_INCLUDEDIR`
5. Use Zlib as a package (automatic linking of the library and add include directory)
6. Don't activate testing if it was not enabled
  • Loading branch information
theta682 committed Nov 1, 2023
1 parent e755fb7 commit 800ee3d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ endif()
option(PNG_BUILD_ZLIB "Custom zlib location, else find_package is used" OFF)
if(NOT PNG_BUILD_ZLIB)
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
endif()

if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU AND NOT EMSCRIPTEN)
Expand Down Expand Up @@ -625,7 +624,6 @@ if(PNG_DEBUG)
endif()

# Now build our targets.
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIRS})

# Initialize the list of libpng library targets.
set(PNG_LIBRARY_TARGETS "")
Expand Down Expand Up @@ -669,7 +667,12 @@ if(PNG_SHARED)
if(WIN32)
set_target_properties(png_shared PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
endif()
target_link_libraries(png_shared ${ZLIB_LIBRARIES} ${M_LIBRARY})
target_include_directories(png_shared
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(png_shared PRIVATE ZLIB::ZLIB ${M_LIBRARY})
endif()

if(PNG_STATIC)
Expand All @@ -679,7 +682,12 @@ if(PNG_STATIC)
set_target_properties(png_static PROPERTIES
OUTPUT_NAME "${PNG_STATIC_OUTPUT_NAME}"
DEBUG_POSTFIX "${PNG_DEBUG_POSTFIX}")
target_link_libraries(png_static ${ZLIB_LIBRARIES} ${M_LIBRARY})
target_include_directories(png_static
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(png_static PRIVATE ZLIB::ZLIB ${M_LIBRARY})
endif()

if(PNG_FRAMEWORK)
Expand All @@ -695,6 +703,11 @@ if(PNG_FRAMEWORK)
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
PUBLIC_HEADER "${libpng_public_hdrs}"
OUTPUT_NAME "png")
target_include_directories(png_framework
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(png_framework ${ZLIB_LIBRARIES} ${M_LIBRARY})
endif()

Expand Down Expand Up @@ -900,7 +913,7 @@ if(PNG_SHARED AND PNG_TOOLS)
set(PNG_BIN_TARGETS pngfix)

add_executable(png-fix-itxt ${png_fix_itxt_sources})
target_link_libraries(png-fix-itxt PRIVATE ${ZLIB_LIBRARIES} ${M_LIBRARY})
target_link_libraries(png-fix-itxt PRIVATE ZLIB::ZLIB ${M_LIBRARY})
list(APPEND PNG_BIN_TARGETS png-fix-itxt)
endif()

Expand Down

0 comments on commit 800ee3d

Please sign in to comment.