Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] FindRapidJSON update to newer module standards #23851

Merged
merged 1 commit into from Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -73,7 +73,6 @@ option(ENABLE_TESTING "Enable testing support?" ON)

# These are required enabled for all CI platforms, and recommended for all builds
option(ENABLE_INTERNAL_CROSSGUID "Enable internal crossguid?" ON)
option(ENABLE_INTERNAL_RapidJSON "Enable internal rapidjson?" ON)

# use ffmpeg from depends or system
option(ENABLE_INTERNAL_FFMPEG "Enable internal ffmpeg?" OFF)
Expand All @@ -83,6 +82,7 @@ dependent_option(ENABLE_INTERNAL_FLATBUFFERS "Enable internal flatbuffers?")
dependent_option(ENABLE_INTERNAL_FMT "Enable internal fmt?")
dependent_option(ENABLE_INTERNAL_NFS "Enable internal libnfs?")
dependent_option(ENABLE_INTERNAL_PCRE "Enable internal pcre?")
dependent_option(ENABLE_INTERNAL_RapidJSON "Enable internal rapidjson?")
garbear marked this conversation as resolved.
Show resolved Hide resolved
dependent_option(ENABLE_INTERNAL_SPDLOG "Enable internal spdlog?")
dependent_option(ENABLE_INTERNAL_TAGLIB "Enable internal taglib?")
if(KODI_DEPENDSBUILD OR WIN32 OR WINDOWS_STORE)
Expand Down Expand Up @@ -195,7 +195,7 @@ set(required_deps ASS>=0.15.0
Lzo2
OpenSSL>=1.1.0
PCRE
RapidJSON
RapidJSON>=1.0.2
Spdlog
Sqlite3
TagLib
Expand Down
86 changes: 60 additions & 26 deletions cmake/modules/FindRapidJSON.cmake
Expand Up @@ -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}")

Expand All @@ -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)
Expand All @@ -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()
@@ -0,0 +1,15 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -94,11 +94,7 @@
SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "Directory where lib will install")
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}" CACHE PATH "Path to the documentation")

-IF(UNIX OR CYGWIN)
- SET(_CMAKE_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}")
-ELSEIF(WIN32)
- SET(_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/cmake")
-ENDIF()
+SET(_CMAKE_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}")
SET(CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" CACHE PATH "The directory cmake fiels are installed in")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
10 changes: 6 additions & 4 deletions tools/depends/target/rapidjson/Makefile
@@ -1,8 +1,9 @@
-include ../../Makefile.include
include RAPIDJSON-VERSION
DEPS = Makefile RAPIDJSON-VERSION 001-remove_custom_cxx_flags.patch ../../download-files.include \
002-cmake-removedocs-examples.patch \
003-win-arm64.patch
002-cmake-standardise_config_installpath.patch \
003-cmake-removedocs-examples.patch \
004-win-arm64.patch

CMAKE_OPTIONS=-DRAPIDJSON_HAS_STDSTRING=ON -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=OFF

Expand Down Expand Up @@ -42,8 +43,9 @@ endif
cd $(PLATFORM); $(ARCHIVE_TOOL) $(ARCHIVE_TOOL_FLAGS) $(TARBALLS_LOCATION)/$(ARCHIVE)
cd $(PLATFORM); rm -rf build; mkdir -p build
cd $(PLATFORM); patch -p1 -i ../001-remove_custom_cxx_flags.patch
cd $(PLATFORM); patch -p1 -i ../002-cmake-removedocs-examples.patch
cd $(PLATFORM); patch -p1 -i ../003-win-arm64.patch
cd $(PLATFORM); patch -p1 -i ../002-cmake-standardise_config_installpath.patch
cd $(PLATFORM); patch -p1 -i ../003-cmake-removedocs-examples.patch
cd $(PLATFORM); patch -p1 -i ../004-win-arm64.patch
cd $(PLATFORM)/build; $(CMAKE) $(CMAKE_OPTIONS) ..

.installed-$(PLATFORM): $(PLATFORM)
Expand Down