-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
potential fixup: simplify MosquittoFind.cmake
- Loading branch information
1 parent
5c72f18
commit 02b1a32
Showing
1 changed file
with
11 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |