From 5f8335c1e49ce108ef3481863833c98efa00411b Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 2 Jul 2020 23:09:26 +0200 Subject: sync with upstream --- cmake/scripts/common/AddonHelpers.cmake | 53 +++++++++++++---- cmake/scripts/common/AddonHelpers.dox | 59 +++++++++++++++++++ cmake/scripts/common/ArchSetup.cmake | 26 +------- cmake/scripts/common/CheckTargetPlatform.cmake | 5 +- cmake/scripts/common/CompilerSettings.cmake | 7 +++ cmake/scripts/common/GenerateVersionedFiles.cmake | 3 - cmake/scripts/common/HandleDepends.cmake | 20 +++++-- cmake/scripts/common/Macros.cmake | 72 ----------------------- cmake/scripts/common/PrepareEnv.cmake | 17 ++++-- 9 files changed, 144 insertions(+), 118 deletions(-) create mode 100644 cmake/scripts/common/AddonHelpers.dox create mode 100644 cmake/scripts/common/CompilerSettings.cmake (limited to 'cmake/scripts/common') diff --git a/cmake/scripts/common/AddonHelpers.cmake b/cmake/scripts/common/AddonHelpers.cmake index 2f3f302..c541ad7 100644 --- a/cmake/scripts/common/AddonHelpers.cmake +++ b/cmake/scripts/common/AddonHelpers.cmake @@ -92,6 +92,7 @@ macro (build_addon target prefix libs) endforeach() endif() + message(STATUS "Addon dependency check ...") # Set defines used in addon.xml.in and read from versions.h to set add-on # version parts automatically file(STRINGS ${KODI_INCLUDE_DIR}/versions.h BIN_ADDON_PARTS) @@ -108,7 +109,8 @@ macro (build_addon target prefix libs) if("${include_name}" MATCHES "_DEPENDS") # Use start definition name as base for other value type list(GET loop_var 0 list_name) - string(REPLACE "_DEPENDS" "" depends_name ${list_name}) + string(REPLACE "_DEPENDS" "_MIN" depends_minver ${list_name}) + string(REPLACE "_DEPENDS" "" depends_ver ${list_name}) string(REPLACE "_DEPENDS" "_XML_ID" xml_entry_name ${list_name}) string(REPLACE "_DEPENDS" "_USED" used_type_name ${list_name}) @@ -120,16 +122,14 @@ macro (build_addon target prefix libs) foreach(src_file ${USED_SOURCES}) file(STRINGS ${src_file} BIN_ADDON_SRC_PARTS) foreach(loop_var ${BIN_ADDON_SRC_PARTS}) - string(FIND "${loop_var}" "#include" matchres) - if("${matchres}" EQUAL 0) - string(REPLACE " " ";" loop_var "${loop_var}") - list(GET loop_var 1 include_name) - string(REGEX REPLACE "[<>\"]|kodi/" "" include_name "${include_name}") - if(include_name MATCHES ${depend_header}) - set(ADDON_DEPENDS "${ADDON_DEPENDS}\n") - # Inform with them the addon header about used type + string(REGEX MATCH "^[ \t]*#[ \t]*(include|import)[ \t]*[<\"](kodi\/)?(.+)[\">]" include_name "${loop_var}") + if(include_name AND CMAKE_MATCH_3 MATCHES ^${depend_header}) + get_directory_property(CURRENT_DEFS COMPILE_DEFINITIONS) + if(NOT used_type_name IN_LIST CURRENT_DEFS) + set(ADDON_DEPENDS "${ADDON_DEPENDS}\n") + # Inform with them the addon header about used type, if not present before add_definitions(-D${used_type_name}) - message(STATUS "Added usage definition: ${used_type_name}") + message(STATUS " - Added API usage definition: ${used_type_name} (Version: \"${${depends_ver}}\", Min. Version: \"${${depends_minver}}\")") set(FOUND_HEADER_USAGE 1) endif() endif() @@ -276,6 +276,18 @@ macro (build_addon target prefix libs) install(FILES ${${prefix}_ADDITIONAL_BINARY} DESTINATION ${target} COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) endif() + if(${prefix}_ADDITIONAL_BINARY_EXE) + install(PROGRAMS ${${prefix}_ADDITIONAL_BINARY_EXE} DESTINATION ${target} + COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) + endif() + if(${prefix}_ADDITIONAL_BINARY_PARTS) + install(FILES ${${prefix}_ADDITIONAL_BINARY_PARTS} DESTINATION ${target} + COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) + endif() + if(${prefix}_ADDITIONAL_BINARY_DIRS) + install(DIRECTORY ${${prefix}_ADDITIONAL_BINARY_DIRS} DESTINATION ${target} USE_SOURCE_PERMISSIONS + COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) + endif() else() # NOT WIN32 if(NOT CPACK_PACKAGE_DIRECTORY) set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -296,6 +308,18 @@ macro (build_addon target prefix libs) install(FILES ${${prefix}_ADDITIONAL_BINARY} DESTINATION ${target} COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) endif() + if(${prefix}_ADDITIONAL_BINARY_EXE) + install(PROGRAMS ${${prefix}_ADDITIONAL_BINARY_EXE} DESTINATION ${target} + COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) + endif() + if(${prefix}_ADDITIONAL_BINARY_PARTS) + install(FILES ${${prefix}_ADDITIONAL_BINARY_PARTS} DESTINATION ${target} + COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) + endif() + if(${prefix}_ADDITIONAL_BINARY_DIRS) + install(DIRECTORY ${${prefix}_ADDITIONAL_BINARY_DIRS} DESTINATION ${target} USE_SOURCE_PERMISSIONS + COMPONENT ${target}-${${prefix}_VERSION}-${PLATFORM_TAG}) + endif() endif() add_cpack_workaround(${target} ${${prefix}_VERSION} ${ext}) else() @@ -339,6 +363,15 @@ macro (build_addon target prefix libs) if(${prefix}_ADDITIONAL_BINARY) install(FILES ${${prefix}_ADDITIONAL_BINARY} DESTINATION ${CMAKE_INSTALL_LIBDIR}/addons/${target}) endif() + if(${prefix}_ADDITIONAL_BINARY_EXE) + install(PROGRAMS ${${prefix}_ADDITIONAL_BINARY_EXE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/addons/${target}) + endif() + if(${prefix}_ADDITIONAL_BINARY_PARTS) + install(FILES ${${prefix}_ADDITIONAL_BINARY_PARTS} DESTINATION ${CMAKE_INSTALL_LIBDIR}/addons/${target}) + endif() + if(${prefix}_ADDITIONAL_BINARY_DIRS) + install(DIRECTORY ${${prefix}_ADDITIONAL_BINARY_DIRS} DESTINATION ${CMAKE_INSTALL_LIBDIR}/addons/${target} USE_SOURCE_PERMISSIONS) + endif() endif() if(${APP_NAME_UC}_BUILD_DIR) file(GLOB_RECURSE files ${CMAKE_CURRENT_SOURCE_DIR}/${target}/*) diff --git a/cmake/scripts/common/AddonHelpers.dox b/cmake/scripts/common/AddonHelpers.dox new file mode 100644 index 0000000..d3acec0 --- /dev/null +++ b/cmake/scripts/common/AddonHelpers.dox @@ -0,0 +1,59 @@ +/*! +\addtogroup cpp_cmake + +Kodi which uses it as a library for its binary addons has a special build +system for this. + +To implement this, a CMake macro brought by Kodi is used, this is +"build_addon (...)". This processes various definitions passed by the addon to +process the construction. + + +-------------------------------------------------------------------------------- + +Here a minmal example of the for addon used CMakeLists.txt: + +~~~~~~~~~~~~~{.cmake} +cmake_minimum_required(VERSION 3.5) +project(example.addon) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}) + +find_package(Kodi REQUIRED) + +include_directories(${KODI_INCLUDE_DIR} + +set(DEPLIBS ) # Here empty +set(EXAMPLE_SOURCES src/main.cpp) +set(EXAMPLE_HEADERS src/main.h) + +build_addon((example.addon EXAMPLE DEPLIBS) + +include(CPack) +~~~~~~~~~~~~~ + + +-------------------------------------------------------------------------------- + +This is a list of special variables that can be passed to the macro. +The parts defined with "*" must be given the second name given to the macro. + +Here to define the necessary creation and installation files on addon CMakeLists.txt: +| Name | Description +|-----------------------------|------------------------------------------------- +| *_SOURCES | List of source code files to be complicated. +| *_HEADERS | List of used source code header files. +| *_CUSTOM_BINARY | For special cases where an already created library from an external source is inserted, the "* _SOURCES" and "* _HEADERS" are unused in this case.
This is currently used primarily on game addons. +| *_CUSTOM_DATA | To add additional required data from a folder, which are stored in the shared folder of the addon.
With a "/" at the end of the content given to the folder is used, without the folder itself. +| *_ADDITIONAL_BINARY | In case the additional library has to be installed for the addon, the path or CMake name can be given here. +| *_ADDITIONAL_BINARY_EXE | In case you need to addon an additional application you can give the path or CMake name, it will be in the same folder as the addon library.
The mode bits are set there as EXE. +| *_ADDITIONAL_BINARY_DIRS | To add complete folders additionally to folders containing the addon library.
With a "/" at the end of the content given to the folder is used, without the folder itself. + +External creation Options, given by `-D...`: +| Name | Description +|-----------------------------|------------------------------------------------- +| PACKAGE_ZIP | To create a package as a ZIP file. This is also used to install locally addon together.
Default is OFF. +| PACKAGE_TGZ | To create a package as a TGZ file.
Default is OFF. +| BUILD_SHARED_LIBS | To define if addon library is shared or static.
Default is ON to have shared. +| USE_LTO | Use link time optimization.
Default is OFF. +*/ diff --git a/cmake/scripts/common/ArchSetup.cmake b/cmake/scripts/common/ArchSetup.cmake index 07ce6d4..2e1eb12 100644 --- a/cmake/scripts/common/ArchSetup.cmake +++ b/cmake/scripts/common/ArchSetup.cmake @@ -18,24 +18,7 @@ include(CheckCXXSourceCompiles) include(CheckSymbolExists) include(CheckFunctionExists) include(CheckIncludeFile) - -# Macro to check if a given type exists in a given header -# Arguments: -# header the header to check -# type the type to check for existence -# var the compiler definition to set if type exists -# On return: -# If type was found, the definition is added to SYSTEM_DEFINES -macro(check_type header type var) - check_cxx_source_compiles("#include <${header}> - int main() - { - ${type} s; - }" ${var}) - if(${var}) - list(APPEND SYSTEM_DEFINES -D${var}=1) - endif() -endmacro() +include(CheckTypeSize) # Macro to check if a given builtin function exists # Arguments: @@ -95,17 +78,12 @@ endif() include(${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/ArchSetup.cmake) message(STATUS "Core system type: ${CORE_SYSTEM_NAME}") -message(STATUS "Platform: ${PLATFORM}") +message(STATUS "Platform: ${CORE_PLATFORM_NAME}") message(STATUS "CPU: ${CPU}, ARCH: ${ARCH}") message(STATUS "Cross-Compiling: ${CMAKE_CROSSCOMPILING}") message(STATUS "Execute build artefacts on host: ${CORE_HOST_IS_TARGET}") message(STATUS "Depends based build: ${KODI_DEPENDSBUILD}") -check_type(string std::u16string HAVE_STD__U16_STRING) -check_type(string std::u32string HAVE_STD__U32_STRING) -check_type(string char16_t HAVE_CHAR16_T) -check_type(string char32_t HAVE_CHAR32_T) -check_type(stdint.h uint_least16_t HAVE_STDINT_H) check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE) check_symbol_exists(PRIdMAX inttypes.h HAVE_INTTYPES_H) check_builtin("long* temp=0; long ret=__sync_add_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_ADD_AND_FETCH) diff --git a/cmake/scripts/common/CheckTargetPlatform.cmake b/cmake/scripts/common/CheckTargetPlatform.cmake index 526e4bd..d776085 100644 --- a/cmake/scripts/common/CheckTargetPlatform.cmake +++ b/cmake/scripts/common/CheckTargetPlatform.cmake @@ -29,7 +29,10 @@ function(check_target_platform dir target_platform build) string(SUBSTRING ${platform} 1 ${platform_length} platform) # check if the current platform does not match the extracted platform - if(NOT ${platform} STREQUAL ${target_platform}) + if(${platform} STREQUAL ${target_platform}) + set(${build} FALSE) + break() + elseif(NOT ${platform} STREQUAL ${target_platform}) set(${build} TRUE) endif() endif() diff --git a/cmake/scripts/common/CompilerSettings.cmake b/cmake/scripts/common/CompilerSettings.cmake new file mode 100644 index 0000000..b4e7e89 --- /dev/null +++ b/cmake/scripts/common/CompilerSettings.cmake @@ -0,0 +1,7 @@ +# Languages and global compiler settings +if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14) + set(CMAKE_CXX_STANDARD 14) +endif() +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp") diff --git a/cmake/scripts/common/GenerateVersionedFiles.cmake b/cmake/scripts/common/GenerateVersionedFiles.cmake index 1d324db..d54b524 100644 --- a/cmake/scripts/common/GenerateVersionedFiles.cmake +++ b/cmake/scripts/common/GenerateVersionedFiles.cmake @@ -24,9 +24,6 @@ foreach(loop_var ${ADDON_XML_IN_FILE}) string(REPLACE ${CORE_SOURCE_DIR} ${CMAKE_BINARY_DIR} dest_dir ${source_dir}) file(MAKE_DIRECTORY ${dest_dir}) - # copy everything except addon.xml.in to build folder - file(COPY "${source_dir}" DESTINATION "${CMAKE_BINARY_DIR}/addons" REGEX ".xml.in" EXCLUDE) - configure_file(${source_dir}/addon.xml.in ${dest_dir}/addon.xml @ONLY) unset(source_dir) diff --git a/cmake/scripts/common/HandleDepends.cmake b/cmake/scripts/common/HandleDepends.cmake index 40e382b..7cacd25 100644 --- a/cmake/scripts/common/HandleDepends.cmake +++ b/cmake/scripts/common/HandleDepends.cmake @@ -68,8 +68,8 @@ function(add_addon_depends addon searchpath) -DCORE_SYSTEM_NAME=${CORE_SYSTEM_NAME} -DENABLE_STATIC=1 -DBUILD_SHARED_LIBS=0) - # windows store args - if (CMAKE_SYSTEM_NAME STREQUAL WindowsStore) + # windows args + if (CMAKE_SYSTEM_NAME STREQUAL WindowsStore OR CMAKE_SYSTEM_NAME STREQUAL Windows) list(APPEND BUILD_ARGS -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}) endif() @@ -78,8 +78,10 @@ function(add_addon_depends addon searchpath) # make sure we create strings, not lists set(TMP_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_DEFINES}") set(TMP_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_DEFINES}") + set(TMP_EXE_LINKER_FLAGS "-L${OUTPUT_DIR}/lib ${CMAKE_EXE_LINKER_FLAGS}") list(APPEND BUILD_ARGS -DCMAKE_C_FLAGS=${TMP_C_FLAGS} - -DCMAKE_CXX_FLAGS=${TMP_CXX_FLAGS}) + -DCMAKE_CXX_FLAGS=${TMP_CXX_FLAGS} + -DCMAKE_EXE_LINKER_FLAGS=${TMP_EXE_LINKER_FLAGS}) endif() if(CMAKE_TOOLCHAIN_FILE) @@ -88,6 +90,17 @@ function(add_addon_depends addon searchpath) message(${BUILD_ARGS}) endif() + # used for addons where need special folders to store there content (if + # not set the addon define it byself). + # e.g. Google Chromium addon where his git bring: + # - "unable to create file" ... "Filename too long" + # see also WARNING by Windows on: https://bitbucket.org/chromiumembedded/cef/wiki/MasterBuildQuickStart + if(THIRD_PARTY_PATH) + message(STATUS "Third party lib path specified") + message(STATUS ${THIRD_PARTY_PATH}) + list(APPEND BUILD_ARGS -DTHIRD_PARTY_PATH=${THIRD_PARTY_PATH}) + endif() + set(PATCH_COMMAND) # if there's a CMakeLists.txt use it to prepare the build @@ -215,7 +228,6 @@ function(add_addon_depends addon searchpath) -DOUTPUT_DIR=${OUTPUT_DIR} -DCMAKE_PREFIX_PATH=${OUTPUT_DIR} -DCMAKE_INSTALL_PREFIX=${OUTPUT_DIR} - -DCMAKE_EXE_LINKER_FLAGS=-L${OUTPUT_DIR}/lib -DCMAKE_INCLUDE_PATH=${OUTPUT_DIR}/include) endif() diff --git a/cmake/scripts/common/Macros.cmake b/cmake/scripts/common/Macros.cmake index eefd7c8..f7327e3 100644 --- a/cmake/scripts/common/Macros.cmake +++ b/cmake/scripts/common/Macros.cmake @@ -111,26 +111,6 @@ function(core_add_test_library name) endforeach() endfunction() -# Add an addon callback library -# Arguments: -# name name of the library to add -# Implicit arguments: -# SOURCES the sources of the library -# HEADERS the headers of the library (only for IDE support) -# OTHERS other library related files (only for IDE support) -# On return: -# Library target is defined and added to LIBRARY_FILES -function(core_add_addon_library name) - get_filename_component(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} NAME) - list(APPEND SOURCES lib${name}.cpp) - core_add_shared_library(${name} OUTPUT_DIRECTORY addons/${DIRECTORY}) - set_target_properties(${name} PROPERTIES FOLDER addons) - target_include_directories(${name} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi - ${CMAKE_SOURCE_DIR}/xbmc) -endfunction() - # Add an dl-loaded shared library # Arguments: # name name of the library to add @@ -386,25 +366,6 @@ function(core_require_dep) endforeach() endfunction() -# add required dyloaded dependencies of main application -# Arguments: -# dep_list One or many dependency specifications (see split_dependency_specification) -# for syntax). The dependency name is used uppercased as variable prefix. -# On return: -# dependency added to ${SYSTEM_INCLUDES}, ${dep}_SONAME is set up -function(core_require_dyload_dep) - foreach(depspec ${ARGN}) - split_dependency_specification(${depspec} dep version) - find_package_with_ver(${dep} ${version} REQUIRED) - string(TOUPPER ${dep} depup) - list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS}) - list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS}) - find_soname(${depup} REQUIRED) - export_dep() - set(${depup}_SONAME ${${depup}_SONAME} PARENT_SCOPE) - endforeach() -endfunction() - # helper macro for optional deps macro(setup_enable_switch) string(TOUPPER ${dep} depup) @@ -450,39 +411,6 @@ function(core_optional_dep) set(final_message ${final_message} PARENT_SCOPE) endfunction() -# add optional dyloaded dependencies of main application -# Arguments: -# dep_list One or many dependency specifications (see split_dependency_specification) -# for syntax). The dependency name is used uppercased as variable prefix. -# On return: -# dependency optionally added to ${SYSTEM_INCLUDES}, ${DEP_DEFINES}, ${dep}_SONAME is set up -function(core_optional_dyload_dep) - foreach(depspec ${ARGN}) - set(_required False) - split_dependency_specification(${depspec} dep version) - setup_enable_switch() - if(${enable_switch} STREQUAL AUTO) - find_package_with_ver(${dep} ${version}) - elseif(${${enable_switch}}) - find_package_with_ver(${dep} ${version} REQUIRED) - set(_required True) - endif() - - if(${depup}_FOUND) - list(APPEND SYSTEM_INCLUDES ${${depup}_INCLUDE_DIRS}) - find_soname(${depup} REQUIRED) - list(APPEND DEP_DEFINES ${${depup}_DEFINITIONS}) - set(final_message ${final_message} "${depup} enabled: Yes" PARENT_SCOPE) - export_dep() - set(${depup}_SONAME ${${depup}_SONAME} PARENT_SCOPE) - elseif(_required) - message(FATAL_ERROR "${depup} enabled but not found") - else() - set(final_message ${final_message} "${depup} enabled: No" PARENT_SCOPE) - endif() - endforeach() -endfunction() - function(core_file_read_filtered result filepattern) # Reads STRINGS from text files # with comments filtered out diff --git a/cmake/scripts/common/PrepareEnv.cmake b/cmake/scripts/common/PrepareEnv.cmake index 753dca1..559788f 100644 --- a/cmake/scripts/common/PrepareEnv.cmake +++ b/cmake/scripts/common/PrepareEnv.cmake @@ -34,6 +34,14 @@ endif() set(PLATFORM_TAG ${CORE_SYSTEM_NAME}) +# The CPU variable is given either by ./tools/depends or by the +# ./cmake/scripts/common/ArchSetup.cmake (which refers to the Kodi building +# itself). However, this file is only used by addons, so CPU can not always +# be defined, so in this case, if empty, the base CPU will be used. +if(NOT CPU) + set(CPU ${CMAKE_SYSTEM_PROCESSOR}) +endif() + if(CORE_SYSTEM_NAME STREQUAL android) if (CPU MATCHES "v7a") set(PLATFORM_TAG ${PLATFORM_TAG}-armv7) @@ -41,13 +49,14 @@ if(CORE_SYSTEM_NAME STREQUAL android) set(PLATFORM_TAG ${PLATFORM_TAG}-aarch64) elseif (CPU MATCHES "i686") set(PLATFORM_TAG ${PLATFORM_TAG}-i686) + elseif (CPU MATCHES "x86_64") + set(PLATFORM_TAG ${PLATFORM_TAG}-x86_64) else() message(FATAL_ERROR "Unsupported architecture") endif() -elseif(CORE_SYSTEM_NAME STREQUAL ios) - if (CPU MATCHES armv7) - set(PLATFORM_TAG ${PLATFORM_TAG}-armv7) - elseif (CPU MATCHES arm64) +elseif(CORE_SYSTEM_NAME STREQUAL darwin_embedded) + set(PLATFORM_TAG ${CORE_PLATFORM_NAME}) + if (CPU MATCHES arm64) set(PLATFORM_TAG ${PLATFORM_TAG}-aarch64) else() message(FATAL_ERROR "Unsupported architecture") -- cgit v1.2.3