summaryrefslogtreecommitdiffstats
path: root/cmake/FindWrapSystemPNG.cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-08-04 17:24:17 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-08-10 11:56:54 +0200
commit3c52f8af9dbc125eee22115910c25510df8fede0 (patch)
tree3a3d7c60c53cb3c49b506ca721afcce249311c15 /cmake/FindWrapSystemPNG.cmake
parent7e7796fb006e616537a31112438232c124e8ce35 (diff)
CMake: pro2cmake: Specify library versions for 3rd party libraries
If certain 3rd party libraries have a version that's not suitable for Qt, the configure summary should say so, rather than use them and fail at build time. With the current situation, we have to duplicate the version information from the configure.json files in helper.py, by assigning the version number as an extra find_package variable. Rerunning configurejson2cmake then embeds this version info into the qt_find_package calls in configure.cmake. Some of the Find modules are rewritten to take the specified version into account when looking for the libraries. This involves moving around the code for creating a target, after calling find_package_handle_standard_args() so we know if a good enough version was found. Task-number: QTBUG-82917 Change-Id: I139748d8090e0630cda413362760034dc3483e11 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'cmake/FindWrapSystemPNG.cmake')
-rw-r--r--cmake/FindWrapSystemPNG.cmake46
1 files changed, 28 insertions, 18 deletions
diff --git a/cmake/FindWrapSystemPNG.cmake b/cmake/FindWrapSystemPNG.cmake
index dc42c731fb..372a064ff4 100644
--- a/cmake/FindWrapSystemPNG.cmake
+++ b/cmake/FindWrapSystemPNG.cmake
@@ -1,29 +1,39 @@
# We can't create the same interface imported target multiple times, CMake will complain if we do
# that. This can happen if the find_package call is done in multiple different subdirectories.
if(TARGET WrapSystemPNG::WrapSystemPNG)
- set(WrapSystemPNG_FOUND ON)
+ set(WrapSystemPNG_FOUND TRUE)
return()
endif()
+set(WrapSystemPNG_REQUIRED_VARS __png_found)
-set(WrapSystemPNG_FOUND OFF)
+find_package(PNG ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} QUIET)
-find_package(PNG QUIET)
-
-if(PNG_FOUND)
- set(potential_target_names PNG::PNG)
- foreach(target_name ${potential_target_names})
- if(TARGET ${target_name})
- set(WrapSystemPNG_FOUND ON)
- set(final_target_name ${target_name})
-
- add_library(WrapSystemPNG::WrapSystemPNG INTERFACE IMPORTED)
- target_link_libraries(WrapSystemPNG::WrapSystemPNG INTERFACE
- ${final_target_name})
+set(__png_target_name "PNG::PNG")
+if(PNG_FOUND AND TARGET "${__png_target_name}")
+ set(__png_found TRUE)
+ if(PNG_VERSION)
+ set(WrapSystemPNG_VERSION "${PNG_VERSION}")
+ endif()
+endif()
- break()
- endif()
- endforeach()
+if(PNG_LIBRARIES)
+ list(PREPEND WrapSystemPNG_REQUIRED_VARS PNG_LIBRARIES)
+endif()
+if(PNG_VERSION)
+ set(WrapSystemPNG_VERSION "${PNG_VERSION}")
+elseif(PNG_VERSION_STRING)
+ set(WrapSystemPNG_VERSION "${PNG_VERSION_STRING}")
endif()
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(WrapSystemPNG DEFAULT_MSG WrapSystemPNG_FOUND)
+find_package_handle_standard_args(WrapSystemPNG
+ REQUIRED_VARS ${WrapSystemPNG_REQUIRED_VARS}
+ VERSION_VAR WrapSystemPNG_VERSION)
+
+if(WrapSystemPNG_FOUND)
+ add_library(WrapSystemPNG::WrapSystemPNG INTERFACE IMPORTED)
+ target_link_libraries(WrapSystemPNG::WrapSystemPNG
+ INTERFACE "${__png_target_name}")
+endif()
+unset(__png_target_name)
+unset(__png_found)