Skip to content

Commit

Permalink
Add version check for Alias target
Browse files Browse the repository at this point in the history
Alias target PNG::PNG is only added if the CMake version installed is
greater or equal 3.11. Also fixed version check for 3.12 to not use
GREATER_EQUAL that was not introduced until version 3.7.
  • Loading branch information
Thomas Schulz authored and ruslo committed Jul 10, 2019
1 parent b489d85 commit 60336b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
# For conditions of distribution and use, see the disclaimer
# and license in png.h

# ALIAS for imported target (see 'cmake/Config.cmake.in'):
# - https://cmake.org/cmake/help/latest/release/3.11.html#other
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)

Expand All @@ -44,8 +42,7 @@ set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
include(GNUInstallDirs)

# needed packages
if(${CMAKE_MAJOR_VERSION} GREATER 3 OR
(${CMAKE_MAJOR_VERSION} EQUAL 3 AND ${CMAKE_MINOR_VERSION} GREATER_EQUAL 12))
if(NOT CMAKE_VERSION VERSION_LESS 3.12)
# For CMake >= 3.12, find_package(<PackageName>) searches prefixes given by
# <PackageName>_ROOT CMake variable and <PackageName>_ROOT
# environment variable.
Expand Down
4 changes: 3 additions & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ find_dependency(ZLIB CONFIG)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

if(NOT TARGET PNG::PNG)
# ALIAS for imported target requires CMake >= 3.11:
# - https://cmake.org/cmake/help/latest/release/3.11.html#other
if(NOT CMAKE_VERSION VERSION_LESS 3.11 AND NOT TARGET PNG::PNG)
set_target_properties(
PNG::png
PROPERTIES
Expand Down

0 comments on commit 60336b5

Please sign in to comment.