1 include(cmake/scripts/linux/Linkers.txt)
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)
13 set(ARCH ${WITH_ARCH})
15 if(CPU STREQUAL x86_64)
16 set(ARCH x86_64-linux)
18 elseif(CPU MATCHES "i.86")
21 add_options(CXX ALL_BUILDS "-msse")
22 elseif(CPU STREQUAL arm1176jzf-s)
25 set(NEON_FLAGS "-mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp")
26 elseif(CPU MATCHES "cortex-a7")
29 set(NEON_FLAGS "-fPIC -mcpu=cortex-a7")
30 elseif(CPU MATCHES "cortex-a53")
33 set(NEON_FLAGS "-fPIC -mcpu=cortex-a53")
34 elseif(CPU MATCHES arm)
37 elseif(CPU MATCHES aarch64 OR CPU MATCHES arm64)
40 elseif(CPU MATCHES riscv64)
43 elseif(CPU MATCHES ppc64le)
46 elseif(CPU MATCHES loongarch64)
50 message(SEND_ERROR "Unknown CPU: ${CPU}")
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)
61 set(ENABLE_MOLD OFF CACHE BOOL "" FORCE)
64 set(ENABLE_LLD OFF CACHE BOOL "" FORCE)
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)
75 include(CheckIPOSupported)
76 check_ipo_supported(RESULT HAVE_LTO OUTPUT _output)
78 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
80 # override flags to enable parallel processing
82 if(USE_LTO MATCHES "^[0-9]+$")
86 if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
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")
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)
101 if(USE_LTO STREQUAL "all")
102 set(NJOBS ${USE_LTO})
105 set(CMAKE_CXX_COMPILE_OPTIONS_IPO -flto=thin)
106 set(CMAKE_C_COMPILE_OPTIONS_IPO -flto=thin)
108 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--thinlto-jobs=${NJOBS},--thinlto-cache-dir=${CLANG_LTO_CACHE}")
110 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--plugin-opt=jobs=${NJOBS},--plugin-opt=cache-dir=${CLANG_LTO_CACHE}")
112 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
113 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
116 message(WARNING "LTO optimization not supported: ${_output}")
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)
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")
134 message(STATUS "include/linux/udmabuf.h not found")
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")
141 message(STATUS "include/linux/dma-heap.h not found")
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")
148 message(STATUS "include/linux/dma-buf.h not found")
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 "")
156 list(APPEND ARCH_DEFINES "-DHAVE_MKOSTEMP=1")
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 "")
163 list(APPEND ARCH_DEFINES "-DHAVE_LINUX_MEMFD=1")
165 message(STATUS "memfd_create() not found")
168 # Additional SYSTEM_DEFINES
169 list(APPEND SYSTEM_DEFINES -DHAS_POSIX_NETWORK -DHAS_LINUX_NETWORK)
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/*)
179 if(NOT "x11" IN_LIST CORE_PLATFORM_NAME_LC)
180 set(ENABLE_VDPAU OFF CACHE BOOL "Disabling VDPAU" FORCE)
183 if("x11" IN_LIST CORE_PLATFORM_NAME_LC AND ENABLE_VDPAU)
184 set(ENABLE_GLX ON CACHE BOOL "Enabling GLX" FORCE)
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")
194 message(STATUS "Host architecture is little-endian")
197 # Build internal libs
198 if(NOT USE_INTERNAL_LIBS)
199 if(KODI_DEPENDSBUILD)
200 set(USE_INTERNAL_LIBS ON)
202 set(USE_INTERNAL_LIBS OFF)
207 list(APPEND PLATFORM_REQUIRED_DEPS Atomic)