From 2a8df712a1275f9ad3cf8853998853cc8546baec Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Wed, 12 Aug 2026 18:53:08 +0000 Subject: [PATCH] Qt4: locate QtSingleApplication by fixed path, not find_path/find_library The qtsingleapplication-qt4 MacPorts port installs no CMake package config or module, and find_path()/find_library() weren't reliably locating it either. Since the Portfile will declare a dependency on qtsingleapplication-qt4, its presence under the Qt4 kit's own include/lib dirs can just be assumed, so address it directly: ${QT_INCLUDE_DIR}/QtSingleApplication/QtSingleApplication ${QT_LIBRARY_DIR}/libQtSingleApplication.dylib (matching the actual port layout), with an EXISTS check for a clear error message if that assumption ever doesn't hold. Also fixes the imported target's type: the port installs a shared .dylib, not a static .a, so it must be `SHARED IMPORTED` rather than `STATIC IMPORTED` -- the previous commit copied the STATIC form from the qt-solutions ExternalProject build, which does produce a .a. --- CMake/Includes/ProjectExternals.cmake | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/CMake/Includes/ProjectExternals.cmake b/CMake/Includes/ProjectExternals.cmake index 4f807e2..5d05afb 100644 --- a/CMake/Includes/ProjectExternals.cmake +++ b/CMake/Includes/ProjectExternals.cmake @@ -40,26 +40,28 @@ if(WITH_QT4) # qt-solutions' own CMakeLists.txt (CMakeLists_qt-solutions.cmake.in) # hardcodes Qt6, so under Qt4 use the prebuilt MacPorts # devel/qtsingleapplication-qt4 port instead of building it ourselves. - find_path(QTSINGLEAPPLICATION_INCLUDE_DIR - NAMES QtSingleApplication - PATH_SUFFIXES QtSingleApplication - HINTS ${QT_INCLUDE_DIR} - ) - find_library(QTSINGLEAPPLICATION_LIBRARY - NAMES QtSingleApplication - HINTS ${QT_LIBRARY_DIR} - ) - if(NOT QTSINGLEAPPLICATION_INCLUDE_DIR OR NOT QTSINGLEAPPLICATION_LIBRARY) - message(FATAL_ERROR "Could NOT find QtSingleApplication! Install it with e.g. 'port install qtsingleapplication-qt4'") + # That port ships no CMake package config/module of its own (and + # find_path()/find_library() don't reliably locate it either), so + # its files are addressed directly under the Qt4 kit's own + # include/lib dirs. The MacPorts Portfile is expected to declare a + # dependency on qtsingleapplication-qt4, so its presence there can + # be assumed rather than searched for. + set(QTSINGLEAPPLICATION_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtSingleApplication") + set(QTSINGLEAPPLICATION_LIBRARY "${QT_LIBRARY_DIR}/libQtSingleApplication.dylib") + if(NOT EXISTS "${QTSINGLEAPPLICATION_INCLUDE_DIR}/QtSingleApplication" OR NOT EXISTS "${QTSINGLEAPPLICATION_LIBRARY}") + message(FATAL_ERROR "QtSingleApplication not found under the Qt4 kit " + "(looked for ${QTSINGLEAPPLICATION_INCLUDE_DIR}/QtSingleApplication and ${QTSINGLEAPPLICATION_LIBRARY}); " + "install it with e.g. 'port install qtsingleapplication-qt4'") endif() message(STATUS "Library 'QtSingleApplication' found at ${QTSINGLEAPPLICATION_LIBRARY}") - add_library(qt-solutions::qtsingleapplication STATIC IMPORTED) + # The port installs a shared .dylib (not a static .a), unlike the + # qt-solutions ExternalProject build below. + add_library(qt-solutions::qtsingleapplication SHARED IMPORTED) set_target_properties(qt-solutions::qtsingleapplication PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${QTSINGLEAPPLICATION_INCLUDE_DIR}" IMPORTED_LOCATION "${QTSINGLEAPPLICATION_LIBRARY}" ) - mark_as_advanced(QTSINGLEAPPLICATION_INCLUDE_DIR QTSINGLEAPPLICATION_LIBRARY) else() include(ProjectExternals_qt-solutions) endif() -- 2.43.0