summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/common/ArchSetup.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/scripts/common/ArchSetup.cmake')
-rw-r--r--project/cmake/scripts/common/ArchSetup.cmake150
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
14include(CheckCXXSourceCompiles)
15include(CheckSymbolExists)
16include(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
25macro(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()
34endmacro()
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
42macro(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()
51endmacro()
52
53
54# -------- Main script ---------
55message(STATUS "System type: ${CMAKE_SYSTEM_NAME}")
56if(NOT CORE_SYSTEM_NAME)
57 string(TOLOWER ${CMAKE_SYSTEM_NAME} CORE_SYSTEM_NAME)
58endif()
59
60if(WITH_CPU)
61 set(CPU ${WITH_CPU})
62elseif(NOT CMAKE_TOOLCHAIN_FILE)
63 set(CPU ${CMAKE_SYSTEM_PROCESSOR})
64endif()
65
66if(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()
72endif()
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).
76if(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)
79else()
80 set(CORE_HOST_IS_TARGET FALSE)
81endif()
82
83# Main cpp
84set(CORE_MAIN_SOURCE ${CORE_SOURCE_DIR}/xbmc/platform/posix/main.cpp)
85
86# system specific arch setup
87if(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!")
93endif()
94include(${PROJECT_SOURCE_DIR}/scripts/${CORE_SYSTEM_NAME}/ArchSetup.cmake)
95
96message(STATUS "Core system type: ${CORE_SYSTEM_NAME}")
97message(STATUS "Platform: ${PLATFORM}")
98message(STATUS "CPU: ${CPU}, ARCH: ${ARCH}")
99message(STATUS "Cross-Compiling: ${CMAKE_CROSSCOMPILING}")
100message(STATUS "Execute build artefacts on host: ${CORE_HOST_IS_TARGET}")
101
102check_type(string std::u16string HAVE_STD__U16_STRING)
103check_type(string std::u32string HAVE_STD__U32_STRING)
104check_type(string char16_t HAVE_CHAR16_T)
105check_type(string char32_t HAVE_CHAR32_T)
106check_type(stdint.h uint_least16_t HAVE_STDINT_H)
107check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE)
108check_symbol_exists(PRIdMAX inttypes.h HAVE_INTTYPES_H)
109check_builtin("long* temp=0; long ret=__sync_add_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_ADD_AND_FETCH)
110check_builtin("long* temp=0; long ret=__sync_sub_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_SUB_AND_FETCH)
111check_builtin("long* temp=0; long ret=__sync_val_compare_and_swap(temp, 1, 1)" HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP)
112if(HAVE_POSIX_FADVISE)
113 list(APPEND SYSTEM_DEFINES -DHAVE_POSIX_FADVISE=1)
114endif()
115check_function_exists(localtime_r HAVE_LOCALTIME_R)
116if(HAVE_LOCALTIME_R)
117 list(APPEND SYSTEM_DEFINES -DHAVE_LOCALTIME_R=1)
118endif()
119if(HAVE_INTTYPES_H)
120 list(APPEND SYSTEM_DEFINES -DHAVE_INTTYPES_H=1)
121endif()
122
123find_package(SSE)
124foreach(_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()
137endforeach()
138
139if(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()
145endif()
146
147if(CMAKE_BUILD_TYPE STREQUAL "Debug")
148 add_options (ALL_LANGUAGES DEBUG "-g" "-D_DEBUG" "-Wall")
149endif()
150