diff options
author | fuzzard <fuzzard@kodi.tv> | 2023-10-02 17:57:12 +1000 |
---|---|---|
committer | fuzzard <fuzzard@kodi.tv> | 2023-10-02 18:06:14 +1000 |
commit | 66f35f8e025bb043de43ee47cb26f5cc9199f2d9 (patch) | |
tree | e969d2d6597a5021c46ebc338f6741a5562691ee /cmake/modules | |
parent | 0730dac071ab0b718d95e9b74a859a32358f9233 (diff) |
[cmake] FindRapidJSON update to newer module standards
Diffstat (limited to 'cmake/modules')
-rw-r--r-- | cmake/modules/FindRapidJSON.cmake | 86 |
1 files changed, 60 insertions, 26 deletions
diff --git a/cmake/modules/FindRapidJSON.cmake b/cmake/modules/FindRapidJSON.cmake index 19405867bd..377273151f 100644 --- a/cmake/modules/FindRapidJSON.cmake +++ b/cmake/modules/FindRapidJSON.cmake @@ -9,18 +9,15 @@ # if(NOT TARGET RapidJSON::RapidJSON) - if(ENABLE_INTERNAL_RapidJSON) - include(cmake/scripts/common/ModuleHelpers.cmake) - - set(MODULE_LC rapidjson) - - SETUP_BUILD_VARS() + include(cmake/scripts/common/ModuleHelpers.cmake) + macro(buildrapidjson) set(RapidJSON_VERSION ${${MODULE}_VER}) set(patches "${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/001-remove_custom_cxx_flags.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/002-cmake-removedocs-examples.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/003-win-arm64.patch") + "${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/002-cmake-standardise_config_installpath.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/003-cmake-removedocs-examples.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/rapidjson/004-win-arm64.patch") generate_patchcommand("${patches}") @@ -29,34 +26,54 @@ if(NOT TARGET RapidJSON::RapidJSON) -DRAPIDJSON_BUILD_TESTS=OFF -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=OFF) - set(BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include/rapidjson/rapidjson.h) + set(BUILD_BYPRODUCTS ${DEPENDS_PATH}/include/rapidjson/rapidjson.h) BUILD_DEP_TARGET() set(RAPIDJSON_INCLUDE_DIRS ${${MODULE}_INCLUDE_DIR}) + endmacro() - else() - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_RapidJSON RapidJSON>=1.0.2 QUIET) - endif() + set(MODULE_LC rapidjson) - if(CORE_SYSTEM_NAME STREQUAL windows OR CORE_SYSTEM_NAME STREQUAL windowsstore) - set(RapidJSON_VERSION 1.1.0) + SETUP_BUILD_VARS() + + if(RapidJSON_FIND_VERSION) + if(RapidJSON_FIND_VERSION_EXACT) + set(RapidJSON_FIND_SPEC "=${RapidJSON_FIND_VERSION_COMPLETE}") + set(RapidJSON_CONFIG_SPEC "${RapidJSON_FIND_VERSION_COMPLETE}" EXACT) else() - if(PC_RapidJSON_VERSION) + set(RapidJSON_FIND_SPEC ">=${RapidJSON_FIND_VERSION_COMPLETE}") + set(RapidJSON_CONFIG_SPEC "${RapidJSON_FIND_VERSION_COMPLETE}") + endif() + endif() + + find_package(RapidJSON CONFIG ${RapidJSON_CONFIG_SPEC} + HINTS ${DEPENDS_PATH}/lib/cmake + ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG}) + + # Check for existing RAPIDJSON. If version >= RAPIDJSON-VERSION file version, dont build + # A corner case, but if a linux/freebsd user WANTS to build internal tinyxml2, build anyway + if((RAPIDJSON_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_RapidJSON) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_RapidJSON)) + # Build internal rapidjson + buildrapidjson() + else() + # If RAPIDJSON_INCLUDE_DIRS exists, then the find_package command found a config + # and suitable version. If its not, we fall back to a pkgconfig/manual search + if(NOT DEFINED RAPIDJSON_INCLUDE_DIRS) + find_package(PkgConfig) + # Fallback to pkg-config and individual lib/include file search + # Do not use pkgconfig on windows + if(PKG_CONFIG_FOUND AND NOT WIN32) + pkg_check_modules(PC_RapidJSON RapidJSON${RapidJSON_FIND_SPEC} QUIET) set(RapidJSON_VERSION ${PC_RapidJSON_VERSION}) - else() - find_package(RapidJSON 1.1.0 CONFIG REQUIRED - QUIET - HINTS ${DEPENDS_PATH}/lib - ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG}) endif() - endif() - find_path(RAPIDJSON_INCLUDE_DIRS NAMES rapidjson/rapidjson.h - HINTS ${DEPENDS_PATH}/include ${PC_RapidJSON_INCLUDEDIR} - ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG} - NO_CACHE) + find_path(RAPIDJSON_INCLUDE_DIRS NAMES rapidjson/rapidjson.h + HINTS ${DEPENDS_PATH}/include ${PC_RapidJSON_INCLUDEDIR} + ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG} + NO_CACHE) + endif() endif() include(FindPackageHandleStandardArgs) @@ -71,6 +88,23 @@ if(NOT TARGET RapidJSON::RapidJSON) if(TARGET rapidjson) add_dependencies(RapidJSON::RapidJSON rapidjson) endif() + + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + if(NOT TARGET rapidjson) + buildrapidjson() + set_target_properties(rapidjson PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() + add_dependencies(build_internal_depends rapidjson) + endif() + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP RapidJSON::RapidJSON) endif() endif() |