[cmake] fallback detection for cJSON

This commit is contained in:
akallabeth 2024-05-14 20:56:53 +02:00
parent 8bdf92ca52
commit de49d32004
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
1 changed files with 66 additions and 42 deletions

View File

@ -190,10 +190,34 @@ option(WITH_JSON_DISABLED "Build without any JSON support" OFF)
CMAKE_DEPENDENT_OPTION(WITH_CJSON_REQUIRED "Build with cJSON (fail if not found)" OFF "NOT WITH_JSON_DISABLED" OFF)
CMAKE_DEPENDENT_OPTION(WITH_JSONC_REQUIRED "Build with JSON-C (fail if not found)" OFF "NOT WITH_JSON_DISABLED" OFF)
if (NOT WITH_JSON_DISABLED)
if (WITH_CJSON_REQUIRED)
find_package(cJSON REQUIRED)
else()
find_package(cJSON)
# Fallback detection:
# older ubuntu releases did not ship CMake or pkg-config files
# for cJSON. Be optimistic and try pkg-config and as last resort
# try manual detection
if (NOT cJSON_FOUND)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(CJSON libcjson)
endif()
if (NOT CJSON_LIBRARIES OR NOT CJSON_INCLUDE_DIRS)
find_path(CJSON_INCLUDE_DIRS
NAMES cjson/cJSON.h
)
find_library(CJSON_LIBRARIES
NAMES cjson
)
endif()
endif()
if (WITH_CJSON_REQUIRED)
if (NOT CJSON_FOUND)
message(FATAL_ERROR "cJSON was requested but not found")
endif()
else()
endif()
if (WITH_JSONC_REQUIRED)
find_package(JSONC REQUIRED)