From 16c1dca933aa13c6a426b921b4a4135816d94b9c Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Sun, 28 Jan 2024 19:06:40 +0100 Subject: [PATCH] Detect utf8cpp by header if cmake config is not found (#1217) --- CMakeLists.txt | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 589920bc1..0e9df4a87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,18 +149,33 @@ if(TRACE_IN_RELEASE) endif() find_package(utf8cpp QUIET) -if(NOT utf8cpp_FOUND) - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/utfcpp/CMakeLists.txt) - add_subdirectory("3rdparty/utfcpp") - message(STATUS "Using utfcpp from ${utf8cpp_SOURCE_DIR}") +if(utf8cpp_FOUND) + message(STATUS "Using utfcpp ${utf8cpp_VERSION} from ${utf8cpp_CONFIG}") +else() + find_path(utf8cpp_INCLUDE_DIR NAMES utf8.h PATH_SUFFIXES utf8cpp + DOC "utf8cpp include directory") + mark_as_advanced(utf8cpp_INCLUDE_DIR) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(utf8cpp REQUIRED_VARS utf8cpp_INCLUDE_DIR) + if(utf8cpp_FOUND) + set(utf8cpp_INCLUDE_DIRS "${utf8cpp_INCLUDE_DIR}") + if(NOT TARGET utf8::cpp) + add_library(utf8::cpp INTERFACE IMPORTED) + set_target_properties(utf8::cpp PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${utf8cpp_INCLUDE_DIR}") + endif() + message(STATUS "Using utfcpp from ${utf8cpp_INCLUDE_DIR}") else() - message(FATAL_ERROR - "utfcpp not found. Either install package (probably utfcpp, utf8cpp, or libutfcpp-dev) " - "or fetch the git submodule using\n" - "git submodule update --init") + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/utfcpp/CMakeLists.txt) + add_subdirectory("3rdparty/utfcpp") + message(STATUS "Using utfcpp from ${utf8cpp_SOURCE_DIR}") + else() + message(FATAL_ERROR + "utfcpp not found. Either install package (probably utfcpp, utf8cpp, or libutfcpp-dev) " + "or fetch the git submodule using\n" + "git submodule update --init") + endif() endif() -else() - message(STATUS "Using utfcpp ${utf8cpp_VERSION} from ${utf8cpp_CONFIG}") endif() add_subdirectory(taglib)