From 02b1a32e76c6d251e91f63efee44a2213fa15019 Mon Sep 17 00:00:00 2001 From: Marco Thaller Date: Fri, 8 Nov 2024 10:43:53 +0100 Subject: [PATCH] potential fixup: simplify MosquittoFind.cmake --- cmake/FindMosquitto.cmake | 71 ++++++--------------------------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/cmake/FindMosquitto.cmake b/cmake/FindMosquitto.cmake index c28c1be..877a99b 100644 --- a/cmake/FindMosquitto.cmake +++ b/cmake/FindMosquitto.cmake @@ -1,61 +1,12 @@ -# FindMosquitto.cmake - Locate the Mosquitto library and headers -# This module defines the following variables: -# Mosquitto_FOUND - Set to TRUE if the library and headers are found -# Mosquitto_INCLUDE_DIRS - Path to the Mosquitto headers -# Mosquitto_LIBRARIES - Path to the Mosquitto library -# It also defines an imported target `Mosquitto::Mosquitto` if found - -# Check for platform-specific library name -if (WIN32) - set(MOSQUITTO_LIB_NAMES mosquitto) # On Windows, the library is usually named `mosquitto.lib` -else () - set(MOSQUITTO_LIB_NAMES mosquitto) # On Linux, it is usually named `libmosquitto.so` or `libmosquitto.a` -endif () - -# Locate the Mosquitto include directory -find_path(Mosquitto_INCLUDE_DIR - NAMES mosquitto.h - HINTS - # Custom hint paths for common installation locations on Linux - /usr/include - /usr/local/include - # Custom hint paths for Windows (assuming installation under Program Files or a common directory) - $ENV{PROGRAMFILES}/mosquitto/devel - #$ENV{PROGRAMFILES(X86)}/mosquitto/devel - PATH_SUFFIXES include - DOC "Path to the Mosquitto include directory" -) - -# Locate the Mosquitto library -find_library(Mosquitto_LIBRARY - NAMES ${MOSQUITTO_LIB_NAMES} - HINTS - # Custom hint paths for common library locations on Linux - /usr/lib - /usr/local/lib - # Custom hint paths for Windows - $ENV{PROGRAMFILES}/mosquitto/devel - #$ENV{PROGRAMFILES(X86)}/mosquitto/devel - PATH_SUFFIXES lib - DOC "Path to the Mosquitto library" -) - -# Use standard package handling to verify both library and include paths were found -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Mosquitto - REQUIRED_VARS Mosquitto_LIBRARY Mosquitto_INCLUDE_DIR - VERSION_VAR Mosquitto_VERSION -) - -# Define convenient variables for include directories and library paths -set(Mosquitto_INCLUDE_DIRS ${Mosquitto_INCLUDE_DIR}) -set(Mosquitto_LIBRARIES ${Mosquitto_LIBRARY}) - -# If Mosquitto is found, define an imported target for linking -if (Mosquitto_FOUND) - add_library(Mosquitto::Mosquitto UNKNOWN IMPORTED) - set_target_properties(Mosquitto::Mosquitto PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Mosquitto_INCLUDE_DIRS}" - IMPORTED_LOCATION "${Mosquitto_LIBRARIES}" - ) +find_library(MOSQUITTO_LIB mosquitto) +find_file(MOSQUITTO_HEADER mosquitto.h) +if(MOSQUITTO_LIB AND MOSQUITTO_HEADER) + cmake_path(GET MOSQUITTO_HEADER PARENT_PATH MOSQUITTO_INCLUDE_DIRECTORIES) + + add_library(Mosquitto::Mosquitto UNKNOWN IMPORTED) + set_target_properties(Mosquitto::Mosquitto PROPERTIES + IMPORTED_LOCATION "${MOSQUITTO_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${MOSQUITTO_INCLUDE_DIRECTORIES}" + ) + set(Mosquitto_FOUND TRUE) endif()