diff options
Diffstat (limited to 'project/cmake/scripts/common/ArchSetup.cmake')
| -rw-r--r-- | project/cmake/scripts/common/ArchSetup.cmake | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/project/cmake/scripts/common/ArchSetup.cmake b/project/cmake/scripts/common/ArchSetup.cmake new file mode 100644 index 0000000..438e3bd --- /dev/null +++ b/project/cmake/scripts/common/ArchSetup.cmake | |||
| @@ -0,0 +1,150 @@ | |||
| 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 | |||
| 18 | # Macro to check if a given type exists in a given header | ||
| 19 | # Arguments: | ||
| 20 | # header the header to check | ||
| 21 | # type the type to check for existence | ||
| 22 | # var the compiler definition to set if type exists | ||
| 23 | # On return: | ||
| 24 | # If type was found, the definition is added to SYSTEM_DEFINES | ||
| 25 | macro(check_type header type var) | ||
| 26 | check_cxx_source_compiles("#include <${header}> | ||
| 27 | int main() | ||
| 28 | { | ||
| 29 | ${type} s; | ||
| 30 | }" ${var}) | ||
| 31 | if(${var}) | ||
| 32 | list(APPEND SYSTEM_DEFINES -D${var}=1) | ||
| 33 | endif() | ||
| 34 | endmacro() | ||
| 35 | |||
| 36 | # Macro to check if a given builtin function exists | ||
| 37 | # Arguments: | ||
| 38 | # func the function to check | ||
| 39 | # var the compiler definition to set if type exists | ||
| 40 | # On return: | ||
| 41 | # If type was found, the definition is added to SYSTEM_DEFINES | ||
| 42 | macro(check_builtin func var) | ||
| 43 | check_cxx_source_compiles(" | ||
| 44 | int main() | ||
| 45 | { | ||
| 46 | ${func}; | ||
| 47 | }" ${var}) | ||
| 48 | if(${var}) | ||
| 49 | list(APPEND SYSTEM_DEFINES -D${var}=1) | ||
| 50 | endif() | ||
| 51 | endmacro() | ||
| 52 | |||
| 53 | |||
| 54 | # -------- Main script --------- | ||
| 55 | message(STATUS "System type: ${CMAKE_SYSTEM_NAME}") | ||
| 56 | if(NOT CORE_SYSTEM_NAME) | ||
| 57 | string(TOLOWER ${CMAKE_SYSTEM_NAME} CORE_SYSTEM_NAME) | ||
| 58 | endif() | ||
| 59 | |||
| 60 | if(WITH_CPU) | ||
| 61 | set(CPU ${WITH_CPU}) | ||
| 62 | elseif(NOT CMAKE_TOOLCHAIN_FILE) | ||
| 63 | set(CPU ${CMAKE_SYSTEM_PROCESSOR}) | ||
| 64 | endif() | ||
| 65 | |||
| 66 | if(CMAKE_TOOLCHAIN_FILE) | ||
| 67 | if(NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}") | ||
| 68 | message(FATAL_ERROR "Toolchain file ${CMAKE_TOOLCHAIN_FILE} does not exist.") | ||
| 69 | elseif(NOT DEPENDS_PATH OR NOT NATIVEPREFIX) | ||
| 70 | message(FATAL_ERROR "Toolchain did not define DEPENDS_PATH or NATIVEPREFIX. Possibly outdated depends.") | ||
| 71 | endif() | ||
| 72 | endif() | ||
| 73 | |||
| 74 | # While CMAKE_CROSSCOMPILING is set unconditionally if there's a toolchain file, | ||
| 75 | # this variable is set if we can execute build artefacts on the host system (for example unit tests). | ||
| 76 | if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL CMAKE_SYSTEM_PROCESSOR AND | ||
| 77 | CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) | ||
| 78 | set(CORE_HOST_IS_TARGET TRUE) | ||
| 79 | else() | ||
| 80 | set(CORE_HOST_IS_TARGET FALSE) | ||
| 81 | endif() | ||
| 82 | |||
| 83 | # Main cpp | ||
| 84 | set(CORE_MAIN_SOURCE ${CORE_SOURCE_DIR}/xbmc/platform/posix/main.cpp) | ||
| 85 | |||
| 86 | # system specific arch setup | ||
| 87 | if(NOT EXISTS ${PROJECT_SOURCE_DIR}/scripts/${CORE_SYSTEM_NAME}/ArchSetup.cmake) | ||
| 88 | message(FATAL_ERROR "Couldn't find configuration for '${CORE_SYSTEM_NAME}' " | ||
| 89 | "Either the platform is not (yet) supported " | ||
| 90 | "or a toolchain file has to be specified. " | ||
| 91 | "Consult ${CMAKE_SOURCE_DIR}/README.md for instructions. " | ||
| 92 | "Note: Specifying a toolchain requires a clean build directory!") | ||
| 93 | endif() | ||
| 94 | include(${PROJECT_SOURCE_DIR}/scripts/${CORE_SYSTEM_NAME}/ArchSetup.cmake) | ||
| 95 | |||
| 96 | message(STATUS "Core system type: ${CORE_SYSTEM_NAME}") | ||
| 97 | message(STATUS "Platform: ${PLATFORM}") | ||
| 98 | message(STATUS "CPU: ${CPU}, ARCH: ${ARCH}") | ||
| 99 | message(STATUS "Cross-Compiling: ${CMAKE_CROSSCOMPILING}") | ||
| 100 | message(STATUS "Execute build artefacts on host: ${CORE_HOST_IS_TARGET}") | ||
| 101 | |||
| 102 | check_type(string std::u16string HAVE_STD__U16_STRING) | ||
| 103 | check_type(string std::u32string HAVE_STD__U32_STRING) | ||
| 104 | check_type(string char16_t HAVE_CHAR16_T) | ||
| 105 | check_type(string char32_t HAVE_CHAR32_T) | ||
| 106 | check_type(stdint.h uint_least16_t HAVE_STDINT_H) | ||
| 107 | check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE) | ||
| 108 | check_symbol_exists(PRIdMAX inttypes.h HAVE_INTTYPES_H) | ||
| 109 | check_builtin("long* temp=0; long ret=__sync_add_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_ADD_AND_FETCH) | ||
| 110 | check_builtin("long* temp=0; long ret=__sync_sub_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_SUB_AND_FETCH) | ||
| 111 | check_builtin("long* temp=0; long ret=__sync_val_compare_and_swap(temp, 1, 1)" HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP) | ||
| 112 | if(HAVE_POSIX_FADVISE) | ||
| 113 | list(APPEND SYSTEM_DEFINES -DHAVE_POSIX_FADVISE=1) | ||
| 114 | endif() | ||
| 115 | check_function_exists(localtime_r HAVE_LOCALTIME_R) | ||
| 116 | if(HAVE_LOCALTIME_R) | ||
| 117 | list(APPEND SYSTEM_DEFINES -DHAVE_LOCALTIME_R=1) | ||
| 118 | endif() | ||
| 119 | if(HAVE_INTTYPES_H) | ||
| 120 | list(APPEND SYSTEM_DEFINES -DHAVE_INTTYPES_H=1) | ||
| 121 | endif() | ||
| 122 | |||
| 123 | find_package(SSE) | ||
| 124 | foreach(_sse SSE SSE2 SSE3 SSSE3 SSE4_1 SSE4_2 AVX AVX2) | ||
| 125 | if(${${_sse}_FOUND}) | ||
| 126 | # enable SSE versions up to 4.1 by default, if available | ||
| 127 | if(NOT ${_sse} MATCHES "AVX" AND NOT ${_sse} STREQUAL "SSE4_2") | ||
| 128 | option(ENABLE_${_sse} "Enable ${_sse}" ON) | ||
| 129 | else() | ||
| 130 | option(ENABLE_${_sse} "Enable ${_sse}" OFF) | ||
| 131 | endif() | ||
| 132 | endif() | ||
| 133 | if(ENABLE_${_sse}) | ||
| 134 | set(HAVE_${_sse} TRUE CACHE STRING "${_sse} enabled") | ||
| 135 | list(APPEND ARCH_DEFINES -DHAVE_${_sse}=1) | ||
| 136 | endif() | ||
| 137 | endforeach() | ||
| 138 | |||
| 139 | if(NOT DEFINED NEON OR NEON) | ||
| 140 | option(ENABLE_NEON "Enable NEON optimization" ${NEON}) | ||
| 141 | if(ENABLE_NEON) | ||
| 142 | message(STATUS "NEON optimization enabled") | ||
| 143 | add_options(CXX ALL_BUILDS "-mfpu=neon -mvectorize-with-neon-quad") | ||
| 144 | endif() | ||
| 145 | endif() | ||
| 146 | |||
| 147 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
| 148 | add_options (ALL_LANGUAGES DEBUG "-g" "-D_DEBUG" "-Wall") | ||
| 149 | endif() | ||
| 150 | |||
