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.cmake99
1 files changed, 99 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..dff5558
--- /dev/null
+++ b/project/cmake/scripts/common/archsetup.cmake
@@ -0,0 +1,99 @@
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# Main cpp
75set(CORE_MAIN_SOURCE ${CORE_SOURCE_DIR}/xbmc/platform/posix/main.cpp)
76
77# system specific arch setup
78include(${PROJECT_SOURCE_DIR}/scripts/${CORE_SYSTEM_NAME}/archsetup.cmake)
79
80message(STATUS "Core system type: ${CORE_SYSTEM_NAME}")
81message(STATUS "Platform: ${PLATFORM}")
82message(STATUS "CPU: ${CPU}, ARCH: ${ARCH}")
83
84check_type(string std::u16string HAVE_STD__U16_STRING)
85check_type(string std::u32string HAVE_STD__U32_STRING)
86check_type(string char16_t HAVE_CHAR16_T)
87check_type(string char32_t HAVE_CHAR32_T)
88check_type(stdint.h uint_least16_t HAVE_STDINT_H)
89check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE)
90check_builtin("long* temp=0; long ret=__sync_add_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_ADD_AND_FETCH)
91check_builtin("long* temp=0; long ret=__sync_sub_and_fetch(temp, 1)" HAS_BUILTIN_SYNC_SUB_AND_FETCH)
92check_builtin("long* temp=0; long ret=__sync_val_compare_and_swap(temp, 1, 1)" HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP)
93if(HAVE_POSIX_FADVISE)
94 list(APPEND SYSTEM_DEFINES -DHAVE_POSIX_FADVISE=1)
95endif()
96check_function_exists(localtime_r HAVE_LOCALTIME_R)
97if(HAVE_LOCALTIME_R)
98 list(APPEND SYSTEM_DEFINES -DHAVE_LOCALTIME_R=1)
99endif()