diff options
| author | manuel <manuel@mausz.at> | 2017-06-04 16:57:49 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2017-06-04 16:57:49 +0200 |
| commit | f44ecaa4f27e7538ddcad66d40e543bffa2d2d86 (patch) | |
| tree | d8de60fc7e17edeb6f0921726c038ee54b281445 /cmake/scripts/common/ArchSetup.cmake | |
| parent | ae08c8b7221bc965ac40d70e53fc8fcddb050c46 (diff) | |
| download | kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.gz kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.bz2 kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.zip | |
sync with upstream
Diffstat (limited to 'cmake/scripts/common/ArchSetup.cmake')
| -rw-r--r-- | cmake/scripts/common/ArchSetup.cmake | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/cmake/scripts/common/ArchSetup.cmake b/cmake/scripts/common/ArchSetup.cmake new file mode 100644 index 0000000..8d5dba8 --- /dev/null +++ b/cmake/scripts/common/ArchSetup.cmake | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | # This script configures the build for a given architecture. | ||
| 2 | # Flags and stringified arch is set up. | ||
| 3 | # General compiler tests belongs here. | ||
| 4 | # | ||
| 5 | # On return, the following variables are set: | ||
| 6 | # CMAKE_SYSTEM_NAME - a lowercased system name | ||
| 7 | # CPU - the CPU on the target | ||
| 8 | # ARCH - the system architecture | ||
| 9 | # ARCH_DEFINES - list of compiler definitions for this architecture | ||
| 10 | # SYSTEM_DEFINES - list of compiler definitions for this system | ||
| 11 | # DEP_DEFINES - compiler definitions for system dependencies (e.g. LIRC) | ||
| 12 | # + the results of compiler tests etc. | ||
| 13 | |||
| 14 | include(CheckCXXSourceCompiles) | ||
| 15 | include(CheckSymbolExists) | ||
| 16 | include(CheckFunctionExists) | ||
| 17 | include(CheckIncludeFile) | ||
| 18 | |||
| 19 | # Macro to check if a given type exists in a given header | ||
| 20 | # Arguments: | ||
| 21 | # header the header to check | ||
| 22 | # type the type to check for existence | ||
| 23 | # var the compiler definition to set if type exists | ||
| 24 | # On return: | ||
| 25 | # If type was found, the definition is added to SYSTEM_DEFINES | ||
| 26 | macro(check_type header type var) | ||
| 27 | check_cxx_source_compiles("#include <${header}> | ||
| 28 | int main() | ||
| 29 | { | ||
| 30 | ${type} s; | ||
| 31 | }" ${var}) | ||
| 32 | if(${var}) | ||
| 33 | list(APPEND SYSTEM_DEFINES -D${var}=1) | ||
| 34 | endif() | ||
| 35 | endmacro() | ||
| 36 | |||
| 37 | # Macro to check if a given builtin function exists | ||
| 38 | # Arguments: | ||
| 39 | # func the function to check | ||
| 40 | # var the compiler definition to set if type exists | ||
| 41 | # On return: | ||
| 42 | # If type was found, the definition is added to SYSTEM_DEFINES | ||
| 43 | macro(check_builtin func var) | ||
| 44 | check_cxx_source_compiles(" | ||
| 45 | int main() | ||
| 46 | { | ||
| 47 | ${func}; | ||
| 48 | }" ${var}) | ||
| 49 | if(${var}) | ||
| 50 | list(APPEND SYSTEM_DEFINES -D${var}=1) | ||
| 51 | endif() | ||
| 52 | endmacro() | ||
| 53 | |||
| 54 | |||
| 55 | # -------- Main script --------- | ||
| 56 | message(STATUS "System type: ${CMAKE_SYSTEM_NAME}") | ||
| 57 | if(NOT CORE_SYSTEM_NAME) | ||
| 58 | string(TOLOWER ${CMAKE_SYSTEM_NAME} CORE_SYSTEM_NAME) | ||
| 59 | endif() | ||
| 60 | |||
| 61 | if(WITH_CPU) | ||
| 62 | set(CPU ${WITH_CPU}) | ||
| 63 | elseif(NOT KODI_DEPENDSBUILD) | ||
| 64 | set(CPU ${CMAKE_SYSTEM_PROCESSOR}) | ||
| 65 | endif() | ||
| 66 | |||
| 67 | if(CMAKE_TOOLCHAIN_FILE) | ||
| 68 | if(NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}") | ||
| 69 | message(FATAL_ERROR "Toolchain file ${CMAKE_TOOLCHAIN_FILE} does not exist.") | ||
| 70 | elseif(KODI_DEPENDSBUILD AND (NOT DEPENDS_PATH OR NOT NATIVEPREFIX)) | ||
| 71 | message(FATAL_ERROR "Toolchain did not define DEPENDS_PATH or NATIVEPREFIX. Possibly outdated depends.") | ||
| 72 | endif() | ||
| 73 | endif() | ||
| 74 | |||
| 75 | # While CMAKE_CROSSCOMPILING is set unconditionally if there's a toolchain file, | ||
| 76 | # this variable is set if we can execute build artefacts on the host system (for example unit tests). | ||
| 77 | if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL CMAKE_SYSTEM_PROCESSOR AND | ||
| 78 | CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) | ||
| 79 | set(CORE_HOST_IS_TARGET TRUE) | ||
| 80 | else() | ||
| 81 | set(CORE_HOST_IS_TARGET FALSE) | ||
| 82 | endif() | ||
| 83 | |||
| 84 | # Main cpp | ||
| 85 | set(CORE_MAIN_SOURCE ${CMAKE_SOURCE_DIR}/xbmc/platform/posix/main.cpp) | ||
| 86 | |||
| 87 | # system specific arch setup | ||
| 88 | if(NOT EXISTS ${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/ArchSetup.cmake) | ||
| 89 | message(FATAL_ERROR "Couldn't find configuration for '${CORE_SYSTEM_NAME}' " | ||
| 90 | "Either the platform is not (yet) supported " | ||
| 91 | "or a toolchain file has to be specified. " | ||
| 92 | "Consult ${CMAKE_SOURCE_DIR}/cmake/README.md for instructions. " | ||
| 93 | "Note: Specifying a toolchain requires a clean build directory!") | ||
| 94 | endif() | ||
| 95 | include(${CMAKE_SOURCE_DIR}/cmake/scripts/${CORE_SYSTEM_NAME}/ArchSetup.cmake) | ||
| 96 | |||
| 97 | message(STATUS "Core system type: ${CORE_SYSTEM_NAME}") | ||
| 98 | message(STATUS "Platform: ${PLATFORM}") | ||
| 99 | message(STATUS "CPU: ${CPU}, ARCH: ${ARCH}") | ||
| 100 | message(STATUS "Cross-Compiling: ${CMAKE_CROSSCOMPILING}") | ||
| 101 | message(STATUS "Execute build artefacts on host: ${CORE_HOST_IS_TARGET}") | ||
| 102 | message(STATUS "Depends based build: ${KODI_DEPENDSBUILD}") | ||
| 103 | |||
| 104 | check_type(string std::u16string HAVE_STD__U16_STRING) | ||
| 105 | check_type(string std::u32string HAVE_STD__U32_STRING) | ||
| 106 | check_type(string char16_t HAVE_CHAR16_T) | ||
| 107 | check_type(string char32_t HAVE_CHAR32_T) | ||
| 108 | check_type(stdint.h uint_least16_t HAVE_STDINT_H) | ||
| 109 | check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE) | ||
| 110 | check_symbol_exists(PRIdMAX inttypes.h HAVE_INTTYPES_H) | ||
| 111 | check_builtin("long* temp=0; long ret=__sync_add_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_ADD_AND_FETCH) | ||
| 112 | check_builtin("long* temp=0; long ret=__sync_sub_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_SUB_AND_FETCH) | ||
| 113 | check_builtin("long* temp=0; long ret=__sync_val_compare_and_swap(temp, 1, 1)" HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP) | ||
| 114 | check_include_file(sys/inotify.h HAVE_INOTIFY) | ||
| 115 | if(HAVE_INOTIFY) | ||
| 116 | list(APPEND SYSTEM_DEFINES -DHAVE_INOTIFY=1) | ||
| 117 | endif() | ||
| 118 | if(HAVE_POSIX_FADVISE) | ||
| 119 | list(APPEND SYSTEM_DEFINES -DHAVE_POSIX_FADVISE=1) | ||
| 120 | endif() | ||
| 121 | check_function_exists(localtime_r HAVE_LOCALTIME_R) | ||
| 122 | if(HAVE_LOCALTIME_R) | ||
| 123 | list(APPEND SYSTEM_DEFINES -DHAVE_LOCALTIME_R=1) | ||
| 124 | endif() | ||
| 125 | if(HAVE_INTTYPES_H) | ||
| 126 | list(APPEND SYSTEM_DEFINES -DHAVE_INTTYPES_H=1) | ||
| 127 | endif() | ||
| 128 | |||
| 129 | find_package(SSE) | ||
| 130 | foreach(_sse SSE SSE2 SSE3 SSSE3 SSE4_1 SSE4_2 AVX AVX2) | ||
| 131 | if(${${_sse}_FOUND}) | ||
| 132 | # enable SSE versions up to 4.1 by default, if available | ||
| 133 | if(NOT ${_sse} MATCHES "AVX" AND NOT ${_sse} STREQUAL "SSE4_2") | ||
| 134 | option(ENABLE_${_sse} "Enable ${_sse}" ON) | ||
| 135 | else() | ||
| 136 | option(ENABLE_${_sse} "Enable ${_sse}" OFF) | ||
| 137 | endif() | ||
| 138 | endif() | ||
| 139 | if(ENABLE_${_sse}) | ||
| 140 | set(HAVE_${_sse} TRUE CACHE STRING "${_sse} enabled") | ||
| 141 | list(APPEND ARCH_DEFINES -DHAVE_${_sse}=1) | ||
| 142 | endif() | ||
| 143 | endforeach() | ||
| 144 | |||
| 145 | if(NOT DEFINED NEON OR NEON) | ||
| 146 | option(ENABLE_NEON "Enable NEON optimization" ${NEON}) | ||
| 147 | if(ENABLE_NEON) | ||
| 148 | message(STATUS "NEON optimization enabled") | ||
| 149 | add_definitions(-DHAS_NEON) | ||
| 150 | if(NEON_FLAGS) | ||
| 151 | add_options(ALL_LANGUAGES ALL_BUILDS ${NEON_FLAGS}) | ||
| 152 | endif() | ||
| 153 | endif() | ||
| 154 | endif() | ||
| 155 | |||
| 156 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
| 157 | add_options (ALL_LANGUAGES DEBUG "-g" "-D_DEBUG" "-Wall") | ||
| 158 | endif() | ||
| 159 | |||
