diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-06-30 15:51:03 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-07-02 00:11:12 +0200 |
commit | a310319a0409c1faa1d2fc83c740e009f46dba84 (patch) | |
tree | 54ef8be430406d556ca93edf843a18ec49a8b64f /cmake/FindWrapSystemDoubleConversion.cmake | |
parent | af56a6f0cb61b45b13fe9efde12bc39b01030fc7 (diff) | |
download | qtbase-a310319a0409c1faa1d2fc83c740e009f46dba84.tar.gz |
CMake: Rewrite double-conversion find module
Rename FindWrapDoubleConversion.cmake into
FindWrapSystemDoubleConversion.cmake.
Merge contents of Finddouble-conversion.cmake into the one above.
This allows users to provide their own Finddouble-conversion.cmake
file (Conan can do it).
Don't mark the system package as required, because we have a bundled
one too.
Add link to upstream.
Make sure to show either Config file or library path when one is
found.
Pick-to: 6.2 6.3 6.4
Fixes: QTBUG-104541
Change-Id: I9ea2330697c6fc280328849ca11522291c4073d8
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Diffstat (limited to 'cmake/FindWrapSystemDoubleConversion.cmake')
-rw-r--r-- | cmake/FindWrapSystemDoubleConversion.cmake | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/cmake/FindWrapSystemDoubleConversion.cmake b/cmake/FindWrapSystemDoubleConversion.cmake new file mode 100644 index 0000000000..164e79ed54 --- /dev/null +++ b/cmake/FindWrapSystemDoubleConversion.cmake @@ -0,0 +1,77 @@ +# 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 WrapSystemDoubleConversion::WrapSystemDoubleConversion) + set(WrapSystemDoubleConversion_FOUND ON) + return() +endif() + +set(WrapSystemDoubleConversion_REQUIRED_VARS "__double_conversion_found") + +# Find either Config package or Find module. +# Upstream can be built either with CMake and then provides a Config file, or with Scons in which +# case there's no Config file. +# A Find module might be provided by a 3rd party, for example Conan might generate a Find module. +find_package(double-conversion ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} QUIET) +set(__double_conversion_target_name "double-conversion::double-conversion") +if(double-conversion_FOUND AND TARGET "${__double_conversion_target_name}") + set(__double_conversion_found TRUE) + # This ensures the Config file is shown in the fphsa message. + if(double-conversion_CONFIG) + list(PREPEND WrapSystemDoubleConversion_REQUIRED_VARS + double-conversion_CONFIG) + endif() +endif() + +if(NOT __double_conversion_found) + list(PREPEND WrapSystemDoubleConversion_REQUIRED_VARS + DOUBLE_CONVERSION_LIBRARY DOUBLE_CONVERSION_INCLUDE_DIR) + + find_path(DOUBLE_CONVERSION_INCLUDE_DIR + NAMES + double-conversion.h + PATH_SUFFIXES + double-conversion + ) + find_library(DOUBLE_CONVERSION_LIBRARY NAMES double-conversion) + include(SelectLibraryConfigurations) + select_library_configurations(DOUBLE_CONVERSION) + mark_as_advanced(DOUBLE_CONVERSION_INCLUDE_DIR DOUBLE_CONVERSION_LIBRARY) + + if(DOUBLE_CONVERSION_LIBRARIES AND DOUBLE_CONVERSION_INCLUDE_DIRS) + set(__double_conversion_found TRUE) + endif() +endif() + +include(FindPackageHandleStandardArgs) + +set(__double_conversion_fphsa_args "") +if(double-conversion_VERSION) + set(WrapSystemDoubleConversion_VERSION "${double-conversion_VERSION}") + list(APPEND __double_conversion_fphsa_args VERSION_VAR WrapSystemDoubleConversion_VERSION) +endif() + +find_package_handle_standard_args(WrapSystemDoubleConversion + REQUIRED_VARS ${WrapSystemDoubleConversion_REQUIRED_VARS} + ${__double_conversion_fphsa_args}) + +if(WrapSystemDoubleConversion_FOUND) + add_library(WrapSystemDoubleConversion::WrapSystemDoubleConversion INTERFACE IMPORTED) + if(TARGET "${__double_conversion_target_name}") + target_link_libraries(WrapSystemDoubleConversion::WrapSystemDoubleConversion + INTERFACE "${__double_conversion_target_name}") + else() + target_link_libraries(WrapSystemDoubleConversion::WrapSystemDoubleConversion + INTERFACE ${DOUBLE_CONVERSION_LIBRARIES}) + target_include_directories(WrapSystemDoubleConversion::WrapSystemDoubleConversion + INTERFACE ${DOUBLE_CONVERSION_INCLUDE_DIRS}) + endif() +endif() +unset(__double_conversion_target_name) +unset(__double_conversion_found) +unset(__double_conversion_fphsa_args) + +include(FeatureSummary) +set_package_properties(WrapSystemDoubleConversion PROPERTIES + URL "https://github.com/google/double-conversion" + DESCRIPTION "double-conversion library") + |