[video] Fix bookmark thumbnails of rotated videos
[xbmc.git] / cmake / scripts / linux / ArchSetup.cmake
blobab142177c81b4d1e403d6fbd899771b5ecc23ead
1 include(cmake/scripts/linux/Linkers.txt)
3 # Main cpp
4 set(CORE_MAIN_SOURCE ${CMAKE_SOURCE_DIR}/xbmc/platform/posix/main.cpp)
6 # we always want to use GNU features if available, so set _GNU_SOURCE
7 list(APPEND ARCH_DEFINES -DTARGET_POSIX -DTARGET_LINUX -D_GNU_SOURCE)
8 set(SYSTEM_DEFINES -D__STDC_CONSTANT_MACROS -D_FILE_OFFSET_BITS=64)
9 set(PLATFORM_DIR platform/linux)
10 set(PLATFORMDEFS_DIR platform/posix)
11 set(CMAKE_SYSTEM_NAME Linux)
12 if(WITH_ARCH)
13   set(ARCH ${WITH_ARCH})
14 else()
15   if(CPU STREQUAL x86_64)
16     set(ARCH x86_64-linux)
17     set(NEON False)
18   elseif(CPU MATCHES "i.86")
19     set(ARCH i486-linux)
20     set(NEON False)
21     add_options(CXX ALL_BUILDS "-msse")
22   elseif(CPU STREQUAL arm1176jzf-s)
23     set(ARCH arm)
24     set(NEON False)
25     set(NEON_FLAGS "-mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp")
26   elseif(CPU MATCHES "cortex-a7")
27     set(ARCH arm)
28     set(NEON True)
29     set(NEON_FLAGS "-fPIC -mcpu=cortex-a7")
30   elseif(CPU MATCHES "cortex-a53")
31     set(ARCH arm)
32     set(NEON True)
33     set(NEON_FLAGS "-fPIC -mcpu=cortex-a53")
34   elseif(CPU MATCHES arm)
35     set(ARCH arm)
36     set(NEON True)
37   elseif(CPU MATCHES aarch64 OR CPU MATCHES arm64)
38     set(ARCH aarch64)
39     set(NEON True)
40   elseif(CPU MATCHES riscv64)
41     set(ARCH riscv64)
42     set(NEON False)
43   elseif(CPU MATCHES ppc64le)
44     set(ARCH ppc64le)
45     set(NEON False)
46   elseif(CPU MATCHES loongarch64)
47     set(ARCH loongarch64)
48     set(NEON False)
49   else()
50     message(SEND_ERROR "Unknown CPU: ${CPU}")
51   endif()
52 endif()
54 # disable the default gold linker when an alternative was enabled by the user
55 if(ENABLE_LLD OR ENABLE_MOLD)
56   set(ENABLE_GOLD OFF CACHE BOOL "" FORCE)
57 elseif(ENABLE_GOLD)
58   include(LDGOLD)
59 endif()
60 if(ENABLE_LLD)
61   set(ENABLE_MOLD OFF CACHE BOOL "" FORCE)
62   include(LLD)
63 elseif(ENABLE_MOLD)
64   set(ENABLE_LLD OFF CACHE BOOL "" FORCE)
65   include(MOLD)
66 endif()
69 if(CMAKE_BUILD_TYPE STREQUAL Release OR CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
71   # LTO Support, requires cmake >= 3.9
72   if(CMAKE_VERSION VERSION_EQUAL 3.9.0 OR CMAKE_VERSION VERSION_GREATER 3.9.0)
73     option(USE_LTO "Enable link time optimization. Specify an int for number of parallel jobs" OFF)
74     if(USE_LTO)
75       include(CheckIPOSupported)
76       check_ipo_supported(RESULT HAVE_LTO OUTPUT _output)
77       if(HAVE_LTO)
78         set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
80         # override flags to enable parallel processing
81         set(NJOBS 2)
82         if(USE_LTO MATCHES "^[0-9]+$")
83           set(NJOBS ${USE_LTO})
84         endif()
86         if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
87           # GCC
88           # Make sure we strip binaries in Release build
89           set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
90           set(CMAKE_CXX_COMPILE_OPTIONS_IPO -flto=${NJOBS} -fno-fat-lto-objects)
91           set(CMAKE_C_COMPILE_OPTIONS_IPO -flto=${NJOBS} -fno-fat-lto-objects)
92         elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
93           # CLANG
94           set(ENABLE_GOLD OFF CACHE BOOL "gold linker forced to off" FORCE)
96           find_package(LLVM REQUIRED)
98           if(NOT CLANG_LTO_CACHE)
99             set(CLANG_LTO_CACHE ${PROJECT_BINARY_DIR}/.clang-lto.cache)
100           endif()
101           if(USE_LTO STREQUAL "all")
102             set(NJOBS ${USE_LTO})
103           endif()
105           set(CMAKE_CXX_COMPILE_OPTIONS_IPO -flto=thin)
106           set(CMAKE_C_COMPILE_OPTIONS_IPO -flto=thin)
107           if(LLD_FOUND)
108             set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--thinlto-jobs=${NJOBS},--thinlto-cache-dir=${CLANG_LTO_CACHE}")
109           elseif(MOLD_FOUND)
110             set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--plugin-opt=jobs=${NJOBS},--plugin-opt=cache-dir=${CLANG_LTO_CACHE}")
111           endif()
112           set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
113           set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
114         endif()
115       else()
116         message(WARNING "LTO optimization not supported: ${_output}")
117         unset(_output)
118       endif()
119     endif()
120   endif()
121 endif()
123 if(KODI_DEPENDSBUILD)
124   # Binaries should be directly runnable from host, so include rpath to depends
125   set(CMAKE_INSTALL_RPATH "${DEPENDS_PATH}/lib")
126   set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
127 endif()
129 include(CheckIncludeFiles)
130 check_include_files("linux/udmabuf.h" HAVE_LINUX_UDMABUF)
131 if(HAVE_LINUX_UDMABUF)
132   list(APPEND ARCH_DEFINES "-DHAVE_LINUX_UDMABUF=1")
133 else()
134   message(STATUS "include/linux/udmabuf.h not found")
135 endif()
137 check_include_files("linux/dma-heap.h" HAVE_LINUX_DMA_HEAP)
138 if(HAVE_LINUX_DMA_HEAP)
139   list(APPEND ARCH_DEFINES "-DHAVE_LINUX_DMA_HEAP=1")
140 else()
141   message(STATUS "include/linux/dma-heap.h not found")
142 endif()
144 check_include_files("linux/dma-buf.h" HAVE_LINUX_DMA_BUF)
145 if(HAVE_LINUX_DMA_BUF)
146   list(APPEND ARCH_DEFINES "-DHAVE_LINUX_DMA_BUF=1")
147 else()
148   message(STATUS "include/linux/dma-buf.h not found")
149 endif()
151 include(CheckSymbolExists)
152 set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
153 check_symbol_exists("mkostemp" "stdlib.h" HAVE_MKOSTEMP)
154 set(CMAKE_REQUIRED_DEFINITIONS "")
155 if(HAVE_MKOSTEMP)
156   list(APPEND ARCH_DEFINES "-DHAVE_MKOSTEMP=1")
157 endif()
159 set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
160 check_symbol_exists("memfd_create" "sys/mman.h" HAVE_LINUX_MEMFD)
161 set(CMAKE_REQUIRED_DEFINITIONS "")
162 if(HAVE_LINUX_MEMFD)
163   list(APPEND ARCH_DEFINES "-DHAVE_LINUX_MEMFD=1")
164 else()
165   message(STATUS "memfd_create() not found")
166 endif()
168 # Additional SYSTEM_DEFINES
169 list(APPEND SYSTEM_DEFINES -DHAS_POSIX_NETWORK -DHAS_LINUX_NETWORK)
171 # Code Coverage
172 if(CMAKE_BUILD_TYPE STREQUAL Coverage)
173   set(COVERAGE_TEST_BINARY ${APP_NAME_LC}-test)
174   set(COVERAGE_SOURCE_DIR ${CMAKE_SOURCE_DIR})
175   set(COVERAGE_DEPENDS "\${APP_NAME_LC}" "\${APP_NAME_LC}-test")
176   set(COVERAGE_EXCLUDES */test/* lib/* */lib/*)
177 endif()
179 if(NOT "x11" IN_LIST CORE_PLATFORM_NAME_LC)
180   set(ENABLE_VDPAU OFF CACHE BOOL "Disabling VDPAU" FORCE)
181 endif()
183 if("x11" IN_LIST CORE_PLATFORM_NAME_LC AND ENABLE_VDPAU)
184   set(ENABLE_GLX ON CACHE BOOL "Enabling GLX" FORCE)
185 endif()
187 # Architecture endianness detector
188 include(TestBigEndian)
189 TEST_BIG_ENDIAN(ARCH_IS_BIGENDIAN)
190 if(ARCH_IS_BIGENDIAN)
191   message(STATUS "Host architecture is big-endian")
192   list(APPEND ARCH_DEFINES "-DWORDS_BIGENDIAN=1")
193 else()
194   message(STATUS "Host architecture is little-endian")
195 endif()
197 # Build internal libs
198 if(NOT USE_INTERNAL_LIBS)
199   if(KODI_DEPENDSBUILD)
200     set(USE_INTERNAL_LIBS ON)
201   else()
202     set(USE_INTERNAL_LIBS OFF)
203   endif()
204 endif()
206 # Atomic library
207 list(APPEND PLATFORM_REQUIRED_DEPS Atomic)