mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[winpr,utils] fix cJSON detection
* pkg-config sets CJSON_FOUND, check for that instead of the paths, which might be unset or set to <var>-NOTFOUND * move detection to own file. find_package targets are meant to be used in same directory or below, but we define the WinPR target one above, so include it in parent
This commit is contained in:
49
cmake/JsonDetect.cmake
Normal file
49
cmake/JsonDetect.cmake
Normal file
@@ -0,0 +1,49 @@
|
||||
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)
|
||||
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_FOUND)
|
||||
find_path(CJSON_INCLUDE_DIRS
|
||||
NAMES cjson/cJSON.h
|
||||
)
|
||||
find_library(CJSON_LIBRARIES
|
||||
NAMES cjson
|
||||
)
|
||||
if (NOT "${CJSON_LIBRARIES}" EQUAL "CJSON_LIBRARIES-NOTFOUND" AND NOT "${CJSON_INCLUDE_DIRS}" EQUAL "CJSON_INCLUDE_DIRS-NOTFOUND")
|
||||
set(CJSON_FOUND ON)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WITH_CJSON_REQUIRED)
|
||||
if (NOT CJSON_FOUND)
|
||||
message(FATAL_ERROR "cJSON was requested but not found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WITH_JSONC_REQUIRED)
|
||||
find_package(JSONC REQUIRED)
|
||||
else()
|
||||
find_package(JSONC)
|
||||
endif()
|
||||
|
||||
if (NOT JSONC_FOUND AND NOT CJSON_FOUND)
|
||||
set(WITH_WINPR_JSON OFF CACHE INTERNAL "internal")
|
||||
message("compiling without JSON support. Install cJSON or json-c to enable")
|
||||
endif()
|
||||
else()
|
||||
set(WITH_WINPR_JSON OFF CACHE INTERNAL "internal")
|
||||
message("forced compile without JSON support. Set -DWITH_JSON_DISABLED=OFF to enable compile time detection")
|
||||
endif()
|
||||
@@ -16,6 +16,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
include(CheckFunctionExists)
|
||||
include(JsonDetect)
|
||||
|
||||
set(WINPR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(WINPR_SRCS "")
|
||||
|
||||
@@ -186,47 +186,8 @@ if (WINPR_HAVE_UNWIND_H)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
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)
|
||||
include(JsonDetect)
|
||||
if (NOT WITH_JSON_DISABLED)
|
||||
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
|
||||
)
|
||||
if (NOT "${CJSON_LIBRARIES}" EQUAL "CJSON_LIBRARIES-NOTFOUND" AND NOT "${CJSON_INCLUDE_DIRS}" EQUAL "CJSON_INCLUDE_DIRS-NOTFOUND")
|
||||
set(CJSON_FOUND ON)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WITH_CJSON_REQUIRED)
|
||||
if (NOT CJSON_FOUND)
|
||||
message(FATAL_ERROR "cJSON was requested but not found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WITH_JSONC_REQUIRED)
|
||||
find_package(JSONC REQUIRED)
|
||||
else()
|
||||
find_package(JSONC)
|
||||
endif()
|
||||
|
||||
if (JSONC_FOUND AND NOT WITH_CJSON_REQUIRED)
|
||||
winpr_library_add_private(${JSONC_LIBRARIES})
|
||||
winpr_include_directory_add(${JSONC_INCLUDE_DIRS})
|
||||
@@ -237,13 +198,7 @@ if (NOT WITH_JSON_DISABLED)
|
||||
winpr_include_directory_add(${CJSON_INCLUDE_DIRS})
|
||||
winpr_definition_add(-DWITH_CJSON)
|
||||
set(WITH_WINPR_JSON ON CACHE INTERNAL "internal")
|
||||
else()
|
||||
set(WITH_WINPR_JSON OFF CACHE INTERNAL "internal")
|
||||
message("compiling without JSON support. Install cJSON or json-c to enable")
|
||||
endif()
|
||||
else()
|
||||
set(WITH_WINPR_JSON OFF CACHE INTERNAL "internal")
|
||||
message("forced compile without JSON support. Set -DWITH_JSON_DISABLED=OFF to enable compile time detection")
|
||||
endif()
|
||||
|
||||
winpr_module_add(json/json.c)
|
||||
|
||||
Reference in New Issue
Block a user