diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ca211a874378..7dbbc53a8983e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -385,7 +385,7 @@ core_add_subdirs_from_filelist(${CMAKE_SOURCE_DIR}/cmake/treedata/common/*.txt core_add_optional_subdirs_from_filelist(${CMAKE_SOURCE_DIR}/cmake/treedata/optional/common/*.txt ${CMAKE_SOURCE_DIR}/cmake/treedata/optional/${CORE_SYSTEM_NAME}/*.txt) -target_link_libraries(lib${APP_NAME_LC} PUBLIC ${core_DEPENDS} ${SYSTEM_LDFLAGS} ${DEPLIBS} ${CMAKE_DL_LIBS}) +target_link_libraries(lib${APP_NAME_LC} PUBLIC ${core_DEPENDS} ${SYSTEM_LDFLAGS} ${DEPLIBS} ${CMAKE_DL_LIBS} ${GLOBAL_TARGET_DEPS}) set_target_properties(lib${APP_NAME_LC} PROPERTIES PROJECT_LABEL "xbmc") source_group_by_folder(lib${APP_NAME_LC} RELATIVE ${CMAKE_SOURCE_DIR}/xbmc) if(WIN32) diff --git a/cmake/modules/FindCrossGUID.cmake b/cmake/modules/FindCrossGUID.cmake index 4aceb84dfcd49..59d0cebc6a6e5 100644 --- a/cmake/modules/FindCrossGUID.cmake +++ b/cmake/modules/FindCrossGUID.cmake @@ -2,110 +2,97 @@ # ------- # Finds the CrossGUID library # -# This will define the following variables:: -# -# CROSSGUID_FOUND_FOUND - system has CrossGUID -# CROSSGUID_INCLUDE_DIRS - the CrossGUID include directory -# CROSSGUID_LIBRARIES - the CrossGUID libraries -# CROSSGUID_DEFINITIONS - cmake definitions required -# -# and the following imported targets:: +# This will define the following target: # # CrossGUID::CrossGUID - The CrossGUID library -if(ENABLE_INTERNAL_CROSSGUID) - include(cmake/scripts/common/ModuleHelpers.cmake) +if(NOT TARGET CrossGUID::CrossGUID) + if(ENABLE_INTERNAL_CROSSGUID) + include(cmake/scripts/common/ModuleHelpers.cmake) - set(MODULE_LC crossguid) + set(MODULE_LC crossguid) - SETUP_BUILD_VARS() + SETUP_BUILD_VARS() - set(CROSSGUID_VERSION ${${MODULE}_VER}) - set(CROSSGUID_DEFINITIONS -DHAVE_NEW_CROSSGUID) - set(CROSSGUID_DEBUG_POSTFIX "-dgb") + set(CROSSGUID_VERSION ${${MODULE}_VER}) + set(CROSSGUID_DEBUG_POSTFIX "-dgb") - if(ANDROID) - list(APPEND CROSSGUID_DEFINITIONS -DGUID_ANDROID) - endif() + set(_crossguid_definitions HAVE_NEW_CROSSGUID) - set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/001-fix-unused-function.patch" - "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/002-disable-Wall-error.patch" - "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/003-add-cstdint-include.patch") + if(ANDROID) + list(APPEND _crossguid_definitions GUID_ANDROID) + endif() - generate_patchcommand("${patches}") + set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/001-fix-unused-function.patch" + "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/002-disable-Wall-error.patch" + "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/003-add-cstdint-include.patch") - set(CMAKE_ARGS -DCROSSGUID_TESTS=OFF - -DDISABLE_WALL=ON) + generate_patchcommand("${patches}") - BUILD_DEP_TARGET() + set(CMAKE_ARGS -DCROSSGUID_TESTS=OFF + -DDISABLE_WALL=ON) -else() - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_CROSSGUID crossguid QUIET) - set(CROSSGUID_VERSION ${PC_CROSSGUID_VERSION}) - endif() + BUILD_DEP_TARGET() - if(CROSSGUID_FOUND) - find_path(CROSSGUID_INCLUDE_DIR NAMES crossguid/guid.hpp guid.h - PATHS ${PC_CROSSGUID_INCLUDEDIR}) + else() + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_CROSSGUID crossguid QUIET) + set(CROSSGUID_VERSION ${PC_CROSSGUID_VERSION}) + endif() + find_path(CROSSGUID_INCLUDE_DIR NAMES crossguid/guid.hpp guid.h + PATHS ${PC_CROSSGUID_INCLUDEDIR}) find_library(CROSSGUID_LIBRARY_RELEASE NAMES crossguid - PATHS ${PC_CROSSGUID_LIBDIR}) + HINTS ${PC_CROSSGUID_LIBDIR}) find_library(CROSSGUID_LIBRARY_DEBUG NAMES crossguidd crossguid-dgb - PATHS ${PC_CROSSGUID_LIBDIR}) - else() - find_path(CROSSGUID_INCLUDE_DIR NAMES crossguid/guid.hpp guid.h) - find_library(CROSSGUID_LIBRARY_RELEASE NAMES crossguid) - find_library(CROSSGUID_LIBRARY_DEBUG NAMES crossguidd) - endif() -endif() + HINTS ${PC_CROSSGUID_LIBDIR}) -# Select relevant lib build type (ie CROSSGUID_LIBRARY_RELEASE or CROSSGUID_LIBRARY_DEBUG) -include(SelectLibraryConfigurations) -select_library_configurations(CROSSGUID) + # NEW_CROSSGUID >= 0.2.0 release + if(EXISTS "${CROSSGUID_INCLUDE_DIR}/crossguid/guid.hpp") + list(APPEND _crossguid_definitions HAVE_NEW_CROSSGUID) + endif() + endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(CrossGUID - REQUIRED_VARS CROSSGUID_LIBRARY CROSSGUID_INCLUDE_DIR - VERSION_VAR CROSSGUID_VERSION) + # Select relevant lib build type (ie CROSSGUID_LIBRARY_RELEASE or CROSSGUID_LIBRARY_DEBUG) + include(SelectLibraryConfigurations) + select_library_configurations(CROSSGUID) -if(CROSSGUID_FOUND) - set(CROSSGUID_LIBRARIES ${CROSSGUID_LIBRARY}) - set(CROSSGUID_INCLUDE_DIRS ${CROSSGUID_INCLUDE_DIR}) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(CrossGUID + REQUIRED_VARS CROSSGUID_LIBRARY CROSSGUID_INCLUDE_DIR + VERSION_VAR CROSSGUID_VERSION) - # NEW_CROSSGUID >= 0.2.0 release - if(EXISTS "${CROSSGUID_INCLUDE_DIR}/crossguid/guid.hpp") - list(APPEND CROSSGUID_DEFINITIONS -DHAVE_NEW_CROSSGUID) + add_library(CrossGUID::CrossGUID UNKNOWN IMPORTED) + if(CROSSGUID_LIBRARY_RELEASE) + set_target_properties(CrossGUID::CrossGUID PROPERTIES + IMPORTED_CONFIGURATIONS RELEASE + IMPORTED_LOCATION_RELEASE "${CROSSGUID_LIBRARY_RELEASE}") endif() + if(CROSSGUID_LIBRARY_DEBUG) + set_target_properties(CrossGUID::CrossGUID PROPERTIES + IMPORTED_CONFIGURATIONS DEBUG + IMPORTED_LOCATION_DEBUG "${CROSSGUID_LIBRARY_DEBUG}") + endif() + set_target_properties(CrossGUID::CrossGUID PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CROSSGUID_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_crossguid_definitions}") if(UNIX AND NOT (APPLE OR ANDROID)) # Suppress mismatch warning, see https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html set(FPHSA_NAME_MISMATCHED 1) find_package(UUID REQUIRED) unset(FPHSA_NAME_MISMATCHED) - list(APPEND CROSSGUID_INCLUDE_DIRS ${UUID_INCLUDE_DIRS}) - list(APPEND CROSSGUID_LIBRARIES ${UUID_LIBRARIES}) - endif() - if(NOT TARGET CrossGUID::CrossGUID) - add_library(CrossGUID::CrossGUID UNKNOWN IMPORTED) - if(CROSSGUID_LIBRARY_RELEASE) - set_target_properties(CrossGUID::CrossGUID PROPERTIES - IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION "${CROSSGUID_LIBRARY_RELEASE}") + if(TARGET UUID::UUID) + add_dependencies(CrossGUID::CrossGUID UUID::UUID) + target_link_libraries(CrossGUID::CrossGUID INTERFACE UUID::UUID) endif() - if(CROSSGUID_LIBRARY_DEBUG) - set_target_properties(CrossGUID::CrossGUID PROPERTIES - IMPORTED_CONFIGURATIONS DEBUG - IMPORTED_LOCATION "${CROSSGUID_LIBRARY_DEBUG}") - endif() - set_target_properties(CrossGUID::CrossGUID PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${CROSSGUID_INCLUDE_DIRS}") endif() + if(TARGET crossguid) add_dependencies(CrossGUID::CrossGUID crossguid) endif() - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP CrossGUID::CrossGUID) + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP CrossGUID::CrossGUID) endif() mark_as_advanced(CROSSGUID_INCLUDE_DIR CROSSGUID_LIBRARY) diff --git a/cmake/modules/FindFFMPEG.cmake b/cmake/modules/FindFFMPEG.cmake index e53a121ecf16a..96d9533406ae4 100644 --- a/cmake/modules/FindFFMPEG.cmake +++ b/cmake/modules/FindFFMPEG.cmake @@ -18,17 +18,9 @@ # usage: -DWITH_FFMPEG=/path/to/ffmpeg_install_prefix # # -------- -# This module will define the following variables: +# This will define the following target: # -# FFMPEG_FOUND - system has FFmpeg -# FFMPEG_INCLUDE_DIRS - FFmpeg include directory -# FFMPEG_LIBRARIES - FFmpeg libraries -# FFMPEG_DEFINITIONS - pre-processor definitions -# FFMPEG_LDFLAGS - linker flags -# -# and the following imported targets:: -# -# ffmpeg - The FFmpeg libraries +# ffmpeg::ffmpeg - The FFmpeg interface target # -------- # @@ -37,14 +29,17 @@ macro(buildFFMPEG) include(cmake/scripts/common/ModuleHelpers.cmake) - set(MODULE_LC ffmpeg) - - SETUP_BUILD_VARS() - + # Check for dependencies - Must be done before SETUP_BUILD_VARS + get_libversion_data("dav1d" "target") + find_package(Dav1d ${LIB_DAV1D_VER} MODULE) if(NOT DAV1D_FOUND) message(STATUS "dav1d not found, internal ffmpeg build will be missing AV1 support!") endif() + set(MODULE_LC ffmpeg) + + SETUP_BUILD_VARS() + set(FFMPEG_OPTIONS -DENABLE_CCACHE=${ENABLE_CCACHE} -DCCACHE_PROGRAM=${CCACHE_PROGRAM} -DENABLE_VAAPI=${ENABLE_VAAPI} @@ -67,8 +62,7 @@ macro(buildFFMPEG) string(REPLACE ";" "|" FFMPEG_MODULE_PATH "${CMAKE_MODULE_PATH}") set(FFMPEG_LIST_SEPARATOR LIST_SEPARATOR |) - set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} - -DCMAKE_MODULE_PATH=${FFMPEG_MODULE_PATH} + set(CMAKE_ARGS -DCMAKE_MODULE_PATH=${FFMPEG_MODULE_PATH} -DFFMPEG_VER=${FFMPEG_VER} -DCORE_SYSTEM_NAME=${CORE_SYSTEM_NAME} -DCORE_PLATFORM_NAME=${CORE_PLATFORM_NAME_LC} @@ -91,11 +85,9 @@ macro(buildFFMPEG) set(FFMPEG_GENERATOR CMAKE_GENERATOR "Unix Makefiles") endif() - set(FFMPEG_LIB_TYPE STATIC) - BUILD_DEP_TARGET() - if(ENABLE_INTERNAL_DAV1D) + if(TARGET dav1d) add_dependencies(ffmpeg dav1d) endif() @@ -105,7 +97,7 @@ macro(buildFFMPEG) endif() file(WRITE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ffmpeg/ffmpeg-link-wrapper "#!${BASH_COMMAND} -if [[ $@ == *${APP_NAME_LC}.bin* || $@ == *${APP_NAME_LC}${APP_BINARY_SUFFIX}* || $@ == *${APP_NAME_LC}.so* || $@ == *${APP_NAME_LC}-test* ]] +if [[ $@ == *${APP_NAME_LC}.bin* || $@ == *${APP_NAME_LC}${APP_BINARY_SUFFIX}* || $@ == *${APP_NAME_LC}.so* || $@ == *${APP_NAME_LC}-test* || $@ == *MacOS/Kodi* ]] then avcodec=`PKG_CONFIG_PATH=${DEPENDS_PATH}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libavcodec` avformat=`PKG_CONFIG_PATH=${DEPENDS_PATH}/lib/pkgconfig ${PKG_CONFIG_EXECUTABLE} --libs --static libavformat` @@ -123,12 +115,49 @@ fi") FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) set(FFMPEG_LINK_EXECUTABLE "${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ffmpeg-link-wrapper -o " PARENT_SCOPE) - set(FFMPEG_CREATE_SHARED_LIBRARY "${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ffmpeg-link-wrapper -o " PARENT_SCOPE) set(FFMPEG_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include) - set(FFMPEG_DEFINITIONS -DUSE_STATIC_FFMPEG=1) set(FFMPEG_FOUND 1) - - set_target_properties(ffmpeg PROPERTIES FOLDER "External Projects") + set(FFMPEG_VERSION ${FFMPEG_VER}) + + # Whilst we use ffmpeg-link-wrapper, we only need INTERFACE at most, and possibly + # just not at all. However this gives target consistency with external FFMPEG usage + # The benefit and reason to continue to use the wrapper is to automate the collection + # of the actual linker flags from pkg-config lookup + + add_library(ffmpeg::libavcodec INTERFACE IMPORTED) + set_target_properties(ffmpeg::libavcodec PROPERTIES + FOLDER "FFMPEG - External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}") + + add_library(ffmpeg::libavfilter INTERFACE IMPORTED) + set_target_properties(ffmpeg::libavfilter PROPERTIES + FOLDER "FFMPEG - External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}") + + add_library(ffmpeg::libavformat INTERFACE IMPORTED) + set_target_properties(ffmpeg::libavformat PROPERTIES + FOLDER "FFMPEG - External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}") + + add_library(ffmpeg::libavutil INTERFACE IMPORTED) + set_target_properties(ffmpeg::libavutil PROPERTIES + FOLDER "FFMPEG - External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}") + + add_library(ffmpeg::libswscale INTERFACE IMPORTED) + set_target_properties(ffmpeg::libswscale PROPERTIES + FOLDER "FFMPEG - External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}") + + add_library(ffmpeg::libswresample INTERFACE IMPORTED) + set_target_properties(ffmpeg::libswresample PROPERTIES + FOLDER "FFMPEG - External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}") + + add_library(ffmpeg::libpostproc INTERFACE IMPORTED) + set_target_properties(ffmpeg::libpostproc PROPERTIES + FOLDER "FFMPEG - External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}") endmacro() @@ -174,7 +203,6 @@ else() if(PKG_CONFIG_FOUND) pkg_check_modules(PC_FFMPEG ${FFMPEG_PKGS} QUIET) - string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LDFLAGS "${PC_FFMPEG_LDFLAGS}") endif() find_path(FFMPEG_INCLUDE_DIRS libavcodec/avcodec.h libavfilter/avfilter.h libavformat/avformat.h @@ -192,6 +220,19 @@ else() NO_DEFAULT_PATH) find_library(FFMPEG_LIBAVCODEC NAMES avcodec libavcodec PATH_SUFFIXES ffmpeg/libavcodec) + if(FFMPEG_LIBAVCODEC) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FFMPEG_LIB libavcodec${_avcodec_ver} QUIET) + string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LIB_LDFLAGS "${PC_FFMPEG_LIB_LDFLAGS}") + endif() + add_library(ffmpeg::libavcodec UNKNOWN IMPORTED) + set_target_properties(ffmpeg::libavcodec PROPERTIES + FOLDER "FFMPEG - External Projects" + IMPORTED_LOCATION "${FFMPEG_LIBAVCODEC}" + INTERFACE_LINK_LIBRARIES "${PC_FFMPEG_LIB_LDFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}") + endif() + find_library(FFMPEG_LIBAVFILTER NAMES avfilter libavfilter PATH_SUFFIXES ffmpeg/libavfilter @@ -199,6 +240,19 @@ else() NO_DEFAULT_PATH) find_library(FFMPEG_LIBAVFILTER NAMES avfilter libavfilter PATH_SUFFIXES ffmpeg/libavfilter) + if(FFMPEG_LIBAVFILTER) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FFMPEG_LIB libavfilter${_avfilter_ver} QUIET) + string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LIB_LDFLAGS "${PC_FFMPEG_LIB_LDFLAGS}") + endif() + add_library(ffmpeg::libavfilter UNKNOWN IMPORTED) + set_target_properties(ffmpeg::libavfilter PROPERTIES + FOLDER "FFMPEG - External Projects" + IMPORTED_LOCATION "${FFMPEG_LIBAVFILTER}" + INTERFACE_LINK_LIBRARIES "${PC_FFMPEG_LIB_LDFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}") + endif() + find_library(FFMPEG_LIBAVFORMAT NAMES avformat libavformat PATH_SUFFIXES ffmpeg/libavformat @@ -206,6 +260,19 @@ else() NO_DEFAULT_PATH) find_library(FFMPEG_LIBAVFORMAT NAMES avformat libavformat PATH_SUFFIXES ffmpeg/libavformat) + if(FFMPEG_LIBAVFORMAT) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FFMPEG_LIB libavformat${_avformat_ver} QUIET) + string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LIB_LDFLAGS "${PC_FFMPEG_LIB_LDFLAGS}") + endif() + add_library(ffmpeg::libavformat UNKNOWN IMPORTED) + set_target_properties(ffmpeg::libavformat PROPERTIES + FOLDER "FFMPEG - External Projects" + IMPORTED_LOCATION "${FFMPEG_LIBAVFORMAT}" + INTERFACE_LINK_LIBRARIES "${PC_FFMPEG_LIB_LDFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}") + endif() + find_library(FFMPEG_LIBAVUTIL NAMES avutil libavutil PATH_SUFFIXES ffmpeg/libavutil @@ -213,6 +280,19 @@ else() NO_DEFAULT_PATH) find_library(FFMPEG_LIBAVUTIL NAMES avutil libavutil PATH_SUFFIXES ffmpeg/libavutil) + if(FFMPEG_LIBAVUTIL) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FFMPEG_LIB libavutil${_avutil_ver} QUIET) + string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LIB_LDFLAGS "${PC_FFMPEG_LIB_LDFLAGS}") + endif() + add_library(ffmpeg::libavutil UNKNOWN IMPORTED) + set_target_properties(ffmpeg::libavutil PROPERTIES + FOLDER "FFMPEG - External Projects" + IMPORTED_LOCATION "${FFMPEG_LIBAVUTIL}" + INTERFACE_LINK_LIBRARIES "${PC_FFMPEG_LIB_LDFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}") + endif() + find_library(FFMPEG_LIBSWSCALE NAMES swscale libswscale PATH_SUFFIXES ffmpeg/libswscale @@ -220,6 +300,19 @@ else() NO_DEFAULT_PATH) find_library(FFMPEG_LIBSWSCALE NAMES swscale libswscale PATH_SUFFIXES ffmpeg/libswscale) + if(FFMPEG_LIBSWSCALE) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FFMPEG_LIB libswscale${_swscale_ver} QUIET) + string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LIB_LDFLAGS "${PC_FFMPEG_LIB_LDFLAGS}") + endif() + add_library(ffmpeg::libswscale UNKNOWN IMPORTED) + set_target_properties(ffmpeg::libswscale PROPERTIES + FOLDER "FFMPEG - External Projects" + IMPORTED_LOCATION "${FFMPEG_LIBSWSCALE}" + INTERFACE_LINK_LIBRARIES "${PC_FFMPEG_LIB_LDFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}") + endif() + find_library(FFMPEG_LIBSWRESAMPLE NAMES swresample libswresample PATH_SUFFIXES ffmpeg/libswresample @@ -227,6 +320,19 @@ else() NO_DEFAULT_PATH) find_library(FFMPEG_LIBSWRESAMPLE NAMES NAMES swresample libswresample PATH_SUFFIXES ffmpeg/libswresample) + if(FFMPEG_LIBSWRESAMPLE) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FFMPEG_LIB libswresample${_swresample_ver} QUIET) + string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LIB_LDFLAGS "${PC_FFMPEG_LIB_LDFLAGS}") + endif() + add_library(ffmpeg::libswresample UNKNOWN IMPORTED) + set_target_properties(ffmpeg::libswresample PROPERTIES + FOLDER "FFMPEG - External Projects" + IMPORTED_LOCATION "${FFMPEG_LIBSWRESAMPLE}" + INTERFACE_LINK_LIBRARIES "${PC_FFMPEG_LIB_LDFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}") + endif() + find_library(FFMPEG_LIBPOSTPROC NAMES postproc libpostproc PATH_SUFFIXES ffmpeg/libpostproc @@ -234,6 +340,19 @@ else() NO_DEFAULT_PATH) find_library(FFMPEG_LIBPOSTPROC NAMES postproc libpostproc PATH_SUFFIXES ffmpeg/libpostproc) + if(FFMPEG_LIBPOSTPROC) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FFMPEG_LIB libpostproc${_postproc_ver} QUIET) + string(REGEX REPLACE "framework;" "framework " PC_FFMPEG_LIB_LDFLAGS "${PC_FFMPEG_LIB_LDFLAGS}") + endif() + add_library(ffmpeg::libpostproc UNKNOWN IMPORTED) + set_target_properties(ffmpeg::libpostproc PROPERTIES + FOLDER "FFMPEG - External Projects" + IMPORTED_LOCATION "${FFMPEG_LIBPOSTPROC}" + INTERFACE_LINK_LIBRARIES "${PC_FFMPEG_LIB_LDFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}") + endif() + if((PC_FFMPEG_FOUND AND PC_FFMPEG_libavcodec_VERSION AND PC_FFMPEG_libavfilter_VERSION @@ -260,23 +379,6 @@ else() FFMPEG_VERSION FAIL_MESSAGE "FFmpeg ${REQUIRED_FFMPEG_VERSION} not found, please consider using -DENABLE_INTERNAL_FFMPEG=ON") - if(FFMPEG_FOUND) - set(FFMPEG_LDFLAGS ${PC_FFMPEG_LDFLAGS} CACHE STRING "ffmpeg linker flags") - - set(FFMPEG_LIBRARIES ${FFMPEG_LIBAVCODEC} ${FFMPEG_LIBAVFILTER} - ${FFMPEG_LIBAVFORMAT} ${FFMPEG_LIBAVUTIL} - ${FFMPEG_LIBSWSCALE} ${FFMPEG_LIBSWRESAMPLE} - ${FFMPEG_LIBPOSTPROC} ${FFMPEG_LDFLAGS}) - - # check if ffmpeg libs are statically linked - set(FFMPEG_LIB_TYPE SHARED) - foreach(_fflib IN LISTS FFMPEG_LIBRARIES) - if(${_fflib} MATCHES ".+\.a$" AND PC_FFMPEG_STATIC_LDFLAGS) - set(FFMPEG_LIB_TYPE STATIC) - break() - endif() - endforeach() - endif() else() if(FFMPEG_PATH) message(FATAL_ERROR "FFmpeg not found, please consider using -DENABLE_INTERNAL_FFMPEG=ON") @@ -288,20 +390,29 @@ else() endif() if(FFMPEG_FOUND) + set(_ffmpeg_definitions FFMPEG_VER_SHA=${FFMPEG_VERSION}) + + if(NOT TARGET ffmpeg::ffmpeg) + add_library(ffmpeg::ffmpeg INTERFACE IMPORTED) + set_target_properties(ffmpeg::ffmpeg PROPERTIES + FOLDER "External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_ffmpeg_definitions}") + endif() - list(APPEND FFMPEG_DEFINITIONS -DFFMPEG_VER_SHA=\"${FFMPEG_VERSION}\") + target_link_libraries(ffmpeg::ffmpeg INTERFACE ffmpeg::libavcodec) + target_link_libraries(ffmpeg::ffmpeg INTERFACE ffmpeg::libavfilter) + target_link_libraries(ffmpeg::ffmpeg INTERFACE ffmpeg::libavformat) + target_link_libraries(ffmpeg::ffmpeg INTERFACE ffmpeg::libavutil) + target_link_libraries(ffmpeg::ffmpeg INTERFACE ffmpeg::libswscale) + target_link_libraries(ffmpeg::ffmpeg INTERFACE ffmpeg::libswresample) + target_link_libraries(ffmpeg::ffmpeg INTERFACE ffmpeg::libpostproc) - if(NOT TARGET ffmpeg) - add_library(ffmpeg ${FFMPEG_LIB_TYPE} IMPORTED) - set_target_properties(ffmpeg PROPERTIES - FOLDER "External Projects" - IMPORTED_LOCATION "${FFMPEG_LIBRARIES}" - INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}" - INTERFACE_LINK_LIBRARIES "${FFMPEG_LDFLAGS}" - INTERFACE_COMPILE_DEFINITIONS "${FFMPEG_DEFINITIONS}") + if(TARGET ffmpeg) + add_dependencies(ffmpeg::ffmpeg ffmpeg) endif() - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP ffmpeg) + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP ffmpeg::ffmpeg) endif() -mark_as_advanced(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES FFMPEG_LDFLAGS FFMPEG_DEFINITIONS FFMPEG_FOUND) +mark_as_advanced(FFMPEG_FOUND) diff --git a/cmake/modules/FindFlatBuffers.cmake b/cmake/modules/FindFlatBuffers.cmake index fffac4fae7390..4c0a28b63581e 100644 --- a/cmake/modules/FindFlatBuffers.cmake +++ b/cmake/modules/FindFlatBuffers.cmake @@ -10,47 +10,44 @@ find_package(FlatC REQUIRED) -if(ENABLE_INTERNAL_FLATBUFFERS) - include(cmake/scripts/common/ModuleHelpers.cmake) - - set(MODULE_LC flatbuffers) - - SETUP_BUILD_VARS() - - # Override build type detection and always build as release - set(FLATBUFFERS_BUILD_TYPE Release) - - set(CMAKE_ARGS -DFLATBUFFERS_CODE_COVERAGE=OFF - -DFLATBUFFERS_BUILD_TESTS=OFF - -DFLATBUFFERS_INSTALL=ON - -DFLATBUFFERS_BUILD_FLATLIB=OFF - -DFLATBUFFERS_BUILD_FLATC=OFF - -DFLATBUFFERS_BUILD_FLATHASH=OFF - -DFLATBUFFERS_BUILD_GRPCTEST=OFF - -DFLATBUFFERS_BUILD_SHAREDLIB=OFF - "${EXTRA_ARGS}") - set(BUILD_BYPRODUCTS ${DEPENDS_PATH}/include/flatbuffers/flatbuffers.h) - - BUILD_DEP_TARGET() -else() - find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h) -endif() +if(NOT TARGET flatbuffers::flatbuffers) + if(ENABLE_INTERNAL_FLATBUFFERS) + include(cmake/scripts/common/ModuleHelpers.cmake) + + set(MODULE_LC flatbuffers) + + SETUP_BUILD_VARS() + + # Override build type detection and always build as release + set(FLATBUFFERS_BUILD_TYPE Release) + + set(CMAKE_ARGS -DFLATBUFFERS_CODE_COVERAGE=OFF + -DFLATBUFFERS_BUILD_TESTS=OFF + -DFLATBUFFERS_INSTALL=ON + -DFLATBUFFERS_BUILD_FLATLIB=OFF + -DFLATBUFFERS_BUILD_FLATC=OFF + -DFLATBUFFERS_BUILD_FLATHASH=OFF + -DFLATBUFFERS_BUILD_GRPCTEST=OFF + -DFLATBUFFERS_BUILD_SHAREDLIB=OFF + "${EXTRA_ARGS}") + set(BUILD_BYPRODUCTS ${DEPENDS_PATH}/include/flatbuffers/flatbuffers.h) + + BUILD_DEP_TARGET() + else() + find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h) + endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(FlatBuffers - REQUIRED_VARS FLATBUFFERS_INCLUDE_DIR - VERSION_VAR FLATBUFFERS_VER) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(FlatBuffers + REQUIRED_VARS FLATBUFFERS_INCLUDE_DIR + VERSION_VAR FLATBUFFERS_VER) -if(FLATBUFFERS_FOUND) set(FLATBUFFERS_MESSAGES_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/RetroPlayer/messages CACHE INTERNAL "Generated FlatBuffer headers") - set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR} ${FLATBUFFERS_MESSAGES_INCLUDE_DIR}) - if(NOT TARGET flatbuffers::flatbuffers) - add_library(flatbuffers::flatbuffers UNKNOWN IMPORTED) - set_target_properties(flatbuffers::flatbuffers PROPERTIES - FOLDER "External Projects" - INTERFACE_INCLUDE_DIRECTORIES ${FLATBUFFERS_INCLUDE_DIR}) - endif() + add_library(flatbuffers::flatbuffers INTERFACE IMPORTED) + set_target_properties(flatbuffers::flatbuffers PROPERTIES + FOLDER "External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${FLATBUFFERS_INCLUDE_DIR};${FLATBUFFERS_MESSAGES_INCLUDE_DIR}") add_dependencies(flatbuffers::flatbuffers flatbuffers::flatc) @@ -58,6 +55,7 @@ if(FLATBUFFERS_FOUND) add_dependencies(flatbuffers::flatbuffers flatbuffers) endif() set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP flatbuffers::flatbuffers) + endif() mark_as_advanced(FLATBUFFERS_INCLUDE_DIR) diff --git a/cmake/modules/FindFmt.cmake b/cmake/modules/FindFmt.cmake index 7f0023be0512a..4c50291efb9e5 100644 --- a/cmake/modules/FindFmt.cmake +++ b/cmake/modules/FindFmt.cmake @@ -2,13 +2,7 @@ # ------- # Finds the Fmt library # -# This will define the following variables:: -# -# FMT_FOUND - system has Fmt -# FMT_INCLUDE_DIRS - the Fmt include directory -# FMT_LIBRARIES - the Fmt libraries -# -# and the following imported targets:: +# This will define the following target: # # fmt::fmt - The Fmt library @@ -21,27 +15,27 @@ set(FORCE_BUILD OFF) # If target exists, no need to rerun find # Allows a module that may be a dependency for multiple libraries to just be executed # once to populate all required variables/targets -if((NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) AND NOT TARGET fmt) +if(NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) - # Build if ENABLE_INTERNAL_FMT, or if required version in find_package call is greater - # than already found FMT_VERSION from a previous find_package call - if(ENABLE_INTERNAL_FMT OR (Fmt_FIND_REQUIRED AND FMT_VERSION VERSION_LESS Fmt_FIND_VERSION)) + include(cmake/scripts/common/ModuleHelpers.cmake) - include(cmake/scripts/common/ModuleHelpers.cmake) + set(MODULE_LC fmt) - set(MODULE_LC fmt) + SETUP_BUILD_VARS() - SETUP_BUILD_VARS() + # Check for existing FMT. If version >= FMT-VERSION file version, dont build + find_package(FMT CONFIG QUIET) - # Check for existing FMT. If version >= FMT-VERSION file version, dont build - find_package(FMT CONFIG QUIET) + # Build if ENABLE_INTERNAL_FMT, or if required version in find_package call is greater + # than already found FMT_VERSION from a previous find_package call + if((Fmt_FIND_REQUIRED AND FMT_VERSION VERSION_LESS Fmt_FIND_VERSION AND ENABLE_INTERNAL_FMT) OR + (FMT_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_FMT) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_FMT)) if(Fmt_FIND_VERSION) if(FMT_VERSION VERSION_LESS ${Fmt_FIND_VERSION}) set(FORCE_BUILD ON) endif() - else() - set(FORCE_BUILD ON) endif() if(${FORCE_BUILD} OR FMT_VERSION VERSION_LESS ${${MODULE}_VER}) @@ -71,31 +65,76 @@ if((NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) AND NOT TARGET fmt) BUILD_DEP_TARGET() else() - # Populate paths for find_package_handle_standard_args - find_path(FMT_INCLUDE_DIR NAMES fmt/format.h) - find_library(FMT_LIBRARY_RELEASE NAMES fmt) - find_library(FMT_LIBRARY_DEBUG NAMES fmtd) + if(NOT TARGET fmt::fmt) + set(FMT_PKGCONFIG_CHECK ON) + endif() endif() else() - find_package(FMT 6.1.2 CONFIG REQUIRED QUIET) + if(NOT TARGET fmt::fmt) + set(FMT_PKGCONFIG_CHECK ON) + endif() + endif() - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_FMT libfmt QUIET) - if(PC_FMT_VERSION AND NOT FMT_VERSION) + if(NOT TARGET fmt::fmt) + if(FMT_PKGCONFIG_CHECK) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FMT libfmt QUIET) set(FMT_VERSION ${PC_FMT_VERSION}) endif() + + find_path(FMT_INCLUDE_DIR NAMES fmt/format.h + PATHS ${PC_FMT_INCLUDEDIR}) + + find_library(FMT_LIBRARY_RELEASE NAMES fmt + PATHS ${PC_FMT_LIBDIR}) + find_library(FMT_LIBRARY_DEBUG NAMES fmtd + PATHS ${PC_FMT_LIBDIR}) endif() - find_path(FMT_INCLUDE_DIR NAMES fmt/format.h - PATHS ${PC_FMT_INCLUDEDIR}) + add_library(fmt::fmt UNKNOWN IMPORTED) + if(FMT_LIBRARY_RELEASE) + set_target_properties(fmt::fmt PROPERTIES + IMPORTED_CONFIGURATIONS RELEASE + IMPORTED_LOCATION_RELEASE "${FMT_LIBRARY_RELEASE}") + endif() + if(FMT_LIBRARY_DEBUG) + set_target_properties(fmt::fmt PROPERTIES + IMPORTED_CONFIGURATIONS DEBUG + IMPORTED_LOCATION_DEBUG "${FMT_LIBRARY_DEBUG}") + endif() + set_target_properties(fmt::fmt PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${FMT_INCLUDE_DIR}") - find_library(FMT_LIBRARY_RELEASE NAMES fmt - PATHS ${PC_FMT_LIBDIR}) - find_library(FMT_LIBRARY_DEBUG NAMES fmtd - PATHS ${PC_FMT_LIBDIR}) + if(TARGET fmt) + add_dependencies(fmt::fmt fmt) + endif() + endif() + # If a force build is done, let any calling packages know they may want to rebuild + if(FORCE_BUILD) + set_target_properties(fmt::fmt PROPERTIES LIB_BUILD ON) endif() + # This is for the case where a distro provides a non standard (Debug/Release) config type + # eg Debian's config file is fmtConfigTargets-none.cmake + # convert this back to either DEBUG/RELEASE or just RELEASE + # we only do this because we use find_package_handle_standard_args for config time output + # and it isnt capable of handling TARGETS, so we have to extract the info + get_target_property(_FMT_CONFIGURATIONS fmt::fmt IMPORTED_CONFIGURATIONS) + foreach(_fmt_config IN LISTS _FMT_CONFIGURATIONS) + # Some non standard config (eg None on Debian) + # Just set to RELEASE var so select_library_configurations can continue to work its magic + string(TOUPPER ${_fmt_config} _fmt_config_UPPER) + if((NOT ${_fmt_config_UPPER} STREQUAL "RELEASE") AND + (NOT ${_fmt_config_UPPER} STREQUAL "DEBUG")) + get_target_property(FMT_LIBRARY_RELEASE fmt::fmt IMPORTED_LOCATION_${_fmt_config_UPPER}) + else() + get_target_property(FMT_LIBRARY_${_fmt_config_UPPER} fmt::fmt IMPORTED_LOCATION_${_fmt_config_UPPER}) + endif() + endforeach() + + get_target_property(FMT_INCLUDE_DIR fmt::fmt INTERFACE_INCLUDE_DIRECTORIES) + include(SelectLibraryConfigurations) select_library_configurations(FMT) @@ -104,46 +143,13 @@ if((NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) AND NOT TARGET fmt) REQUIRED_VARS FMT_LIBRARY FMT_INCLUDE_DIR VERSION_VAR FMT_VERSION) - if(FMT_FOUND) - set(FMT_LIBRARIES ${FMT_LIBRARY}) - set(FMT_INCLUDE_DIRS ${FMT_INCLUDE_DIR}) - - # Reorder this to allow handling of FMT_FORCE_BUILD and not duplicate in property - if(NOT TARGET fmt::fmt) - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fmt::fmt) - endif() - - if(NOT TARGET fmt::fmt OR FORCE_BUILD) - if(NOT TARGET fmt::fmt) - add_library(fmt::fmt UNKNOWN IMPORTED) - endif() - - if(FMT_LIBRARY_RELEASE) - set_target_properties(fmt::fmt PROPERTIES - IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION "${FMT_LIBRARY_RELEASE}") - endif() - if(FMT_LIBRARY_DEBUG) - set_target_properties(fmt::fmt PROPERTIES - IMPORTED_CONFIGURATIONS DEBUG - IMPORTED_LOCATION "${FMT_LIBRARY_DEBUG}") - endif() - set_target_properties(fmt::fmt PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${FMT_INCLUDE_DIR}") + # Check whether we already have tinyxml2::tinyxml2 target added to dep property list + get_property(CHECK_INTERNAL_DEPS GLOBAL PROPERTY INTERNAL_DEPS_PROP) + list(FIND CHECK_INTERNAL_DEPS "fmt::fmt" FMT_PROP_FOUND) - # If a force build is done, let any calling packages know they may want to rebuild - if(FORCE_BUILD) - set_target_properties(fmt::fmt PROPERTIES LIB_BUILD ON) - endif() - endif() - if(TARGET fmt) - add_dependencies(fmt::fmt fmt) - endif() - else() - if(FMT_FIND_REQUIRED) - message(FATAL_ERROR "Fmt lib not found. Maybe use -DENABLE_INTERNAL_FMT=ON") - endif() + # list(FIND) returns -1 if search item not found + if(FMT_PROP_FOUND STREQUAL "-1") + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fmt::fmt) endif() - mark_as_advanced(FMT_INCLUDE_DIR FMT_LIBRARY) endif() diff --git a/cmake/modules/FindFstrcmp.cmake b/cmake/modules/FindFstrcmp.cmake index d2625f1020eb3..2bf412c2ddb9e 100644 --- a/cmake/modules/FindFstrcmp.cmake +++ b/cmake/modules/FindFstrcmp.cmake @@ -3,61 +3,58 @@ # -------- # Finds the fstrcmp library # -# This will define the following variables:: +# This will define the following target: # -# FSTRCMP_FOUND - system has libfstrcmp -# FSTRCMP_INCLUDE_DIRS - the libfstrcmp include directory -# FSTRCMP_LIBRARIES - the libfstrcmp libraries +# fstrcmp::fstrcmp - The fstrcmp library # -if(ENABLE_INTERNAL_FSTRCMP) - find_program(LIBTOOL libtool REQUIRED) - include(cmake/scripts/common/ModuleHelpers.cmake) +if(NOT TARGET fstrcmp::fstrcmp) + if(ENABLE_INTERNAL_FSTRCMP) + find_program(LIBTOOL libtool REQUIRED) + include(cmake/scripts/common/ModuleHelpers.cmake) - set(MODULE_LC fstrcmp) + set(MODULE_LC fstrcmp) - SETUP_BUILD_VARS() + SETUP_BUILD_VARS() - find_program(AUTORECONF autoreconf REQUIRED) + find_program(AUTORECONF autoreconf REQUIRED) - set(CONFIGURE_COMMAND ${AUTORECONF} -vif - COMMAND ./configure --prefix ${DEPENDS_PATH}) - set(BUILD_COMMAND make lib/libfstrcmp.la) - set(BUILD_IN_SOURCE 1) - set(INSTALL_COMMAND make install-libdir install-include) + set(CONFIGURE_COMMAND ${AUTORECONF} -vif + COMMAND ./configure --prefix ${DEPENDS_PATH}) + set(BUILD_COMMAND make lib/libfstrcmp.la) + set(BUILD_IN_SOURCE 1) + set(INSTALL_COMMAND make install-libdir install-include) - BUILD_DEP_TARGET() -else() - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_FSTRCMP fstrcmp QUIET) - endif() + BUILD_DEP_TARGET() + else() + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FSTRCMP fstrcmp QUIET) + endif() - find_path(FSTRCMP_INCLUDE_DIR NAMES fstrcmp.h - PATHS ${PC_FSTRCMP_INCLUDEDIR}) + find_path(FSTRCMP_INCLUDE_DIR NAMES fstrcmp.h + PATHS ${PC_FSTRCMP_INCLUDEDIR}) - find_library(FSTRCMP_LIBRARY NAMES fstrcmp - PATHS ${PC_FSTRCMP_LIBDIR}) + find_library(FSTRCMP_LIBRARY NAMES fstrcmp + PATHS ${PC_FSTRCMP_LIBDIR}) - set(FSTRCMP_VER ${PC_FSTRCMP_VERSION}) -endif() + set(FSTRCMP_VER ${PC_FSTRCMP_VERSION}) + endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Fstrcmp - REQUIRED_VARS FSTRCMP_LIBRARY FSTRCMP_INCLUDE_DIR - VERSION_VAR FSTRCMP_VER) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Fstrcmp + REQUIRED_VARS FSTRCMP_LIBRARY FSTRCMP_INCLUDE_DIR + VERSION_VAR FSTRCMP_VER) -if(FSTRCMP_FOUND) - set(FSTRCMP_INCLUDE_DIRS ${FSTRCMP_INCLUDE_DIR}) - set(FSTRCMP_LIBRARIES ${FSTRCMP_LIBRARY}) + add_library(fstrcmp::fstrcmp UNKNOWN IMPORTED) + set_target_properties(fstrcmp::fstrcmp PROPERTIES + IMPORTED_LOCATION "${FSTRCMP_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${FSTRCMP_INCLUDE_DIR}") - if(NOT TARGET fstrcmp) - add_library(fstrcmp UNKNOWN IMPORTED) - set_target_properties(fstrcmp PROPERTIES - IMPORTED_LOCATION "${FSTRCMP_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${FSTRCMP_INCLUDE_DIR}") + if(TARGET fstrcmp) + add_dependencies(fstrcmp::fstrcmp fstrcmp) endif() - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fstrcmp) + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fstrcmp::fstrcmp) endif() mark_as_advanced(FSTRCMP_INCLUDE_DIR FSTRCMP_LIBRARY) diff --git a/cmake/modules/FindLibAndroidJNI.cmake b/cmake/modules/FindLibAndroidJNI.cmake index 506e70fe095d6..8d240b7e2a193 100644 --- a/cmake/modules/FindLibAndroidJNI.cmake +++ b/cmake/modules/FindLibAndroidJNI.cmake @@ -2,39 +2,39 @@ # ------- # Finds the LibAndroidJNI library # -# This will define the following variables:: +# This will define the following target: # -# LIBANDROIDJNI_FOUND - system has LibAndroidJNI -# LIBANDROIDJNI_INCLUDE_DIRS - the LibAndroidJNI include directory -# LIBANDROIDJNI_LIBRARIES - the LibAndroidJNI libraries -# -# and the following imported targets:: -# -# libandroidjni - The LibAndroidJNI library +# libandroidjni::libandroidjni - The LibAndroidJNI library + +if(NOT TARGET libandroidjni::libandroidjni) + include(cmake/scripts/common/ModuleHelpers.cmake) + + set(MODULE_LC libandroidjni) -include(cmake/scripts/common/ModuleHelpers.cmake) + SETUP_BUILD_VARS() -set(MODULE_LC libandroidjni) + set(LIBANDROIDJNI_BUILD_TYPE Release) -SETUP_BUILD_VARS() + # We still need to supply SOMETHING to CMAKE_ARGS to initiate a cmake BUILD_DEP_TARGET + # Setting cmake_build_type twice wont cause issues + set(CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release) -set(LIBANDROIDJNI_BUILD_TYPE Release) + BUILD_DEP_TARGET() -# We still need to supply SOMETHING to CMAKE_ARGS to initiate a cmake BUILD_DEP_TARGET -# Setting cmake_build_type twice wont cause issues -set(CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(LibAndroidJNI + REQUIRED_VARS LIBANDROIDJNI_LIBRARY LIBANDROIDJNI_INCLUDE_DIR + VERSION_VAR LIBANDROIDJNI_VER) -BUILD_DEP_TARGET() + add_library(libandroidjni::libandroidjni STATIC IMPORTED) + set_target_properties(libandroidjni::libandroidjni PROPERTIES + FOLDER "External Projects" + IMPORTED_LOCATION "${LIBANDROIDJNI_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBANDROIDJNI_INCLUDE_DIR}") -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LibAndroidJNI - REQUIRED_VARS LIBANDROIDJNI_LIBRARY LIBANDROIDJNI_INCLUDE_DIR - VERSION_VAR LIBANDROIDJNI_VER) + add_dependencies(libandroidjni::libandroidjni libandroidjni) -if(LIBANDROIDJNI_FOUND) - set(LIBANDROIDJNI_LIBRARIES ${LIBANDROIDJNI_LIBRARY}) - set(LIBANDROIDJNI_INCLUDE_DIRS ${LIBANDROIDJNI_INCLUDE_DIR}) + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP libandroidjni::libandroidjni) - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP libandroidjni) + mark_as_advanced(LIBANDROIDJNI_INCLUDE_DIR LIBANDROIDJNI_LIBRARY) endif() -mark_as_advanced(LIBANDROIDJNI_INCLUDE_DIR LIBANDROIDJNI_LIBRARY) diff --git a/cmake/modules/FindLibDvdCSS.cmake b/cmake/modules/FindLibDvdCSS.cmake index ee3b7536beadf..df7ec6ad1f1b4 100644 --- a/cmake/modules/FindLibDvdCSS.cmake +++ b/cmake/modules/FindLibDvdCSS.cmake @@ -100,16 +100,12 @@ find_package_handle_standard_args(LibDvdCSS VERSION_VAR LIBDVDCSS_VERSION) if(LIBDVDCSS_FOUND) - set(LIBDVDCSS_INCLUDE_DIRS ${LIBDVDCSS_INCLUDE_DIR}) - set(LIBDVDCSS_LIBRARIES ${LIBDVDCSS_LIBRARY}) - set(LIBDVDCSS_DEFINITIONS -DHAVE_DVDCSS_DVDCSS_H) - if(NOT TARGET LibDvdCSS::LibDvdCSS) add_library(LibDvdCSS::LibDvdCSS UNKNOWN IMPORTED) set_target_properties(LibDvdCSS::LibDvdCSS PROPERTIES IMPORTED_LOCATION "${LIBDVDCSS_LIBRARY}" - INTERFACE_COMPILE_DEFINITIONS "${LIBDVDCSS_DEFINITIONS}" + INTERFACE_COMPILE_DEFINITIONS "HAVE_DVDCSS_DVDCSS_H" INTERFACE_INCLUDE_DIRECTORIES "${LIBDVDCSS_INCLUDE_DIR}") if(TARGET libdvdcss) diff --git a/cmake/modules/FindLibDvdNav.cmake b/cmake/modules/FindLibDvdNav.cmake index 56f9537995353..4a07d3ca56e57 100644 --- a/cmake/modules/FindLibDvdNav.cmake +++ b/cmake/modules/FindLibDvdNav.cmake @@ -73,7 +73,11 @@ if(NOT TARGET LibDvdNav::LibDvdNav) ${LIBDVD_ADDITIONAL_ARGS}) else() - string(APPEND LIBDVDNAV_CFLAGS " -I$ $") + string(APPEND LIBDVDNAV_CFLAGS " -I$") + + if(TARGET LibDvdCSS::LibDvdCSS) + string(APPEND LIBDVDNAV_CFLAGS " -I$ $<$:-D$>") + endif() find_program(AUTORECONF autoreconf REQUIRED) if (CMAKE_HOST_SYSTEM_NAME MATCHES "(Free|Net|Open)BSD") @@ -116,20 +120,11 @@ find_package_handle_standard_args(LibDvdNav VERSION_VAR LIBDVDNAV_VERSION) if(LIBDVDNAV_FOUND) - set(LIBDVDNAV_INCLUDE_DIRS ${LIBDVDNAV_INCLUDE_DIR}) - set(LIBDVDNAV_LIBRARIES ${LIBDVDNAV_LIBRARY}) - set(LIBDVDNAV_DEFINITIONS -D_XBMC) - - if(APPLE) - string(APPEND LIBDVDNAV_DEFINITIONS " -D__DARWIN__") - endif() - if(NOT TARGET LibDvdNav::LibDvdNav) add_library(LibDvdNav::LibDvdNav UNKNOWN IMPORTED) set_target_properties(LibDvdNav::LibDvdNav PROPERTIES IMPORTED_LOCATION "${LIBDVDNAV_LIBRARY}" - INTERFACE_COMPILE_DEFINITIONS "${LIBDVDNAV_DEFINITIONS}" INTERFACE_INCLUDE_DIRECTORIES "${LIBDVDNAV_INCLUDE_DIR}") if(TARGET libdvdnav) diff --git a/cmake/modules/FindLibDvdRead.cmake b/cmake/modules/FindLibDvdRead.cmake index eeca81c238ce4..c9ffb3cc12ab4 100644 --- a/cmake/modules/FindLibDvdRead.cmake +++ b/cmake/modules/FindLibDvdRead.cmake @@ -76,7 +76,7 @@ if(NOT TARGET LibDvdRead::LibDvdRead) else() if(TARGET LibDvdCSS::LibDvdCSS) - string(APPEND LIBDVDREAD_CFLAGS " -I$ $") + string(APPEND LIBDVDREAD_CFLAGS " -I$ $<$:-D$>") string(APPEND with-css "--with-libdvdcss") endif() @@ -122,20 +122,11 @@ find_package_handle_standard_args(LibDvdRead VERSION_VAR LIBDVDREAD_VERSION) if(LIBDVDREAD_FOUND) - set(LIBDVDREAD_INCLUDE_DIRS ${LIBDVDREAD_INCLUDE_DIR}) - set(LIBDVDREAD_LIBRARIES ${LIBDVDREAD_LIBRARY}) - set(LIBDVDREAD_DEFINITIONS -D_XBMC) - - if(APPLE) - string(APPEND LIBDVDREAD_DEFINITIONS " -D__DARWIN__") - endif() - if(NOT TARGET LibDvdRead::LibDvdRead) add_library(LibDvdRead::LibDvdRead UNKNOWN IMPORTED) set_target_properties(LibDvdRead::LibDvdRead PROPERTIES IMPORTED_LOCATION "${LIBDVDREAD_LIBRARY}" - INTERFACE_COMPILE_DEFINITIONS "${LIBDVDREAD_DEFINITIONS}" INTERFACE_INCLUDE_DIRECTORIES "${LIBDVDREAD_INCLUDE_DIR}") if(TARGET libdvdread) @@ -144,7 +135,7 @@ if(LIBDVDREAD_FOUND) if(TARGET LibDvdCSS::LibDvdCSS) add_dependencies(LibDvdRead::LibDvdRead LibDvdCSS::LibDvdCSS) set_target_properties(LibDvdRead::LibDvdRead PROPERTIES - INTERFACE_LINK_LIBRARIES "-ldvdcss") + INTERFACE_LINK_LIBRARIES "dvdcss") endif() endif() diff --git a/cmake/modules/FindLibZip.cmake b/cmake/modules/FindLibZip.cmake index df2d0428cea6a..6423c29be118e 100644 --- a/cmake/modules/FindLibZip.cmake +++ b/cmake/modules/FindLibZip.cmake @@ -63,6 +63,12 @@ if(LIBZIP_FOUND) if(TARGET libzip) add_dependencies(libzip::zip libzip) endif() + else() + # ToDo: When we correctly import dependencies cmake targets for the following + # BZip2::BZip2, LibLZMA::LibLZMA, GnuTLS::GnuTLS, Nettle::Nettle,ZLIB::ZLIB + # For now, we just override + set_target_properties(libzip::zip PROPERTIES + INTERFACE_LINK_LIBRARIES "") endif() set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP libzip::zip) else() diff --git a/cmake/modules/FindNFS.cmake b/cmake/modules/FindNFS.cmake index 11767fc563a07..b2233a170d1b8 100644 --- a/cmake/modules/FindNFS.cmake +++ b/cmake/modules/FindNFS.cmake @@ -3,28 +3,26 @@ # ------- # Finds the libnfs library # -# This will define the following variables:: -# -# NFS_FOUND - system has libnfs -# NFS_INCLUDE_DIRS - the libnfs include directory -# NFS_LIBRARIES - the libnfs libraries -# NFS_DEFINITIONS - the libnfs compile definitions -# -# and the following imported targets:: +# This will define the following target: # # NFS::NFS - The libnfs library -include(cmake/scripts/common/ModuleHelpers.cmake) +if(NOT TARGET libnfs::nfs) + + include(cmake/scripts/common/ModuleHelpers.cmake) -set(MODULE_LC libnfs) + set(MODULE_LC libnfs) -SETUP_BUILD_VARS() + SETUP_BUILD_VARS() -# Search for cmake config. Suitable for all platforms including windows -find_package(LIBNFS CONFIG QUIET) + # Search for cmake config. Suitable for all platforms including windows + find_package(libnfs CONFIG QUIET) + + # Check for existing TINYXML2. If version >= TINYXML2-VERSION file version, dont build + # A corner case, but if a linux/freebsd user WANTS to build internal tinyxml2, build anyway + if((libnfs_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_NFS) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_NFS)) -if(NOT LIBNFS_FOUND) - if(ENABLE_INTERNAL_NFS) set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DENABLE_TESTS=OFF -DENABLE_DOCUMENTATION=OFF @@ -33,85 +31,111 @@ if(NOT LIBNFS_FOUND) BUILD_DEP_TARGET() - set(NFS_LIBRARY ${${MODULE}_LIBRARY}) - set(NFS_INCLUDE_DIR ${${MODULE}_INCLUDE_DIR}) + set(_nfs_definitions HAS_NFS_SET_TIMEOUT + HAS_NFS_MOUNT_GETEXPORTS_TIMEOUT) else() - # Try pkgconfig based search. Linux may not have a version with cmake config installed - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_NFS libnfs>=3.0.0 QUIET) + if(NOT TARGET libnfs::nfs) + # Try pkgconfig based search as last resort + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_LIBNFS libnfs>=3.0.0 QUIET) + endif() + + find_library(LIBNFS_LIBRARY_RELEASE NAMES nfs libnfs + HINTS ${DEPENDS_PATH}/lib + ${PC_LIBNFS_LIBDIR}) + set(LIBNFS_VERSION ${PC_LIBNFS_VERSION}) endif() - find_path(NFS_INCLUDE_DIR nfsc/libnfs.h - PATHS ${PC_NFS_INCLUDEDIR}) - - set(LIBNFS_VERSION ${PC_NFS_VERSION}) - - find_library(NFS_LIBRARY NAMES nfs libnfs - PATHS ${PC_NFS_LIBDIR}) - endif() -else() - # Find lib and path as we cant easily rely on cmake-config - find_library(NFS_LIBRARY NAMES nfs libnfs - PATHS ${DEPENDS_PATH}/lib) - find_path(NFS_INCLUDE_DIR nfsc/libnfs.h PATHS ${DEPENDS_PATH}/include) -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(NFS - REQUIRED_VARS NFS_LIBRARY NFS_INCLUDE_DIR - VERSION_VAR LIBNFS_VERSION) - -if(NFS_FOUND) - set(NFS_LIBRARIES ${NFS_LIBRARY}) - set(NFS_INCLUDE_DIRS ${NFS_INCLUDE_DIR}) - set(NFS_DEFINITIONS -DHAS_FILESYSTEM_NFS=1) - - set(CMAKE_REQUIRED_INCLUDES "${NFS_INCLUDE_DIR}") - set(CMAKE_REQUIRED_LIBRARIES ${NFS_LIBRARY}) - - # Check for nfs_set_timeout - check_cxx_source_compiles(" - ${NFS_CXX_INCLUDE} - #include - int main() - { - nfs_set_timeout(NULL, 0); - } - " NFS_SET_TIMEOUT) - - if(NFS_SET_TIMEOUT) - list(APPEND NFS_DEFINITIONS -DHAS_NFS_SET_TIMEOUT) + find_path(LIBNFS_INCLUDE_DIR nfsc/libnfs.h HINTS ${PC_LIBNFS_INCLUDEDIR} + ${DEPENDS_PATH}/include) endif() - # Check for mount_getexports_timeout - check_cxx_source_compiles(" - ${NFS_CXX_INCLUDE} - #include - int main() - { - mount_getexports_timeout(NULL, 0); - } - " NFS_MOUNT_GETEXPORTS_TIMEOUT) - - if(NFS_MOUNT_GETEXPORTS_TIMEOUT) - list(APPEND NFS_DEFINITIONS -DHAS_NFS_MOUNT_GETEXPORTS_TIMEOUT) + if(TARGET libnfs::nfs) + # This is for the case where a distro provides a non standard (Debug/Release) config type + # convert this back to either DEBUG/RELEASE or just RELEASE + # we only do this because we use find_package_handle_standard_args for config time output + # and it isnt capable of handling TARGETS, so we have to extract the info + get_target_property(_LIBNFS_CONFIGURATIONS libnfs::nfs IMPORTED_CONFIGURATIONS) + foreach(_libnfs_config IN LISTS _LIBNFS_CONFIGURATIONS) + # Just set to RELEASE var so select_library_configurations can continue to work its magic + string(TOUPPER ${_libnfs_config} _libnfs_config_UPPER) + if((NOT ${_libnfs_config_UPPER} STREQUAL "RELEASE") AND + (NOT ${_libnfs_config_UPPER} STREQUAL "DEBUG")) + get_target_property(LIBNFS_LIBRARY_RELEASE libnfs::nfs IMPORTED_LOCATION_${_libnfs_config_UPPER}) + else() + get_target_property(LIBNFS_LIBRARY_${_libnfs_config_UPPER} libnfs::nfs IMPORTED_LOCATION_${_libnfs_config_UPPER}) + endif() + endforeach() endif() - unset(CMAKE_REQUIRED_INCLUDES) - unset(CMAKE_REQUIRED_LIBRARIES) + include(SelectLibraryConfigurations) + select_library_configurations(LIBNFS) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(NFS + REQUIRED_VARS LIBNFS_LIBRARY LIBNFS_INCLUDE_DIR + VERSION_VAR LIBNFS_VERSION) + + if(NFS_FOUND) + # Pre existing lib, so we can run checks + if(NOT TARGET libnfs) + set(CMAKE_REQUIRED_INCLUDES "${LIBNFS_INCLUDE_DIR}") + set(CMAKE_REQUIRED_LIBRARIES ${LIBNFS_LIBRARY}) + + # Check for nfs_set_timeout + check_cxx_source_compiles(" + ${LIBNFS_CXX_INCLUDE} + #include + int main() + { + nfs_set_timeout(NULL, 0); + } + " NFS_SET_TIMEOUT) + + if(NFS_SET_TIMEOUT) + list(APPEND _nfs_definitions HAS_NFS_SET_TIMEOUT) + endif() + + # Check for mount_getexports_timeout + check_cxx_source_compiles(" + ${LIBNFS_CXX_INCLUDE} + #include + int main() + { + mount_getexports_timeout(NULL, 0); + } + " NFS_MOUNT_GETEXPORTS_TIMEOUT) + + if(NFS_MOUNT_GETEXPORTS_TIMEOUT) + list(APPEND _nfs_definitions HAS_NFS_MOUNT_GETEXPORTS_TIMEOUT) + endif() + + unset(CMAKE_REQUIRED_INCLUDES) + unset(CMAKE_REQUIRED_LIBRARIES) + endif() - if(NOT TARGET NFS::NFS) - add_library(NFS::NFS UNKNOWN IMPORTED) + if(NOT TARGET libnfs::nfs) + add_library(libnfs::nfs UNKNOWN IMPORTED) + set_target_properties(libnfs::nfs PROPERTIES + IMPORTED_LOCATION "${LIBNFS_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBNFS_INCLUDE_DIR}") + endif() - set_target_properties(NFS::NFS PROPERTIES - IMPORTED_LOCATION "${NFS_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${NFS_INCLUDE_DIR}" - INTERFACE_COMPILE_DEFINITIONS "${NFS_DEFINITIONS}") if(TARGET libnfs) - add_dependencies(NFS::NFS libnfs) + add_dependencies(libnfs::nfs libnfs) endif() + + list(APPEND _nfs_definitions HAS_FILESYSTEM_NFS) + + # We need to append in case the cmake config already has definitions + set_property(TARGET libnfs::nfs APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS ${_nfs_definitions}) + + # Need to manually set this, as libnfs cmake config does not provide INTERFACE_INCLUDE_DIRECTORIES + set_target_properties(libnfs::nfs PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LIBNFS_INCLUDE_DIR}) + + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP libnfs::nfs) + + mark_as_advanced(LIBNFS_INCLUDE_DIR LIBNFS_LIBRARY) endif() - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP NFS::NFS) endif() - -mark_as_advanced(NFS_INCLUDE_DIR NFS_LIBRARY) diff --git a/cmake/modules/FindPCRE.cmake b/cmake/modules/FindPCRE.cmake index b2707ab0c21e3..f4c54aea8a300 100644 --- a/cmake/modules/FindPCRE.cmake +++ b/cmake/modules/FindPCRE.cmake @@ -3,106 +3,127 @@ # -------- # Finds the PCRECPP library # -# This will define the following variables:: -# -# PCRE_FOUND - system has libpcrecpp -# PCRE_INCLUDE_DIRS - the libpcrecpp include directory -# PCRE_LIBRARIES - the libpcrecpp libraries -# PCRE_DEFINITIONS - the libpcrecpp definitions -# -# and the following imported targets:: +# This will define the following targets: # # PCRE::PCRECPP - The PCRECPP library # PCRE::PCRE - The PCRE library -if(NOT PCRE::PCRE) - if(ENABLE_INTERNAL_PCRE) - include(cmake/scripts/common/ModuleHelpers.cmake) +if(NOT PCRE::pcre) - set(MODULE_LC pcre) + include(cmake/scripts/common/ModuleHelpers.cmake) - SETUP_BUILD_VARS() + set(MODULE_LC pcre) - # Check for existing PCRE. If version >= PCRE-VERSION file version, dont build - find_package(PCRE CONFIG QUIET) + SETUP_BUILD_VARS() - if(PCRE_VERSION VERSION_LESS ${${MODULE}_VER}) + # Check for existing PCRE. If version >= PCRE-VERSION file version, dont build + find_package(PCRE CONFIG QUIET) - set(PCRE_VERSION ${${MODULE}_VER}) - set(PCRE_DEBUG_POSTFIX d) + if((PCRE_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_PCRE) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_PCRE)) - set(patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-all-cmakeconfig.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/002-all-enable_docs_pc.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/003-all-postfix.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/004-win-pdb.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/jit_aarch64.patch") + set(PCRE_VERSION ${${MODULE}_VER}) + set(PCRE_DEBUG_POSTFIX d) - if(CORE_SYSTEM_NAME STREQUAL darwin_embedded) - list(APPEND patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/tvos-bitcode-fix.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/ios-clear_cache.patch") - endif() - - generate_patchcommand("${patches}") - - set(CMAKE_ARGS -DPCRE_NEWLINE=ANYCRLF - -DPCRE_NO_RECURSE=ON - -DPCRE_MATCH_LIMIT_RECURSION=1500 - -DPCRE_SUPPORT_JIT=ON - -DPCRE_SUPPORT_PCREGREP_JIT=ON - -DPCRE_SUPPORT_UTF=ON - -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON - -DPCRE_SUPPORT_LIBZ=OFF - -DPCRE_SUPPORT_LIBBZ2=OFF - -DPCRE_BUILD_PCREGREP=OFF - -DPCRE_BUILD_TESTS=OFF) - - if(WIN32 OR WINDOWS_STORE) - list(APPEND CMAKE_ARGS -DINSTALL_MSVC_PDB=ON) - elseif(CORE_SYSTEM_NAME STREQUAL android) - # CMake CheckFunctionExists incorrectly detects strtoq for android - list(APPEND CMAKE_ARGS -DHAVE_STRTOQ=0) - endif() + set(patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-all-cmakeconfig.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/002-all-enable_docs_pc.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/003-all-postfix.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/004-win-pdb.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/jit_aarch64.patch") - # populate PCRECPP lib without a separate module - if(NOT CORE_SYSTEM_NAME MATCHES windows) - # Non windows platforms have a lib prefix for the lib artifact - set(_libprefix "lib") - endif() - # regex used to get platform extension (eg lib for windows, .a for unix) - string(REGEX REPLACE "^.*\\." "" _LIBEXT ${${MODULE}_BYPRODUCT}) - set(PCRECPP_LIBRARY_DEBUG ${DEP_LOCATION}/lib/${_libprefix}pcrecpp${${MODULE}_DEBUG_POSTFIX}.${_LIBEXT}) - set(PCRECPP_LIBRARY_RELEASE ${DEP_LOCATION}/lib/${_libprefix}pcrecpp.${_LIBEXT}) + if(CORE_SYSTEM_NAME STREQUAL darwin_embedded) + list(APPEND patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/tvos-bitcode-fix.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/ios-clear_cache.patch") + endif() - BUILD_DEP_TARGET() + generate_patchcommand("${patches}") + + set(CMAKE_ARGS -DPCRE_NEWLINE=ANYCRLF + -DPCRE_NO_RECURSE=ON + -DPCRE_MATCH_LIMIT_RECURSION=1500 + -DPCRE_SUPPORT_JIT=ON + -DPCRE_SUPPORT_PCREGREP_JIT=ON + -DPCRE_SUPPORT_UTF=ON + -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON + -DPCRE_SUPPORT_LIBZ=OFF + -DPCRE_SUPPORT_LIBBZ2=OFF + -DPCRE_BUILD_PCREGREP=OFF + -DPCRE_BUILD_TESTS=OFF) + + if(WIN32 OR WINDOWS_STORE) + list(APPEND CMAKE_ARGS -DINSTALL_MSVC_PDB=ON) + elseif(CORE_SYSTEM_NAME STREQUAL android) + # CMake CheckFunctionExists incorrectly detects strtoq for android + list(APPEND CMAKE_ARGS -DHAVE_STRTOQ=0) + endif() - else() - # Populate paths for find_package_handle_standard_args - find_path(PCRE_INCLUDE_DIR pcre.h) + # populate PCRECPP lib without a separate module + if(NOT CORE_SYSTEM_NAME MATCHES windows) + # Non windows platforms have a lib prefix for the lib artifact + set(_libprefix "lib") + endif() + # regex used to get platform extension (eg lib for windows, .a for unix) + string(REGEX REPLACE "^.*\\." "" _LIBEXT ${${MODULE}_BYPRODUCT}) + set(PCRECPP_LIBRARY_DEBUG ${DEP_LOCATION}/lib/${_libprefix}pcrecpp${${MODULE}_DEBUG_POSTFIX}.${_LIBEXT}) + set(PCRECPP_LIBRARY_RELEASE ${DEP_LOCATION}/lib/${_libprefix}pcrecpp.${_LIBEXT}) - find_library(PCRECPP_LIBRARY_RELEASE NAMES pcrecpp) - find_library(PCRECPP_LIBRARY_DEBUG NAMES pcrecppd) + BUILD_DEP_TARGET() - find_library(PCRE_LIBRARY_RELEASE NAMES pcre) - find_library(PCRE_LIBRARY_DEBUG NAMES pcred) - endif() else() + if(NOT TARGET PCRE::pcre) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_PCRE pcre pcrecpp QUIET) + endif() - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_PCRE libpcrecpp QUIET) - endif() - - find_path(PCRE_INCLUDE_DIR pcrecpp.h - PATHS ${PC_PCRE_INCLUDEDIR}) - find_library(PCRECPP_LIBRARY_RELEASE NAMES pcrecpp + find_path(PCRE_INCLUDE_DIR pcrecpp.h + PATHS ${PC_PCRE_INCLUDEDIR}) + find_library(PCRECPP_LIBRARY_RELEASE NAMES pcrecpp + PATHS ${PC_PCRE_LIBDIR}) + find_library(PCRE_LIBRARY_RELEASE NAMES pcre + PATHS ${PC_PCRE_LIBDIR}) + find_library(PCRECPP_LIBRARY_DEBUG NAMES pcrecppd PATHS ${PC_PCRE_LIBDIR}) - find_library(PCRE_LIBRARY_RELEASE NAMES pcre + find_library(PCRE_LIBRARY_DEBUG NAMES pcred PATHS ${PC_PCRE_LIBDIR}) - find_library(PCRECPP_LIBRARY_DEBUG NAMES pcrecppd - PATHS ${PC_PCRE_LIBDIR}) - find_library(PCRE_LIBRARY_DEBUG NAMES pcred - PATHS ${PC_PCRE_LIBDIR}) - set(PCRE_VERSION ${PC_PCRE_VERSION}) + set(PCRE_VERSION ${PC_PCRE_VERSION}) + else() + + # Populate variables for find_package_handle_standard_args usage + get_target_property(_PCRE_CONFIGURATIONS PCRE::pcre IMPORTED_CONFIGURATIONS) + foreach(_pcre_config IN LISTS _PCRE_CONFIGURATIONS) + # Just set to RELEASE var so select_library_configurations can continue to work its magic + if((NOT ${_pcre_config} STREQUAL "RELEASE") AND + (NOT ${_pcre_config} STREQUAL "DEBUG")) + get_target_property(PCRE_LIBRARY_RELEASE PCRE::pcre IMPORTED_LOCATION_${_pcre_config}) + else() + get_target_property(PCRE_LIBRARY_${_pcre_config} PCRE::pcre IMPORTED_LOCATION_${_pcre_config}) + endif() + endforeach() + + get_target_property(_PCRECPP_CONFIGURATIONS PCRE::pcrecpp IMPORTED_CONFIGURATIONS) + foreach(_pcrecpp_config IN LISTS _PCRECPP_CONFIGURATIONS) + # Just set to RELEASE var so select_library_configurations can continue to work its magic + if((NOT ${_pcrecpp_config} STREQUAL "RELEASE") AND + (NOT ${_pcrecpp_config} STREQUAL "DEBUG")) + get_target_property(PCRECPP_LIBRARY_RELEASE PCRE::pcrecpp IMPORTED_LOCATION_${_pcrecpp_config}) + else() + get_target_property(PCRECPP_LIBRARY_${_pcrecpp_config} PCRE::pcrecpp IMPORTED_LOCATION_${_pcrecpp_config}) + endif() + endforeach() + + # ToDo: patch PCRE cmake to include includedir in config file + find_path(PCRE_INCLUDE_DIR pcrecpp.h + PATHS ${PC_PCRE_INCLUDEDIR}) + + set_target_properties(PCRE::pcre PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PCRE_INCLUDE_DIR}") + set_target_properties(PCRE::pcrecpp PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PCRE_INCLUDE_DIR}") + endif() + endif() + if(TARGET PCRE::pcre) + get_target_property(PCRE_INCLUDE_DIR PCRE::pcre INTERFACE_INCLUDE_DIRECTORIES) endif() include(SelectLibraryConfigurations) @@ -115,56 +136,51 @@ if(NOT PCRE::PCRE) VERSION_VAR PCRE_VERSION) if(PCRE_FOUND) - set(PCRE_LIBRARIES ${PCRECPP_LIBRARY} ${PCRE_LIBRARY}) - set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR}) - if(WIN32) - set(PCRE_DEFINITIONS -DPCRE_STATIC=1) - endif() - - if(NOT TARGET PCRE::PCRE) - add_library(PCRE::PCRE UNKNOWN IMPORTED) + if(NOT TARGET PCRE::pcre) + add_library(PCRE::pcre UNKNOWN IMPORTED) if(PCRE_LIBRARY_RELEASE) - set_target_properties(PCRE::PCRE PROPERTIES + set_target_properties(PCRE::pcre PROPERTIES IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION "${PCRE_LIBRARY_RELEASE}") + IMPORTED_LOCATION_RELEASE "${PCRE_LIBRARY_RELEASE}") endif() if(PCRE_LIBRARY_DEBUG) - set_target_properties(PCRE::PCRE PROPERTIES + set_target_properties(PCRE::pcre PROPERTIES IMPORTED_CONFIGURATIONS DEBUG - IMPORTED_LOCATION "${PCRE_LIBRARY_DEBUG}") + IMPORTED_LOCATION_DEBUG "${PCRE_LIBRARY_DEBUG}") endif() - set_target_properties(PCRE::PCRE PROPERTIES + set_target_properties(PCRE::pcre PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PCRE_INCLUDE_DIR}") - if(WIN32) - set_target_properties(PCRE::PCRE PROPERTIES - INTERFACE_COMPILE_DEFINITIONS PCRE_STATIC=1) - endif() - endif() - if(NOT TARGET PCRE::PCRECPP) - add_library(PCRE::PCRECPP UNKNOWN IMPORTED) - if(PCRE_LIBRARY_RELEASE) - set_target_properties(PCRE::PCRECPP PROPERTIES + if(NOT TARGET PCRE::pcrecpp) + add_library(PCRE::pcrecpp UNKNOWN IMPORTED) + if(PCRECPP_LIBRARY_RELEASE) + set_target_properties(PCRE::pcrecpp PROPERTIES IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION "${PCRECPP_LIBRARY_RELEASE}") + IMPORTED_LOCATION_RELEASE "${PCRECPP_LIBRARY_RELEASE}") endif() - if(PCRE_LIBRARY_DEBUG) - set_target_properties(PCRE::PCRECPP PROPERTIES + if(PCRECPP_LIBRARY_DEBUG) + set_target_properties(PCRE::pcrecpp PROPERTIES IMPORTED_CONFIGURATIONS DEBUG - IMPORTED_LOCATION "${PCRECPP_LIBRARY_DEBUG}") + IMPORTED_LOCATION_DEBUG "${PCRECPP_LIBRARY_DEBUG}") endif() - set_target_properties(PCRE::PCRECPP PROPERTIES - INTERFACE_LINK_LIBRARIES PCRE::PCRE) + set_target_properties(PCRE::pcrecpp PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PCRE_INCLUDE_DIR}") endif() - if(TARGET pcre) - add_dependencies(PCRE::PCRE pcre) + + # Wee need to explicitly add this define. The cmake config does not propagate this info + if(WIN32) + set_property(TARGET PCRE::pcre APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS "PCRE_STATIC=1") + set_property(TARGET PCRE::pcrecpp APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS "PCRE_STATIC=1") endif() - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP PCRE::PCRE) - else() - if(PCRE_FIND_REQUIRED) - message(FATAL_ERROR "PCRE not found. Possibly use -DENABLE_INTERNAL_PCRE=ON to build PCRE") + + if(TARGET pcre) + add_dependencies(PCRE::pcre pcre) + add_dependencies(PCRE::pcrecpp pcre) endif() - endif() - mark_as_advanced(PCRE_INCLUDE_DIR PCRECPP_LIBRARY PCRE_LIBRARY) + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP PCRE::pcre) + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP PCRE::pcrecpp) + endif() endif() diff --git a/cmake/modules/FindRapidJSON.cmake b/cmake/modules/FindRapidJSON.cmake index 2db5e687c21d1..4a84365748ce7 100644 --- a/cmake/modules/FindRapidJSON.cmake +++ b/cmake/modules/FindRapidJSON.cmake @@ -8,60 +8,71 @@ # RapidJSON_FOUND - system has RapidJSON parser # RapidJSON_INCLUDE_DIRS - the RapidJSON parser include directory # -if(ENABLE_INTERNAL_RapidJSON) - include(cmake/scripts/common/ModuleHelpers.cmake) - set(MODULE_LC rapidjson) +if(NOT TARGET RapidJSON::RapidJSON) + if(ENABLE_INTERNAL_RapidJSON) + include(cmake/scripts/common/ModuleHelpers.cmake) - SETUP_BUILD_VARS() + set(MODULE_LC rapidjson) - set(RapidJSON_VERSION ${${MODULE}_VER}) + SETUP_BUILD_VARS() - 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") + set(RapidJSON_VERSION ${${MODULE}_VER}) - generate_patchcommand("${patches}") + 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") - set(CMAKE_ARGS -DRAPIDJSON_BUILD_DOC=OFF - -DRAPIDJSON_BUILD_EXAMPLES=OFF - -DRAPIDJSON_BUILD_TESTS=OFF - -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=OFF) + generate_patchcommand("${patches}") - set(BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include/rapidjson/rapidjson.h) + set(CMAKE_ARGS -DRAPIDJSON_BUILD_DOC=OFF + -DRAPIDJSON_BUILD_EXAMPLES=OFF + -DRAPIDJSON_BUILD_TESTS=OFF + -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=OFF) - BUILD_DEP_TARGET() + set(BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include/rapidjson/rapidjson.h) - set(RapidJSON_INCLUDE_DIR ${${MODULE}_INCLUDE_DIR}) + BUILD_DEP_TARGET() - # Add dependency to libkodi to build - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP rapidjson) -else() - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_RapidJSON RapidJSON>=1.0.2 QUIET) - endif() + set(RAPIDJSON_INCLUDE_DIRS ${${MODULE}_INCLUDE_DIR}) - if(CORE_SYSTEM_NAME STREQUAL windows OR CORE_SYSTEM_NAME STREQUAL windowsstore) - set(RapidJSON_VERSION 1.1.0) else() - if(PC_RapidJSON_VERSION) - set(RapidJSON_VERSION ${PC_RapidJSON_VERSION}) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_RapidJSON RapidJSON>=1.0.2 QUIET) + endif() + + if(CORE_SYSTEM_NAME STREQUAL windows OR CORE_SYSTEM_NAME STREQUAL windowsstore) + set(RapidJSON_VERSION 1.1.0) else() - find_package(RapidJSON 1.1.0 CONFIG REQUIRED QUIET) + if(PC_RapidJSON_VERSION) + set(RapidJSON_VERSION ${PC_RapidJSON_VERSION}) + else() + find_package(RapidJSON 1.1.0 CONFIG REQUIRED QUIET) + endif() endif() + + find_path(RAPIDJSON_INCLUDE_DIRS NAMES rapidjson/rapidjson.h + PATHS ${PC_RapidJSON_INCLUDEDIR}) endif() - find_path(RapidJSON_INCLUDE_DIR NAMES rapidjson/rapidjson.h - PATHS ${PC_RapidJSON_INCLUDEDIR}) -endif() + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(RapidJSON + REQUIRED_VARS RAPIDJSON_INCLUDE_DIRS RapidJSON_VERSION + VERSION_VAR RapidJSON_VERSION) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(RapidJSON - REQUIRED_VARS RapidJSON_INCLUDE_DIR RapidJSON_VERSION - VERSION_VAR RapidJSON_VERSION) + if(RAPIDJSON_FOUND) + if(NOT TARGET RapidJSON::RapidJSON) + add_library(RapidJSON::RapidJSON INTERFACE IMPORTED) -if(RAPIDJSON_FOUND) - set(RAPIDJSON_INCLUDE_DIRS ${RapidJSON_INCLUDE_DIR}) -endif() + set_target_properties(RapidJSON::RapidJSON PROPERTIES + FOLDER "External Projects" + INTERFACE_INCLUDE_DIRECTORIES "${RAPIDJSON_INCLUDE_DIRS}") + endif() + if(TARGET rapidjson) + add_dependencies(RapidJSON::RapidJSON rapidjson) + endif() + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP RapidJSON::RapidJSON) + endif() -mark_as_advanced(RapidJSON_INCLUDE_DIR) + mark_as_advanced(RapidJSON_INCLUDE_DIR) +endif() diff --git a/cmake/modules/FindSpdlog.cmake b/cmake/modules/FindSpdlog.cmake index 0274d140e16ed..520c8abba757e 100644 --- a/cmake/modules/FindSpdlog.cmake +++ b/cmake/modules/FindSpdlog.cmake @@ -2,34 +2,41 @@ # ------- # Finds the Spdlog library # -# This will define the following variables: +# This will define the following target: # -# SPDLOG_FOUND - system has Spdlog -# SPDLOG_INCLUDE_DIRS - the Spdlog include directory -# SPDLOG_LIBRARIES - the Spdlog libraries -# SPDLOG_DEFINITIONS - the Spdlog compile definitions -# -# and the following imported targets: -# -# Spdlog::Spdlog - The Spdlog library +# spdlog::spdlog - The Spdlog library -if(ENABLE_INTERNAL_SPDLOG) +if(NOT TARGET spdlog::spdlog) include(cmake/scripts/common/ModuleHelpers.cmake) # Check for dependencies - Must be done before SETUP_BUILD_VARS - get_libversion_data("fmt" "target") - find_package(Fmt ${LIB_FMT_VER} MODULE REQUIRED) + # Todo: We might need a way to do this after SETUP_BUILD_VARS... + if(ENABLE_INTERNAL_SPDLOG) + get_libversion_data("fmt" "target") + find_package(Fmt ${LIB_FMT_VER} MODULE REQUIRED) + endif() - # Check if we want to force a build due to a dependency rebuild - get_property(LIB_FORCE_REBUILD TARGET fmt::fmt PROPERTY LIB_BUILD) + if(TARGET fmt::fmt) + # Check if we want to force a build due to a dependency rebuild + get_property(LIB_FORCE_REBUILD TARGET fmt::fmt PROPERTY LIB_BUILD) + endif() set(MODULE_LC spdlog) SETUP_BUILD_VARS() + # Darwin systems we want to avoid system packages. We are entirely self sufficient + # Avoids homebrew populating rubbish we cant control + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(_spdlog_find_option NO_SYSTEM_ENVIRONMENT_PATH) + endif() + # Check for existing SPDLOG. If version >= SPDLOG-VERSION file version, dont build - find_package(SPDLOG CONFIG QUIET) + find_package(SPDLOG ${_spdlog_find_option} CONFIG QUIET) + + if((SPDLOG_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_SPDLOG) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_SPDLOG) OR + LIB_FORCE_REBUILD) - if(SPDLOG_VERSION VERSION_LESS ${${MODULE}_VER} OR LIB_FORCE_REBUILD) if(APPLE) set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") endif() @@ -41,6 +48,8 @@ if(ENABLE_INTERNAL_SPDLOG) set(EXTRA_ARGS -DSPDLOG_WCHAR_SUPPORT=ON -DSPDLOG_WCHAR_FILENAMES=ON) + set(EXTRA_DEFINITIONS SPDLOG_WCHAR_FILENAMES + SPDLOG_WCHAR_TO_UTF8_SUPPORT) endif() set(SPDLOG_VERSION ${${MODULE}_VER}) @@ -55,74 +64,100 @@ if(ENABLE_INTERNAL_SPDLOG) -DSPDLOG_FMT_EXTERNAL=ON ${EXTRA_ARGS}) + # Set definitions that will be set in the built cmake config file + # We dont import the config file if we build internal (chicken/egg scenario) + set(_spdlog_definitions SPDLOG_COMPILED_LIB + SPDLOG_FMT_EXTERNAL + ${EXTRA_DEFINITIONS}) + BUILD_DEP_TARGET() add_dependencies(${MODULE_LC} fmt::fmt) else() - # Populate paths for find_package_handle_standard_args - find_path(SPDLOG_INCLUDE_DIR NAMES spdlog/spdlog.h) - find_library(SPDLOG_LIBRARY_RELEASE NAMES spdlog) - find_library(SPDLOG_LIBRARY_DEBUG NAMES spdlogd) + if(NOT TARGET spdlog::spdlog) + # Fallback to pkg-config and individual lib/include file search + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_SPDLOG spdlog QUIET) + set(SPDLOG_VERSION ${PC_SPDLOG_VERSION}) + endif() + + find_path(SPDLOG_INCLUDE_DIR NAMES spdlog/spdlog.h + PATHS ${PC_SPDLOG_INCLUDEDIR}) + + find_library(SPDLOG_LIBRARY_RELEASE NAMES spdlog + PATHS ${PC_SPDLOG_LIBDIR}) + find_library(SPDLOG_LIBRARY_DEBUG NAMES spdlogd + PATHS ${PC_SPDLOG_LIBDIR}) + + # Only add -D definitions. Skip -I include as we do a find_path for the header anyway + foreach(_spdlog_cflag IN LISTS PC_SPDLOG_CFLAGS) + if(${_spdlog_cflag} MATCHES "^-D(.*)") + list(APPEND _spdlog_definitions ${CMAKE_MATCH_1}) + endif() + endforeach() + endif() endif() -else() - find_package(spdlog 1.5.0 CONFIG REQUIRED QUIET) - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_SPDLOG spdlog QUIET) - set(SPDLOG_VERSION ${PC_SPDLOG_VERSION}) + if(TARGET spdlog::spdlog) + # This is for the case where a distro provides a non standard (Debug/Release) config type + # eg Debian's config file is spdlogConfigTargets-none.cmake + # convert this back to either DEBUG/RELEASE or just RELEASE + # we only do this because we use find_package_handle_standard_args for config time output + # and it isnt capable of handling TARGETS, so we have to extract the info + get_target_property(_SPDLOG_CONFIGURATIONS spdlog::spdlog IMPORTED_CONFIGURATIONS) + foreach(_spdlog_config IN LISTS _SPDLOG_CONFIGURATIONS) + # Some non standard config (eg None on Debian) + # Just set to RELEASE var so select_library_configurations can continue to work its magic + string(TOUPPER ${_spdlog_config} _spdlog_config_UPPER) + if((NOT ${_spdlog_config_UPPER} STREQUAL "RELEASE") AND + (NOT ${_spdlog_config_UPPER} STREQUAL "DEBUG")) + get_target_property(SPDLOG_LIBRARY_RELEASE spdlog::spdlog IMPORTED_LOCATION_${_spdlog_config_UPPER}) + else() + get_target_property(SPDLOG_LIBRARY_${_spdlog_config_UPPER} spdlog::spdlog IMPORTED_LOCATION_${_spdlog_config_UPPER}) + endif() + endforeach() + + get_target_property(SPDLOG_INCLUDE_DIR spdlog::spdlog INTERFACE_INCLUDE_DIRECTORIES) endif() - find_path(SPDLOG_INCLUDE_DIR NAMES spdlog/spdlog.h - PATHS ${PC_SPDLOG_INCLUDEDIR}) - - find_library(SPDLOG_LIBRARY_RELEASE NAMES spdlog - PATHS ${PC_SPDLOG_LIBDIR}) - find_library(SPDLOG_LIBRARY_DEBUG NAMES spdlogd - PATHS ${PC_SPDLOG_LIBDIR}) -endif() - -include(SelectLibraryConfigurations) -select_library_configurations(SPDLOG) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Spdlog - REQUIRED_VARS SPDLOG_LIBRARY SPDLOG_INCLUDE_DIR - VERSION_VAR SPDLOG_VERSION) - -if(SPDLOG_FOUND) - set(SPDLOG_LIBRARIES ${SPDLOG_LIBRARY}) - set(SPDLOG_INCLUDE_DIRS ${SPDLOG_INCLUDE_DIR}) - set(SPDLOG_DEFINITIONS -DSPDLOG_FMT_EXTERNAL - -DSPDLOG_DEBUG_ON - -DSPDLOG_NO_ATOMIC_LEVELS - -DSPDLOG_ENABLE_PATTERN_PADDING - -DSPDLOG_COMPILED_LIB - ${PC_SPDLOG_CFLAGS}) - if(WIN32) - list(APPEND SPDLOG_DEFINITIONS -DSPDLOG_WCHAR_FILENAMES - -DSPDLOG_WCHAR_TO_UTF8_SUPPORT) - endif() - - if(NOT TARGET spdlog::spdlog) - add_library(spdlog::spdlog UNKNOWN IMPORTED) - if(SPDLOG_LIBRARY_RELEASE) + include(SelectLibraryConfigurations) + select_library_configurations(SPDLOG) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Spdlog + REQUIRED_VARS SPDLOG_LIBRARY SPDLOG_INCLUDE_DIR + VERSION_VAR SPDLOG_VERSION) + + if(Spdlog_FOUND) + if(NOT TARGET spdlog::spdlog) + # Ideally we probably shouldnt be overriding these. We should trust the cmake config file + list(APPEND _spdlog_definitions SPDLOG_DEBUG_ON + SPDLOG_NO_ATOMIC_LEVELS) + + add_library(spdlog::spdlog UNKNOWN IMPORTED) + if(SPDLOG_LIBRARY_RELEASE) + set_target_properties(spdlog::spdlog PROPERTIES + IMPORTED_CONFIGURATIONS RELEASE + IMPORTED_LOCATION_RELEASE "${SPDLOG_LIBRARY_RELEASE}") + endif() + if(SPDLOG_LIBRARY_DEBUG) + set_target_properties(spdlog::spdlog PROPERTIES + IMPORTED_CONFIGURATIONS DEBUG + IMPORTED_LOCATION_DEBUG "${SPDLOG_LIBRARY_DEBUG}") + endif() set_target_properties(spdlog::spdlog PROPERTIES - IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION "${SPDLOG_LIBRARY_RELEASE}") + INTERFACE_INCLUDE_DIRECTORIES "${SPDLOG_INCLUDE_DIR}") + + # We need to append in case the cmake config already has definitions + set_property(TARGET spdlog::spdlog APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS "${_spdlog_definitions}") endif() - if(SPDLOG_LIBRARY_DEBUG) - set_target_properties(spdlog::spdlog PROPERTIES - IMPORTED_CONFIGURATIONS DEBUG - IMPORTED_LOCATION "${SPDLOG_LIBRARY_DEBUG}") + + if(TARGET spdlog) + add_dependencies(spdlog::spdlog spdlog) endif() - set_target_properties(spdlog::spdlog PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${SPDLOG_INCLUDE_DIR}" - INTERFACE_COMPILE_DEFINITIONS "${SPDLOG_DEFINITIONS}") - endif() - if(TARGET spdlog) - add_dependencies(spdlog::spdlog spdlog) endif() + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP spdlog::spdlog) -endif() -mark_as_advanced(SPDLOG_INCLUDE_DIR SPDLOG_LIBRARY) +endif() diff --git a/cmake/modules/FindSqlite3.cmake b/cmake/modules/FindSqlite3.cmake index 8fd9719ec7dbc..9b85e34f41a71 100644 --- a/cmake/modules/FindSqlite3.cmake +++ b/cmake/modules/FindSqlite3.cmake @@ -3,42 +3,36 @@ # ----------- # Finds the SQLite3 library # -# This will define the following variables:: -# -# SQLITE3_FOUND - system has SQLite3 -# SQLITE3_INCLUDE_DIRS - the SQLite3 include directory -# SQLITE3_LIBRARIES - the SQLite3 libraries -# -# and the following imported targets:: +# This will define the following target: # # SQLite3::SQLite3 - The SQLite3 library +# -if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_SQLITE3 sqlite3 QUIET) -endif() +if(NOT TARGET SQLite3::SQLite3) -find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h - PATHS ${PC_SQLITE3_INCLUDEDIR}) -find_library(SQLITE3_LIBRARY NAMES sqlite3 - PATHS ${PC_SQLITE3_LIBDIR}) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_SQLITE3 sqlite3 QUIET) + endif() -set(SQLITE3_VERSION ${PC_SQLITE3_VERSION}) + find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h + PATHS ${PC_SQLITE3_INCLUDEDIR}) + find_library(SQLITE3_LIBRARY NAMES sqlite3 + PATHS ${PC_SQLITE3_LIBDIR}) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Sqlite3 - REQUIRED_VARS SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR - VERSION_VAR SQLITE3_VERSION) + set(SQLITE3_VERSION ${PC_SQLITE3_VERSION}) -if(SQLITE3_FOUND) - set(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) - set(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Sqlite3 + REQUIRED_VARS SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR + VERSION_VAR SQLITE3_VERSION) - if(NOT TARGET SQLite3::SQLite3) + if(Sqlite3_FOUND) add_library(SQLite3::SQLite3 UNKNOWN IMPORTED) set_target_properties(SQLite3::SQLite3 PROPERTIES IMPORTED_LOCATION "${SQLITE3_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SQLITE3_INCLUDE_DIR}") + + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP SQLite3::SQLite3) endif() + mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY) endif() - -mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY) diff --git a/cmake/modules/FindTagLib.cmake b/cmake/modules/FindTagLib.cmake index 9caafaff03c89..e1b8745e4a749 100644 --- a/cmake/modules/FindTagLib.cmake +++ b/cmake/modules/FindTagLib.cmake @@ -3,97 +3,114 @@ # ---------- # Finds the TagLib library # -# This will define the following variables:: -# -# TAGLIB_FOUND - system has TagLib -# TAGLIB_INCLUDE_DIRS - the TagLib include directory -# TAGLIB_LIBRARIES - the TagLib libraries -# -# and the following imported targets:: +# This will define the following target: # # TagLib::TagLib - The TagLib library +# -if(ENABLE_INTERNAL_TAGLIB) - include(cmake/scripts/common/ModuleHelpers.cmake) +if(NOT TARGET TagLib::TagLib) + if(ENABLE_INTERNAL_TAGLIB) - set(MODULE_LC taglib) + # Suppress mismatch warning, see https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html + set(FPHSA_NAME_MISMATCHED 1) - SETUP_BUILD_VARS() + # Darwin systems use a system tbd that isnt found as a static lib + # Other platforms when using ENABLE_INTERNAL_TAGLIB, we want the static lib + if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") + # Requires cmake 3.24 for ZLIB_USE_STATIC_LIBS to actually do something + set(ZLIB_USE_STATIC_LIBS ON) + endif() + find_package(ZLIB REQUIRED) + unset(FPHSA_NAME_MISMATCHED) - set(TAGLIB_VERSION ${${MODULE}_VER}) + include(cmake/scripts/common/ModuleHelpers.cmake) - if(WIN32 OR WINDOWS_STORE) - set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-cmake-pdb-debug.patch") - generate_patchcommand("${patches}") + set(MODULE_LC taglib) - if(WINDOWS_STORE) - set(EXTRA_ARGS -DPLATFORM_WINRT=ON) - endif() - endif() + SETUP_BUILD_VARS() - # Debug postfix only used for windows - if(WIN32 OR WINDOWS_STORE) - set(TAGLIB_DEBUG_POSTFIX "d") - endif() + set(TAGLIB_VERSION ${${MODULE}_VER}) - set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF - -DBUILD_EXAMPLES=OFF - -DBUILD_TESTING=OFF - -DBUILD_BINDINGS=OFF - ${EXTRA_ARGS}) + if(WIN32 OR WINDOWS_STORE) + set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-cmake-pdb-debug.patch") + generate_patchcommand("${patches}") - BUILD_DEP_TARGET() + if(WINDOWS_STORE) + set(EXTRA_ARGS -DPLATFORM_WINRT=ON) + endif() + endif() -else() + # Debug postfix only used for windows + if(WIN32 OR WINDOWS_STORE) + set(TAGLIB_DEBUG_POSTFIX "d") + endif() - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_TAGLIB taglib>=1.9.0 QUIET) - endif() + set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF + -DBUILD_EXAMPLES=OFF + -DBUILD_TESTING=OFF + -DBUILD_BINDINGS=OFF + ${EXTRA_ARGS}) - find_path(TAGLIB_INCLUDE_DIR taglib/tag.h - PATHS ${PC_TAGLIB_INCLUDEDIR}) - find_library(TAGLIB_LIBRARY_RELEASE NAMES tag - PATHS ${PC_TAGLIB_LIBDIR}) - find_library(TAGLIB_LIBRARY_DEBUG NAMES tagd - PATHS ${PC_TAGLIB_LIBDIR}) - set(TAGLIB_VERSION ${PC_TAGLIB_VERSION}) + BUILD_DEP_TARGET() -endif() + add_dependencies(${MODULE_LC} ZLIB::ZLIB) + + else() + + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_TAGLIB taglib>=1.9.0 QUIET) + endif() -include(SelectLibraryConfigurations) -select_library_configurations(TAGLIB) + find_path(TAGLIB_INCLUDE_DIR taglib/tag.h PATHS ${PC_TAGLIB_INCLUDEDIR}) + find_library(TAGLIB_LIBRARY_RELEASE NAMES tag + PATHS ${PC_TAGLIB_LIBDIR}) + find_library(TAGLIB_LIBRARY_DEBUG NAMES tagd + PATHS ${PC_TAGLIB_LIBDIR}) + set(TAGLIB_VERSION ${PC_TAGLIB_VERSION}) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(TagLib - REQUIRED_VARS TAGLIB_LIBRARY TAGLIB_INCLUDE_DIR - VERSION_VAR TAGLIB_VERSION) + set(TAGLIB_LINK_LIBS ${PC_TAGLIB_LIBRARIES}) + endif() -if(TAGLIB_FOUND) - set(TAGLIB_INCLUDE_DIRS ${TAGLIB_INCLUDE_DIR}) - set(TAGLIB_LIBRARIES ${TAGLIB_LIBRARY}) + include(SelectLibraryConfigurations) + select_library_configurations(TAGLIB) - # Workaround broken .pc file - list(APPEND TAGLIB_LIBRARIES ${PC_TAGLIB_ZLIB_LIBRARIES}) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(TagLib + REQUIRED_VARS TAGLIB_LIBRARY TAGLIB_INCLUDE_DIR + VERSION_VAR TAGLIB_VERSION) - if(NOT TARGET TagLib::TagLib) + if(TagLib_FOUND) add_library(TagLib::TagLib UNKNOWN IMPORTED) if(TAGLIB_LIBRARY_RELEASE) set_target_properties(TagLib::TagLib PROPERTIES IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION "${TAGLIB_LIBRARY_RELEASE}") + IMPORTED_LOCATION_RELEASE "${TAGLIB_LIBRARY_RELEASE}") endif() if(TAGLIB_LIBRARY_DEBUG) set_target_properties(TagLib::TagLib PROPERTIES IMPORTED_CONFIGURATIONS DEBUG - IMPORTED_LOCATION "${TAGLIB_LIBRARY_DEBUG}") + IMPORTED_LOCATION_DEBUG "${TAGLIB_LIBRARY_DEBUG}") endif() set_target_properties(TagLib::TagLib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${TAGLIB_INCLUDE_DIR}") + + # if pkg-config returns link libs at to TARGET. For internal build, we use ZLIB::Zlib + # dependency explicitly + if(TAGLIB_LINK_LIBS) + set_target_properties(TagLib::TagLib PROPERTIES + INTERFACE_LINK_LIBRARIES "${TAGLIB_LINK_LIBS}") + endif() + if(TARGET taglib) add_dependencies(TagLib::TagLib taglib) endif() + + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP TagLib::TagLib) + else() + if(TagLib_FIND_REQUIRED) + message(FATAL_ERROR "TagLib not found.") + endif() endif() - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP TagLib::TagLib) + mark_as_advanced(TAGLIB_INCLUDE_DIR TAGLIB_LIBRARY) endif() -mark_as_advanced(TAGLIB_INCLUDE_DIR TAGLIB_LIBRARY) diff --git a/cmake/modules/FindTinyXML2.cmake b/cmake/modules/FindTinyXML2.cmake index 891a2e7b82e2e..d95a7343b6a67 100644 --- a/cmake/modules/FindTinyXML2.cmake +++ b/cmake/modules/FindTinyXML2.cmake @@ -3,7 +3,6 @@ # ----------- # Finds the TinyXML2 library # -# # This will define the following target: # # tinyxml2::tinyxml2 - The TinyXML2 library @@ -15,111 +14,91 @@ if(NOT TARGET tinyxml2::tinyxml2) SETUP_BUILD_VARS() - # Check for existing TINYXML2. If version >= TINYXML2-VERSION file version, dont build - # A corner case, but if a linux/freebsd user WANTS to build internal tinyxml2, skip the - # config search and act like tinyxml2 doesnt exist on system - if(NOT ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_TINYXML2)) - - # Darwin systems we want to avoid system packages. We are entirely self sufficient - # Avoids homebrew populating rubbish we cant control - if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(_tinyxml2_find_option NO_SYSTEM_ENVIRONMENT_PATH) - endif() - - find_package(TINYXML2 ${_tinyxml2_find_option} CONFIG QUIET) + # Darwin systems we want to avoid system packages. We are entirely self sufficient + # Avoids homebrew populating rubbish we cant control + # Do we want to set this for all except LINUX/FREEBSD possibly? + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(_tinyxml2_find_option NO_SYSTEM_ENVIRONMENT_PATH) endif() - # Some linux distro's dont package cmake config files for TinyXML2 - # This means that they will fall into the below and we will run a pkg_check_modules - # for one last search - if(TINYXML2_VERSION VERSION_LESS ${${MODULE}_VER}) - - if(ENABLE_INTERNAL_TINYXML2) - set(TINYXML2_VERSION ${${MODULE}_VER}) - set(TINYXML2_DEBUG_POSTFIX d) - - find_package(Patch MODULE REQUIRED) - - if(UNIX) - # ancient patch (Apple/freebsd) fails to patch tinyxml2 CMakeLists.txt file due to it being crlf encoded - # Strip crlf before applying patches. - # Freebsd fails even harder and requires both .patch and CMakeLists.txt to be crlf stripped - # possibly add requirement for freebsd on gpatch? Wouldnt need to copy/strip the patch file then - set(PATCH_COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/CMakeLists.txt - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch - COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch - COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch) - else() - set(PATCH_COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch) - endif() + find_package(TINYXML2 ${_tinyxml2_find_option} CONFIG QUIET) - if(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR STREQUAL Xcode) - # Multiconfig generators fail due to file(GENERATE tinyxml.pc) command. - # This patch makes it generate a distinct named pc file for each build type and rename - # pc file on install - list(APPEND PATCH_COMMAND COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/002-multiconfig-gen-pkgconfig.patch) - endif() - - set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} - -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -Dtinyxml2_BUILD_TESTING=OFF) - - BUILD_DEP_TARGET() + # Check for existing TINYXML2. If version >= TINYXML2-VERSION file version, dont build + # A corner case, but if a linux/freebsd user WANTS to build internal tinyxml2, build anyway + if((TINYXML2_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_TINYXML2) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_TINYXML2)) + + set(TINYXML2_VERSION ${${MODULE}_VER}) + set(TINYXML2_DEBUG_POSTFIX d) + + find_package(Patch MODULE REQUIRED) + + if(UNIX) + # ancient patch (Apple/freebsd) fails to patch tinyxml2 CMakeLists.txt file due to it being crlf encoded + # Strip crlf before applying patches. + # Freebsd fails even harder and requires both .patch and CMakeLists.txt to be crlf stripped + # possibly add requirement for freebsd on gpatch? Wouldnt need to copy/strip the patch file then + set(PATCH_COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/CMakeLists.txt + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch + COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch + COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch) else() - # This is the fallback case where linux distro's dont ship cmake config files - # use the old find_library way. Only do this if we didnt find a cmake config - # in the event of the version < depends version - if(NOT TARGET tinyxml2::tinyxml2) - if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_TINYXML2 tinyxml2 QUIET) - endif() - - find_path(TINYXML2_INCLUDE_DIR tinyxml2.h - PATHS ${PC_TINYXML2_INCLUDEDIR}) - find_library(TINYXML2_LIBRARY_RELEASE NAMES tinyxml2 - PATHS ${PC_TINYXML2_LIBDIR}) - find_library(TINYXML2_LIBRARY_DEBUG NAMES tinyxml2d - PATHS ${PC_TINYXML2_LIBDIR}) + set(PATCH_COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch) + endif() - set(TINYXML2_VERSION ${PC_TINYXML2_VERSION}) - endif() + if(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR STREQUAL Xcode) + # Multiconfig generators fail due to file(GENERATE tinyxml.pc) command. + # This patch makes it generate a distinct named pc file for each build type and rename + # pc file on install + list(APPEND PATCH_COMMAND COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/002-multiconfig-gen-pkgconfig.patch) endif() + set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} + -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -Dtinyxml2_BUILD_TESTING=OFF) + + BUILD_DEP_TARGET() + else() + # This is the fallback case where linux distro's dont ship cmake config files + # use the old find_library way. Only do this if we didnt find a cmake config + # in the event of the version < depends version if(NOT TARGET tinyxml2::tinyxml2) - add_library(tinyxml2::tinyxml2 UNKNOWN IMPORTED) - if(TINYXML2_LIBRARY_RELEASE) - set_target_properties(tinyxml2::tinyxml2 PROPERTIES - IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION_RELEASE "${TINYXML2_LIBRARY_RELEASE}") + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_TINYXML2 tinyxml2 QUIET) endif() - if(TINYXML2_LIBRARY_DEBUG) - set_target_properties(tinyxml2::tinyxml2 PROPERTIES - IMPORTED_CONFIGURATIONS DEBUG - IMPORTED_LOCATION_DEBUG "${TINYXML2_LIBRARY_DEBUG}") - endif() - set_target_properties(tinyxml2::tinyxml2 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${TINYXML2_INCLUDE_DIR}") - endif() - if(TARGET tinyxml2) - add_dependencies(tinyxml2::tinyxml2 tinyxml2) + find_path(TINYXML2_INCLUDE_DIR tinyxml2.h + PATHS ${PC_TINYXML2_INCLUDEDIR}) + find_library(TINYXML2_LIBRARY_RELEASE NAMES tinyxml2 + PATHS ${PC_TINYXML2_LIBDIR}) + find_library(TINYXML2_LIBRARY_DEBUG NAMES tinyxml2d + PATHS ${PC_TINYXML2_LIBDIR}) + + set(TINYXML2_VERSION ${PC_TINYXML2_VERSION}) endif() endif() if(TARGET tinyxml2::tinyxml2) + # This is for the case where a distro provides a non standard (Debug/Release) config type + # eg Debian's config file is tinyxml2ConfigTargets-none.cmake + # convert this back to either DEBUG/RELEASE or just RELEASE + # we only do this because we use find_package_handle_standard_args for config time output + # and it isnt capable of handling TARGETS, so we have to extract the info get_target_property(_TINYXML2_CONFIGURATIONS tinyxml2::tinyxml2 IMPORTED_CONFIGURATIONS) foreach(_tinyxml2_config IN LISTS _TINYXML2_CONFIGURATIONS) # Some non standard config (eg None on Debian) # Just set to RELEASE var so select_library_configurations can continue to work its magic - if((NOT ${_tinyxml2_config} STREQUAL "RELEASE") AND - (NOT ${_tinyxml2_config} STREQUAL "DEBUG")) - get_target_property(TINYXML2_LIBRARY_RELEASE tinyxml2::tinyxml2 IMPORTED_LOCATION_${_tinyxml2_config}) + string(TOUPPER ${_tinyxml2_config} _tinyxml2_config_UPPER) + if((NOT ${_tinyxml2_config_UPPER} STREQUAL "RELEASE") AND + (NOT ${_tinyxml2_config_UPPER} STREQUAL "DEBUG")) + get_target_property(TINYXML2_LIBRARY_RELEASE tinyxml2::tinyxml2 IMPORTED_LOCATION_${_tinyxml2_config_UPPER}) else() - get_target_property(TINYXML2_LIBRARY_${_tinyxml2_config} tinyxml2::tinyxml2 IMPORTED_LOCATION_${_tinyxml2_config}) + get_target_property(TINYXML2_LIBRARY_${_tinyxml2_config_UPPER} tinyxml2::tinyxml2 IMPORTED_LOCATION_${_tinyxml2_config_UPPER}) endif() endforeach() + # Need this, as we may only get the existing TARGET from system and not build or use pkg-config get_target_property(TINYXML2_INCLUDE_DIR tinyxml2::tinyxml2 INTERFACE_INCLUDE_DIRECTORIES) endif() @@ -131,13 +110,27 @@ if(NOT TARGET tinyxml2::tinyxml2) REQUIRED_VARS TINYXML2_LIBRARY TINYXML2_INCLUDE_DIR VERSION_VAR TINYXML2_VERSION) - # Check whether we already have tinyxml2::tinyxml2 target added to dep property list - get_property(CHECK_INTERNAL_DEPS GLOBAL PROPERTY INTERNAL_DEPS_PROP) - list(FIND CHECK_INTERNAL_DEPS "tinyxml2::tinyxml2" TINYXML2_PROP_FOUND) + if(TinyXML2_FOUND) + if(NOT TARGET tinyxml2::tinyxml2) + add_library(tinyxml2::tinyxml2 UNKNOWN IMPORTED) + if(TINYXML2_LIBRARY_RELEASE) + set_target_properties(tinyxml2::tinyxml2 PROPERTIES + IMPORTED_CONFIGURATIONS RELEASE + IMPORTED_LOCATION_RELEASE "${TINYXML2_LIBRARY_RELEASE}") + endif() + if(TINYXML2_LIBRARY_DEBUG) + set_target_properties(tinyxml2::tinyxml2 PROPERTIES + IMPORTED_CONFIGURATIONS DEBUG + IMPORTED_LOCATION_DEBUG "${TINYXML2_LIBRARY_DEBUG}") + endif() + set_target_properties(tinyxml2::tinyxml2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${TINYXML2_INCLUDE_DIR}") + endif() - # list(FIND) returns -1 if search item not found - if(TINYXML2_PROP_FOUND STREQUAL "-1") - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP tinyxml2::tinyxml2) + if(TARGET tinyxml2) + add_dependencies(tinyxml2::tinyxml2 tinyxml2) + endif() endif() + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP tinyxml2::tinyxml2) endif() diff --git a/cmake/modules/FindUUID.cmake b/cmake/modules/FindUUID.cmake index 0c2ff5aa225f4..49fc5b28ce566 100644 --- a/cmake/modules/FindUUID.cmake +++ b/cmake/modules/FindUUID.cmake @@ -3,41 +3,33 @@ # -------- # Finds the libuuid library # -# This will define the following variables:: -# -# UUID_FOUND - system has libuuid -# UUID_INCLUDE_DIRS - the libuuid include directory -# UUID_LIBRARIES - the libuuid libraries -# -# and the following imported targets:: +# This will define the following target: # # UUID::UUID - The libuuid library +# -if(PKG_CONFIG_FOUND) - pkg_check_modules(PC_UUID uuid QUIET) -endif() - -find_path(UUID_INCLUDE_DIR uuid/uuid.h - PATHS ${PC_UUID_INCLUDEDIR}) -find_library(UUID_LIBRARY uuid - PATHS ${PC_UUID_LIBRARY}) -set(UUID_VERSION ${PC_UUID_VERSION}) +if(NOT TARGET UUID::UUID) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_UUID uuid QUIET) + endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(UUID - REQUIRED_VARS UUID_LIBRARY UUID_INCLUDE_DIR - VERSION_VAR UUID_VERSION) + find_path(UUID_INCLUDE_DIR uuid/uuid.h + PATHS ${PC_UUID_INCLUDEDIR}) + find_library(UUID_LIBRARY uuid + PATHS ${PC_UUID_LIBRARY}) + set(UUID_VERSION ${PC_UUID_VERSION}) -if(UUID_FOUND) - set(UUID_LIBRARIES ${UUID_LIBRARY}) - set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR}) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(UUID + REQUIRED_VARS UUID_LIBRARY UUID_INCLUDE_DIR + VERSION_VAR UUID_VERSION) - if(NOT TARGET UUID::UUID) + if(UUID_FOUND) add_library(UUID::UUID UNKNOWN IMPORTED) set_target_properties(UUID::UUID PROPERTIES IMPORTED_LOCATION "${UUID_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${UUID_INCLUDE_DIR}") endif() -endif() -mark_as_advanced(UUID_INCLUDE_DIR UUID_LIBRARY) + mark_as_advanced(UUID_INCLUDE_DIR UUID_LIBRARY) +endif() diff --git a/cmake/platform/linux/wayland.cmake b/cmake/platform/linux/wayland.cmake index 1adcd8fe77626..be00c12bbadfc 100644 --- a/cmake/platform/linux/wayland.cmake +++ b/cmake/platform/linux/wayland.cmake @@ -7,7 +7,6 @@ elseif(APP_RENDER_SYSTEM STREQUAL "gles") list(APPEND PLATFORM_REQUIRED_DEPS OpenGLES EGL) endif() -set(PLATFORM_GLOBAL_TARGET_DEPS generate-wayland-extra-protocols) set(WAYLAND_EXTRA_PROTOCOL_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}") # for wayland-extra-protocols.hpp diff --git a/cmake/platform/linux/webos.cmake b/cmake/platform/linux/webos.cmake index aa6c5d1a276e8..c740ecd27739b 100644 --- a/cmake/platform/linux/webos.cmake +++ b/cmake/platform/linux/webos.cmake @@ -5,7 +5,6 @@ include(${CMAKE_SOURCE_DIR}/cmake/platform/${CORE_SYSTEM_NAME}/wayland.cmake) list(APPEND CORE_PLATFORM_NAME_LC wayland) list(APPEND PLATFORM_REQUIRED_DEPS WaylandProtocolsWebOS PlayerAPIs PlayerFactory WebOSHelpers) -list(APPEND PLATFORM_GLOBAL_TARGET_DEPS generate-wayland-webos-protocols) list(APPEND ARCH_DEFINES -DTARGET_WEBOS) set(ENABLE_PULSEAUDIO OFF CACHE BOOL "" FORCE) set(TARGET_WEBOS TRUE) diff --git a/cmake/scripts/common/Macros.cmake b/cmake/scripts/common/Macros.cmake index b6863960b7f0c..e98ef7564f00a 100644 --- a/cmake/scripts/common/Macros.cmake +++ b/cmake/scripts/common/Macros.cmake @@ -73,6 +73,10 @@ function(core_add_library name) set_target_properties(${name} PROPERTIES PREFIX "") set(core_DEPENDS ${name} ${core_DEPENDS} CACHE STRING "" FORCE) add_dependencies(${name} ${GLOBAL_TARGET_DEPS}) + + # Adds global target to library. This propagates dep lib info (eg include_dir locations) + target_link_libraries(${name} PRIVATE ${GLOBAL_TARGET_DEPS}) + set(CORE_LIBRARY ${name} PARENT_SCOPE) if(NOT MSVC) diff --git a/cmake/scripts/linux/ExtraTargets.cmake b/cmake/scripts/linux/ExtraTargets.cmake index 9be92f19d4f83..62c6a400b136b 100644 --- a/cmake/scripts/linux/ExtraTargets.cmake +++ b/cmake/scripts/linux/ExtraTargets.cmake @@ -34,4 +34,7 @@ if("wayland" IN_LIST CORE_PLATFORM_NAME_LC) # Dummy target for dependencies add_custom_target(generate-wayland-extra-protocols DEPENDS wayland-extra-protocols.hpp) + # ToDo: turn this into a TARGET OBJECT. For now, a custum target doesnt play nice with + # our PLATFORM_GLOBAL_TARGET_DEPS usage in macros + add_dependencies(lib${APP_NAME_LC} generate-wayland-extra-protocols) endif() diff --git a/cmake/scripts/webos/ExtraTargets.cmake b/cmake/scripts/webos/ExtraTargets.cmake index 6eec8967819cd..3380c6a3be656 100644 --- a/cmake/scripts/webos/ExtraTargets.cmake +++ b/cmake/scripts/webos/ExtraTargets.cmake @@ -7,3 +7,6 @@ add_custom_command(OUTPUT "${WAYLAND_EXTRA_PROTOCOL_GENERATED_DIR}/wayland-webos DEPENDS "${WAYLANDPP_SCANNER}" ${WEBOS_PROTOCOL_XMLS} COMMENT "Generating wayland-webos C++ wrappers") add_custom_target(generate-wayland-webos-protocols DEPENDS wayland-webos-protocols.hpp) +# ToDo: turn this into a TARGET OBJECT. For now, a custum target doesnt play nice with +# our PLATFORM_GLOBAL_TARGET_DEPS usage in macros +add_dependencies(lib${APP_NAME_LC} generate-wayland-webos-protocols) diff --git a/xbmc/filesystem/CMakeLists.txt b/xbmc/filesystem/CMakeLists.txt index 8f80f8b08b165..a88132b3bc95a 100644 --- a/xbmc/filesystem/CMakeLists.txt +++ b/xbmc/filesystem/CMakeLists.txt @@ -158,7 +158,7 @@ if(ENABLE_OPTICAL) DVDDirectory.h) endif() -if(NFS_FOUND) +if(TARGET libnfs::nfs) list(APPEND SOURCES NFSDirectory.cpp NFSFile.cpp) list(APPEND HEADERS NFSDirectory.h diff --git a/xbmc/filesystem/test/CMakeLists.txt b/xbmc/filesystem/test/CMakeLists.txt index 9572459cf198e..0020050598e8b 100644 --- a/xbmc/filesystem/test/CMakeLists.txt +++ b/xbmc/filesystem/test/CMakeLists.txt @@ -8,7 +8,7 @@ if(MICROHTTPD_FOUND) list(APPEND SOURCES TestHTTPDirectory.cpp) endif() -if(NFS_FOUND) +if(TARGET libnfs::nfs) list(APPEND SOURCES TestNfsFile.cpp) endif() diff --git a/xbmc/interfaces/swig/CMakeLists.txt b/xbmc/interfaces/swig/CMakeLists.txt index b1748fd87a757..a7c683e7e7682 100644 --- a/xbmc/interfaces/swig/CMakeLists.txt +++ b/xbmc/interfaces/swig/CMakeLists.txt @@ -59,6 +59,8 @@ set_target_properties(python_binding PROPERTIES POSITION_INDEPENDENT_CODE TRUE FOLDER "Build Utilities") set(core_DEPENDS python_binding ${core_DEPENDS} CACHE STRING "" FORCE) add_dependencies(python_binding ${GLOBAL_TARGET_DEPS}) +# This propagates target options from dependencies (eg spdlog definitions) +target_link_libraries(python_binding PRIVATE ${GLOBAL_TARGET_DEPS}) if(CORE_SYSTEM_NAME STREQUAL windowsstore) set_target_properties(python_binding PROPERTIES STATIC_LIBRARY_FLAGS "/ignore:4264")