summaryrefslogtreecommitdiffstats
path: root/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
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')
-rw-r--r--cmake/FindWrapDBus1.cmake6
-rw-r--r--cmake/FindWrapSystemFreetype.cmake47
-rw-r--r--cmake/FindWrapSystemHarfbuzz.cmake50
-rw-r--r--cmake/FindWrapSystemPCRE2.cmake53
-rw-r--r--cmake/FindWrapSystemPNG.cmake46
-rw-r--r--cmake/FindZSTD.cmake3
6 files changed, 136 insertions, 69 deletions
diff --git a/cmake/FindWrapDBus1.cmake b/cmake/FindWrapDBus1.cmake
index ee856e1de5..e227d224e0 100644
--- a/cmake/FindWrapDBus1.cmake
+++ b/cmake/FindWrapDBus1.cmake
@@ -19,7 +19,7 @@ if(DEFINED ENV{PKG_CONFIG_LIBDIR})
set(__qt_dbus_pcl "$ENV{PKG_CONFIG_LIBDIR}")
endif()
-find_package(DBus1 QUIET)
+find_package(DBus1 ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} QUIET)
if(DEFINED __qt_dbus_pcd)
set(ENV{PKG_CONFIG_DIR} "${__qt_dbus_pcd}")
@@ -42,4 +42,6 @@ if(DBus1_FOUND)
endif()
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(WrapDBus1 DEFAULT_MSG WrapDBus1_FOUND)
+find_package_handle_standard_args(WrapDBus1 REQUIRED_VARS
+ DBus1_LIBRARY DBus1_INCLUDE_DIR WrapDBus1_FOUND
+ VERSION_VAR DBus1_VERSION)
diff --git a/cmake/FindWrapSystemFreetype.cmake b/cmake/FindWrapSystemFreetype.cmake
index 41c669b973..2cf6caca19 100644
--- a/cmake/FindWrapSystemFreetype.cmake
+++ b/cmake/FindWrapSystemFreetype.cmake
@@ -1,37 +1,50 @@
# 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 WrapSystemFreetype::WrapSystemFreetype)
- set(WrapSystemFreetype_FOUND ON)
+ set(WrapSystemFreetype_FOUND TRUE)
return()
endif()
-
-set(WrapSystemFreetype_FOUND OFF)
+set(WrapSystemFreetype_REQUIRED_VARS __freetype_found)
# Hunter has the package named freetype, but exports the Freetype::Freetype target as upstream
# First try the CONFIG package, and afterwards the MODULE if not found
-
-find_package(Freetype QUIET CONFIG NAMES Freetype freetype QUIET)
+find_package(Freetype ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION}
+ CONFIG NAMES Freetype freetype QUIET)
if(NOT Freetype_FOUND)
- find_package(Freetype QUIET MODULE)
+ find_package(Freetype ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} QUIET MODULE)
endif()
if(Freetype_FOUND)
# vcpkg defines a lower case target name, while upstream Find module defines a prefixed
# upper case name.
- set(potential_target_names Freetype::Freetype freetype)
- foreach(target_name ${potential_target_names})
- if(TARGET ${target_name})
- set(WrapSystemFreetype_FOUND ON)
- set(final_target_name ${target_name})
-
- add_library(WrapSystemFreetype::WrapSystemFreetype INTERFACE IMPORTED)
- target_link_libraries(WrapSystemFreetype::WrapSystemFreetype INTERFACE
- ${final_target_name})
-
+ set(__freetype_potential_target_names Freetype::Freetype freetype)
+ foreach(__freetype_potential_target_name ${__freetype_potential_target_names})
+ if(TARGET "${__freetype_potential_target_name}")
+ set(__freetype_target_name "${__freetype_potential_target_name}")
+ set(__freetype_found TRUE)
break()
endif()
endforeach()
endif()
+if(FREETYPE_LIBRARIES)
+ list(PREPEND WrapSystemFreetype_REQUIRED_VARS FREETYPE_LIBRARIES)
+endif()
+if(Freetype_VERSION)
+ set(WrapSystemFreetype_VERSION "${Freetype_VERSION}")
+elseif(FREETYPE_VERSION_STRING)
+ set(WrapSystemFreetype_VERSION "${FREETYPE_VERSION_STRING}")
+endif()
+
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(WrapSystemFreetype DEFAULT_MSG WrapSystemFreetype_FOUND)
+find_package_handle_standard_args(WrapSystemFreetype
+ REQUIRED_VARS ${WrapSystemFreetype_REQUIRED_VARS}
+ VERSION_VAR WrapSystemFreetype_VERSION)
+
+if(WrapSystemFreetype_FOUND)
+ add_library(WrapSystemFreetype::WrapSystemFreetype INTERFACE IMPORTED)
+ target_link_libraries(WrapSystemFreetype::WrapSystemFreetype
+ INTERFACE "${__freetype_target_name}")
+endif()
+unset(__freetype_target_name)
+unset(__freetype_found)
diff --git a/cmake/FindWrapSystemHarfbuzz.cmake b/cmake/FindWrapSystemHarfbuzz.cmake
index 087c1b070b..3cb44aa766 100644
--- a/cmake/FindWrapSystemHarfbuzz.cmake
+++ b/cmake/FindWrapSystemHarfbuzz.cmake
@@ -1,13 +1,12 @@
# 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 WrapSystemHarfbuzz::WrapSystemHarfbuzz)
- set(WrapSystemHarfbuzz_FOUND ON)
+ set(WrapSystemHarfbuzz_FOUND TRUE)
return()
endif()
+set(WrapSystemHarfbuzz_REQUIRED_VARS __harfbuzz_found)
-set(WrapSystemHarfbuzz_FOUND OFF)
-
-find_package(harfbuzz QUIET)
+find_package(harfbuzz ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} QUIET)
# Gentoo has some buggy version of a harfbuzz Config file. Check if include paths are valid.
set(__harfbuzz_target_name "harfbuzz::harfbuzz")
@@ -21,28 +20,43 @@ if(harfbuzz_FOUND AND TARGET "${__harfbuzz_target_name}")
break()
endif()
endforeach()
-endif()
-if(__harfbuzz_broken_config_file)
- find_package(PkgConfig QUIET)
+ set(__harfbuzz_found TRUE)
+ if(harfbuzz_VERSION)
+ set(WrapSystemHarfbuzz_VERSION "${harfbuzz_VERSION}")
+ endif()
+endif()
- pkg_check_modules(harfbuzz harfbuzz IMPORTED_TARGET)
- set(__harfbuzz_target_name "PkgConfig::harfbuzz")
+if(__harfbuzz_broken_config_file OR NOT __harfbuzz_found)
+ list(PREPEND WrapSystemHarfbuzz_REQUIRED_VARS HARFBUZZ_LIBRARIES HARFBUZZ_INCLUDE_DIRS)
- if (NOT TARGET "${__harfbuzz_target_name}")
- set(harfbuzz_FOUND 0)
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(PC_HARFBUZZ harfbuzz IMPORTED_TARGET)
+
+ find_path(HARFBUZZ_INCLUDE_DIRS
+ NAMES harfbuzz/hb.h
+ HINTS ${PC_HARFBUZZ_INCLUDEDIR})
+ find_library(HARFBUZZ_LIBRARIES
+ NAMES harfbuzz
+ HINTS ${PC_HARFBUZZ_LIBDIR})
+
+ set(__harfbuzz_target_name "PkgConfig::PC_HARFBUZZ")
+ set(__harfbuzz_found TRUE)
+ if(PC_HARFBUZZ_VERSION)
+ set(WrapSystemHarfbuzz_VERSION "${PC_HARFBUZZ_VERSION}")
endif()
endif()
-if(TARGET "${__harfbuzz_target_name}")
- set(WrapSystemHarfbuzz_FOUND ON)
-
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(WrapSystemHarfbuzz
+ REQUIRED_VARS ${WrapSystemHarfbuzz_REQUIRED_VARS}
+ VERSION_VAR WrapSystemHarfbuzz_VERSION)
+if(WrapSystemHarfbuzz_FOUND)
add_library(WrapSystemHarfbuzz::WrapSystemHarfbuzz INTERFACE IMPORTED)
- target_link_libraries(WrapSystemHarfbuzz::WrapSystemHarfbuzz INTERFACE ${__harfbuzz_target_name})
+ target_link_libraries(WrapSystemHarfbuzz::WrapSystemHarfbuzz
+ INTERFACE "${__harfbuzz_target_name}")
endif()
unset(__harfbuzz_target_name)
+unset(__harfbuzz_found)
unset(__harfbuzz_include_dir)
unset(__harfbuzz_broken_config_file)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(WrapSystemHarfbuzz DEFAULT_MSG WrapSystemHarfbuzz_FOUND)
diff --git a/cmake/FindWrapSystemPCRE2.cmake b/cmake/FindWrapSystemPCRE2.cmake
index 32966c2e30..6d8b471f88 100644
--- a/cmake/FindWrapSystemPCRE2.cmake
+++ b/cmake/FindWrapSystemPCRE2.cmake
@@ -2,25 +2,52 @@ if(TARGET WrapSystemPCRE2::WrapSystemPCRE2)
set(WrapSystemPCRE2_FOUND TRUE)
return()
endif()
+set(WrapSystemPCRE2_REQUIRED_VARS __pcre2_found)
-find_package(PCRE2 CONFIG QUIET)
+find_package(PCRE2 ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} CONFIG QUIET)
-if(PCRE2_FOUND AND TARGET PCRE2::pcre2-16)
+set(__pcre2_target_name "PCRE2::pcre2-16")
+if(PCRE2_FOUND AND TARGET "${__pcre2_target_name}")
# Hunter case.
- add_library(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE IMPORTED)
- target_link_libraries(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE PCRE2::pcre2-16)
- set(WrapSystemPCRE2_FOUND TRUE)
-else()
- find_library(PCRE2_LIBRARIES NAMES pcre2-16)
- find_path(PCRE2_INCLUDE_DIRS pcre2.h)
+ set(__pcre2_found TRUE)
+ if(PCRE2_VERSION)
+ set(WrapSystemPCRE2_VERSION "${PCRE2_VERSION}")
+ endif()
+endif()
+
+if(NOT __pcre2_found)
+ list(PREPEND WrapSystemPCRE2_REQUIRED_VARS PCRE2_LIBRARIES PCRE2_INCLUDE_DIRS)
+
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(PC_PCRE2 QUIET libpcre2-16)
+
+ find_path(PCRE2_INCLUDE_DIRS
+ NAMES pcre2.h
+ HINTS ${PC_PCRE2_INCLUDEDIR})
+ find_library(PCRE2_LIBRARIES
+ NAMES pcre2-16
+ HINTS ${PC_PCRE2_LIBDIR})
+ if(PC_PCRE2_VERSION)
+ set(WrapSystemPCRE2_VERSION "${PC_PCRE2_VERSION}")
+ endif()
if (PCRE2_LIBRARIES AND PCRE2_INCLUDE_DIRS)
- add_library(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE IMPORTED)
- target_link_libraries(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE ${PCRE2_LIBRARIES})
- target_include_directories(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE ${PCRE2_INCLUDE_DIRS})
- set(WrapSystemPCRE2_FOUND TRUE)
+ set(__pcre2_found TRUE)
endif()
endif()
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(WrapSystemPCRE2 DEFAULT_MSG WrapSystemPCRE2_FOUND)
+find_package_handle_standard_args(WrapSystemPCRE2
+ REQUIRED_VARS ${WrapSystemPCRE2_REQUIRED_VARS}
+ VERSION_VAR WrapSystemPCRE2_VERSION)
+if(WrapSystemPCRE2_FOUND)
+ add_library(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE IMPORTED)
+ if(TARGET "${__pcre2_target_name}")
+ target_link_libraries(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE "${__pcre2_target_name}")
+ else()
+ target_link_libraries(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE ${PCRE2_LIBRARIES})
+ target_include_directories(WrapSystemPCRE2::WrapSystemPCRE2 INTERFACE ${PCRE2_INCLUDE_DIRS})
+ endif()
+endif()
+unset(__pcre2_target_name)
+unset(__pcre2_found)
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)
diff --git a/cmake/FindZSTD.cmake b/cmake/FindZSTD.cmake
index 57fe8d1c3a..11515c8a31 100644
--- a/cmake/FindZSTD.cmake
+++ b/cmake/FindZSTD.cmake
@@ -32,7 +32,8 @@ find_library(ZSTD_LIBRARIES
)
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(ZSTD DEFAULT_MSG ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS)
+find_package_handle_standard_args(ZSTD REQUIRED_VARS ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS
+ VERSION_VAR PC_ZSTD_VERSION)
if(ZSTD_FOUND AND NOT TARGET ZSTD::ZSTD)
add_library(ZSTD::ZSTD UNKNOWN IMPORTED)