xref: /aosp_15_r20/external/libaom/build/cmake/aom_configure.cmake (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker#
2*77c1e3ccSAndroid Build Coastguard Worker# Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker#
4*77c1e3ccSAndroid Build Coastguard Worker# This source code is subject to the terms of the BSD 2 Clause License and the
5*77c1e3ccSAndroid Build Coastguard Worker# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
6*77c1e3ccSAndroid Build Coastguard Worker# not distributed with this source code in the LICENSE file, you can obtain it
7*77c1e3ccSAndroid Build Coastguard Worker# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
8*77c1e3ccSAndroid Build Coastguard Worker# License 1.0 was not distributed with this source code in the PATENTS file, you
9*77c1e3ccSAndroid Build Coastguard Worker# can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker#
11*77c1e3ccSAndroid Build Coastguard Workerif(AOM_BUILD_CMAKE_AOM_CONFIGURE_CMAKE_)
12*77c1e3ccSAndroid Build Coastguard Worker  return()
13*77c1e3ccSAndroid Build Coastguard Workerendif() # AOM_BUILD_CMAKE_AOM_CONFIGURE_CMAKE_
14*77c1e3ccSAndroid Build Coastguard Workerset(AOM_BUILD_CMAKE_AOM_CONFIGURE_CMAKE_ 1)
15*77c1e3ccSAndroid Build Coastguard Worker
16*77c1e3ccSAndroid Build Coastguard Workerinclude(FindThreads)
17*77c1e3ccSAndroid Build Coastguard Worker
18*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/aom_config_defaults.cmake")
19*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/aom_experiment_deps.cmake")
20*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/aom_optimization.cmake")
21*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/compiler_flags.cmake")
22*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/compiler_tests.cmake")
23*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/util.cmake")
24*77c1e3ccSAndroid Build Coastguard Worker
25*77c1e3ccSAndroid Build Coastguard Workerif(DEFINED CONFIG_LOWBITDEPTH)
26*77c1e3ccSAndroid Build Coastguard Worker  message(WARNING "CONFIG_LOWBITDEPTH has been removed. \
27*77c1e3ccSAndroid Build Coastguard Worker    Use -DFORCE_HIGHBITDEPTH_DECODING=1 instead of -DCONFIG_LOWBITDEPTH=0 \
28*77c1e3ccSAndroid Build Coastguard Worker    and -DFORCE_HIGHBITDEPTH_DECODING=0 instead of -DCONFIG_LOWBITDEPTH=1.")
29*77c1e3ccSAndroid Build Coastguard Worker  if(NOT CONFIG_LOWBITDEPTH)
30*77c1e3ccSAndroid Build Coastguard Worker    set(FORCE_HIGHBITDEPTH_DECODING
31*77c1e3ccSAndroid Build Coastguard Worker        1
32*77c1e3ccSAndroid Build Coastguard Worker        CACHE STRING "${cmake_cmdline_helpstring}" FORCE)
33*77c1e3ccSAndroid Build Coastguard Worker  endif()
34*77c1e3ccSAndroid Build Coastguard Workerendif()
35*77c1e3ccSAndroid Build Coastguard Worker
36*77c1e3ccSAndroid Build Coastguard Workerif(FORCE_HIGHBITDEPTH_DECODING AND NOT CONFIG_AV1_HIGHBITDEPTH)
37*77c1e3ccSAndroid Build Coastguard Worker  change_config_and_warn(CONFIG_AV1_HIGHBITDEPTH 1
38*77c1e3ccSAndroid Build Coastguard Worker                         "FORCE_HIGHBITDEPTH_DECODING")
39*77c1e3ccSAndroid Build Coastguard Workerendif()
40*77c1e3ccSAndroid Build Coastguard Worker
41*77c1e3ccSAndroid Build Coastguard Workerif(CONFIG_THREE_PASS AND NOT CONFIG_AV1_DECODER)
42*77c1e3ccSAndroid Build Coastguard Worker  change_config_and_warn(CONFIG_THREE_PASS 0 "CONFIG_AV1_DECODER=0")
43*77c1e3ccSAndroid Build Coastguard Workerendif()
44*77c1e3ccSAndroid Build Coastguard Worker
45*77c1e3ccSAndroid Build Coastguard Worker# Generate the user config settings.
46*77c1e3ccSAndroid Build Coastguard Workerlist(APPEND aom_build_vars ${AOM_CONFIG_VARS} ${AOM_OPTION_VARS})
47*77c1e3ccSAndroid Build Coastguard Workerforeach(cache_var ${aom_build_vars})
48*77c1e3ccSAndroid Build Coastguard Worker  get_property(cache_var_helpstring CACHE ${cache_var} PROPERTY HELPSTRING)
49*77c1e3ccSAndroid Build Coastguard Worker  if(cache_var_helpstring STREQUAL cmake_cmdline_helpstring)
50*77c1e3ccSAndroid Build Coastguard Worker    set(AOM_CMAKE_CONFIG "${AOM_CMAKE_CONFIG} -D${cache_var}=${${cache_var}}")
51*77c1e3ccSAndroid Build Coastguard Worker  endif()
52*77c1e3ccSAndroid Build Coastguard Workerendforeach()
53*77c1e3ccSAndroid Build Coastguard Workerstring(STRIP "${AOM_CMAKE_CONFIG}" AOM_CMAKE_CONFIG)
54*77c1e3ccSAndroid Build Coastguard Worker
55*77c1e3ccSAndroid Build Coastguard Worker# Detect target CPU.
56*77c1e3ccSAndroid Build Coastguard Workerif(NOT AOM_TARGET_CPU)
57*77c1e3ccSAndroid Build Coastguard Worker  string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" cpu_lowercase)
58*77c1e3ccSAndroid Build Coastguard Worker  if(cpu_lowercase STREQUAL "amd64" OR cpu_lowercase STREQUAL "x86_64")
59*77c1e3ccSAndroid Build Coastguard Worker    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
60*77c1e3ccSAndroid Build Coastguard Worker      set(AOM_TARGET_CPU "x86")
61*77c1e3ccSAndroid Build Coastguard Worker    elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
62*77c1e3ccSAndroid Build Coastguard Worker      set(AOM_TARGET_CPU "x86_64")
63*77c1e3ccSAndroid Build Coastguard Worker    else()
64*77c1e3ccSAndroid Build Coastguard Worker      message(
65*77c1e3ccSAndroid Build Coastguard Worker        FATAL_ERROR "--- Unexpected pointer size (${CMAKE_SIZEOF_VOID_P}) for\n"
66*77c1e3ccSAndroid Build Coastguard Worker                    "      CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}\n"
67*77c1e3ccSAndroid Build Coastguard Worker                    "      CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}\n"
68*77c1e3ccSAndroid Build Coastguard Worker                    "      CMAKE_GENERATOR=${CMAKE_GENERATOR}\n")
69*77c1e3ccSAndroid Build Coastguard Worker    endif()
70*77c1e3ccSAndroid Build Coastguard Worker  elseif(cpu_lowercase STREQUAL "i386" OR cpu_lowercase STREQUAL "x86")
71*77c1e3ccSAndroid Build Coastguard Worker    set(AOM_TARGET_CPU "x86")
72*77c1e3ccSAndroid Build Coastguard Worker  elseif(cpu_lowercase MATCHES "^arm")
73*77c1e3ccSAndroid Build Coastguard Worker    set(AOM_TARGET_CPU "${cpu_lowercase}")
74*77c1e3ccSAndroid Build Coastguard Worker  elseif(cpu_lowercase MATCHES "aarch64")
75*77c1e3ccSAndroid Build Coastguard Worker    set(AOM_TARGET_CPU "arm64")
76*77c1e3ccSAndroid Build Coastguard Worker  elseif(cpu_lowercase MATCHES "^ppc")
77*77c1e3ccSAndroid Build Coastguard Worker    set(AOM_TARGET_CPU "ppc")
78*77c1e3ccSAndroid Build Coastguard Worker  else()
79*77c1e3ccSAndroid Build Coastguard Worker    message(WARNING "The architecture ${CMAKE_SYSTEM_PROCESSOR} is not "
80*77c1e3ccSAndroid Build Coastguard Worker                    "supported, falling back to the generic target")
81*77c1e3ccSAndroid Build Coastguard Worker    set(AOM_TARGET_CPU "generic")
82*77c1e3ccSAndroid Build Coastguard Worker  endif()
83*77c1e3ccSAndroid Build Coastguard Workerendif()
84*77c1e3ccSAndroid Build Coastguard Worker
85*77c1e3ccSAndroid Build Coastguard Workerif(CMAKE_TOOLCHAIN_FILE) # Add toolchain file to config string.
86*77c1e3ccSAndroid Build Coastguard Worker  if(IS_ABSOLUTE "${CMAKE_TOOLCHAIN_FILE}")
87*77c1e3ccSAndroid Build Coastguard Worker    file(RELATIVE_PATH toolchain_path "${AOM_CONFIG_DIR}"
88*77c1e3ccSAndroid Build Coastguard Worker         "${CMAKE_TOOLCHAIN_FILE}")
89*77c1e3ccSAndroid Build Coastguard Worker  else()
90*77c1e3ccSAndroid Build Coastguard Worker    set(toolchain_path "${CMAKE_TOOLCHAIN_FILE}")
91*77c1e3ccSAndroid Build Coastguard Worker  endif()
92*77c1e3ccSAndroid Build Coastguard Worker  set(toolchain_string "-DCMAKE_TOOLCHAIN_FILE=\\\"${toolchain_path}\\\"")
93*77c1e3ccSAndroid Build Coastguard Worker  set(AOM_CMAKE_CONFIG "${toolchain_string} ${AOM_CMAKE_CONFIG}")
94*77c1e3ccSAndroid Build Coastguard Workerelse()
95*77c1e3ccSAndroid Build Coastguard Worker
96*77c1e3ccSAndroid Build Coastguard Worker  # Add detected CPU to the config string.
97*77c1e3ccSAndroid Build Coastguard Worker  set(AOM_CMAKE_CONFIG "-DAOM_TARGET_CPU=${AOM_TARGET_CPU} ${AOM_CMAKE_CONFIG}")
98*77c1e3ccSAndroid Build Coastguard Workerendif()
99*77c1e3ccSAndroid Build Coastguard Workerset(AOM_CMAKE_CONFIG "-G \\\"${CMAKE_GENERATOR}\\\" ${AOM_CMAKE_CONFIG}")
100*77c1e3ccSAndroid Build Coastguard Workerfile(RELATIVE_PATH source_path "${AOM_CONFIG_DIR}" "${AOM_ROOT}")
101*77c1e3ccSAndroid Build Coastguard Workerset(AOM_CMAKE_CONFIG "cmake ${source_path} ${AOM_CMAKE_CONFIG}")
102*77c1e3ccSAndroid Build Coastguard Workerstring(STRIP "${AOM_CMAKE_CONFIG}" AOM_CMAKE_CONFIG)
103*77c1e3ccSAndroid Build Coastguard Worker
104*77c1e3ccSAndroid Build Coastguard Workermessage("--- aom_configure: Detected CPU: ${AOM_TARGET_CPU}")
105*77c1e3ccSAndroid Build Coastguard Workerset(AOM_TARGET_SYSTEM ${CMAKE_SYSTEM_NAME})
106*77c1e3ccSAndroid Build Coastguard Worker
107*77c1e3ccSAndroid Build Coastguard Workerstring(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lowercase)
108*77c1e3ccSAndroid Build Coastguard Workerif(build_type_lowercase STREQUAL "debug")
109*77c1e3ccSAndroid Build Coastguard Worker  set(CONFIG_DEBUG 1)
110*77c1e3ccSAndroid Build Coastguard Workerendif()
111*77c1e3ccSAndroid Build Coastguard Worker
112*77c1e3ccSAndroid Build Coastguard Workerif(BUILD_SHARED_LIBS)
113*77c1e3ccSAndroid Build Coastguard Worker  set(CONFIG_PIC 1)
114*77c1e3ccSAndroid Build Coastguard Worker  set(CONFIG_SHARED 1)
115*77c1e3ccSAndroid Build Coastguard Workerelseif(NOT CONFIG_PIC)
116*77c1e3ccSAndroid Build Coastguard Worker  # Update the variable only when it does not carry the CMake assigned help
117*77c1e3ccSAndroid Build Coastguard Worker  # string for variables specified via the command line. This allows the user to
118*77c1e3ccSAndroid Build Coastguard Worker  # force CONFIG_PIC=0.
119*77c1e3ccSAndroid Build Coastguard Worker  unset(cache_helpstring)
120*77c1e3ccSAndroid Build Coastguard Worker  get_property(cache_helpstring CACHE CONFIG_PIC PROPERTY HELPSTRING)
121*77c1e3ccSAndroid Build Coastguard Worker  if(NOT "${cache_helpstring}" STREQUAL "${cmake_cmdline_helpstring}")
122*77c1e3ccSAndroid Build Coastguard Worker    aom_check_c_compiles("pie_check" "
123*77c1e3ccSAndroid Build Coastguard Worker                          #if !(__pie__ || __PIE__)
124*77c1e3ccSAndroid Build Coastguard Worker                          #error Neither __pie__ or __PIE__ are set
125*77c1e3ccSAndroid Build Coastguard Worker                          #endif
126*77c1e3ccSAndroid Build Coastguard Worker                          extern void unused(void);
127*77c1e3ccSAndroid Build Coastguard Worker                          void unused(void) {}" HAVE_PIE)
128*77c1e3ccSAndroid Build Coastguard Worker
129*77c1e3ccSAndroid Build Coastguard Worker    if(HAVE_PIE)
130*77c1e3ccSAndroid Build Coastguard Worker      # If -fpie or -fPIE are used ensure the assembly code has PIC enabled to
131*77c1e3ccSAndroid Build Coastguard Worker      # avoid DT_TEXTRELs: /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
132*77c1e3ccSAndroid Build Coastguard Worker      set(CONFIG_PIC 1)
133*77c1e3ccSAndroid Build Coastguard Worker      message(
134*77c1e3ccSAndroid Build Coastguard Worker        "CONFIG_PIC enabled for position independent executable (PIE) build")
135*77c1e3ccSAndroid Build Coastguard Worker    endif()
136*77c1e3ccSAndroid Build Coastguard Worker  endif()
137*77c1e3ccSAndroid Build Coastguard Worker  unset(cache_helpstring)
138*77c1e3ccSAndroid Build Coastguard Workerendif()
139*77c1e3ccSAndroid Build Coastguard Worker
140*77c1e3ccSAndroid Build Coastguard Workerif(NOT MSVC)
141*77c1e3ccSAndroid Build Coastguard Worker  if(CONFIG_PIC)
142*77c1e3ccSAndroid Build Coastguard Worker
143*77c1e3ccSAndroid Build Coastguard Worker    # TODO(tomfinegan): clang needs -pie in CMAKE_EXE_LINKER_FLAGS for this to
144*77c1e3ccSAndroid Build Coastguard Worker    # work.
145*77c1e3ccSAndroid Build Coastguard Worker    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
146*77c1e3ccSAndroid Build Coastguard Worker    if(AOM_TARGET_SYSTEM STREQUAL "Linux"
147*77c1e3ccSAndroid Build Coastguard Worker       AND AOM_TARGET_CPU MATCHES "^armv[78]")
148*77c1e3ccSAndroid Build Coastguard Worker      set(AOM_AS_FLAGS ${AOM_AS_FLAGS} --defsym PIC=1)
149*77c1e3ccSAndroid Build Coastguard Worker    else()
150*77c1e3ccSAndroid Build Coastguard Worker      set(AOM_AS_FLAGS ${AOM_AS_FLAGS} -DPIC)
151*77c1e3ccSAndroid Build Coastguard Worker    endif()
152*77c1e3ccSAndroid Build Coastguard Worker  endif()
153*77c1e3ccSAndroid Build Coastguard Workerendif()
154*77c1e3ccSAndroid Build Coastguard Worker
155*77c1e3ccSAndroid Build Coastguard Workerif(AOM_TARGET_CPU STREQUAL "x86" OR AOM_TARGET_CPU STREQUAL "x86_64")
156*77c1e3ccSAndroid Build Coastguard Worker  find_program(CMAKE_ASM_NASM_COMPILER yasm $ENV{YASM_PATH})
157*77c1e3ccSAndroid Build Coastguard Worker  if(NOT CMAKE_ASM_NASM_COMPILER OR ENABLE_NASM)
158*77c1e3ccSAndroid Build Coastguard Worker    unset(CMAKE_ASM_NASM_COMPILER CACHE)
159*77c1e3ccSAndroid Build Coastguard Worker    find_program(CMAKE_ASM_NASM_COMPILER nasm $ENV{NASM_PATH})
160*77c1e3ccSAndroid Build Coastguard Worker  endif()
161*77c1e3ccSAndroid Build Coastguard Worker
162*77c1e3ccSAndroid Build Coastguard Worker  include(CheckLanguage)
163*77c1e3ccSAndroid Build Coastguard Worker  check_language(ASM_NASM)
164*77c1e3ccSAndroid Build Coastguard Worker  if(CMAKE_ASM_NASM_COMPILER)
165*77c1e3ccSAndroid Build Coastguard Worker    get_asm_obj_format("objformat")
166*77c1e3ccSAndroid Build Coastguard Worker    unset(CMAKE_ASM_NASM_OBJECT_FORMAT)
167*77c1e3ccSAndroid Build Coastguard Worker    set(CMAKE_ASM_NASM_OBJECT_FORMAT ${objformat})
168*77c1e3ccSAndroid Build Coastguard Worker    enable_language(ASM_NASM)
169*77c1e3ccSAndroid Build Coastguard Worker    if(CMAKE_ASM_NASM_COMPILER_ID STREQUAL "NASM")
170*77c1e3ccSAndroid Build Coastguard Worker      test_nasm()
171*77c1e3ccSAndroid Build Coastguard Worker    endif()
172*77c1e3ccSAndroid Build Coastguard Worker    # Xcode requires building the objects manually, so pass the object format
173*77c1e3ccSAndroid Build Coastguard Worker    # flag.
174*77c1e3ccSAndroid Build Coastguard Worker    if(XCODE)
175*77c1e3ccSAndroid Build Coastguard Worker      set(AOM_AS_FLAGS -f ${objformat} ${AOM_AS_FLAGS})
176*77c1e3ccSAndroid Build Coastguard Worker    endif()
177*77c1e3ccSAndroid Build Coastguard Worker  else()
178*77c1e3ccSAndroid Build Coastguard Worker    message(
179*77c1e3ccSAndroid Build Coastguard Worker      FATAL_ERROR
180*77c1e3ccSAndroid Build Coastguard Worker        "Unable to find assembler. Install 'yasm' or 'nasm.' "
181*77c1e3ccSAndroid Build Coastguard Worker        "To build without optimizations, add -DAOM_TARGET_CPU=generic to "
182*77c1e3ccSAndroid Build Coastguard Worker        "your cmake command line.")
183*77c1e3ccSAndroid Build Coastguard Worker  endif()
184*77c1e3ccSAndroid Build Coastguard Worker  string(STRIP "${AOM_AS_FLAGS}" AOM_AS_FLAGS)
185*77c1e3ccSAndroid Build Coastguard Workerelseif(AOM_TARGET_CPU MATCHES "arm")
186*77c1e3ccSAndroid Build Coastguard Worker  if(AOM_TARGET_SYSTEM STREQUAL "Darwin")
187*77c1e3ccSAndroid Build Coastguard Worker    if(NOT CMAKE_ASM_COMPILER)
188*77c1e3ccSAndroid Build Coastguard Worker      set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
189*77c1e3ccSAndroid Build Coastguard Worker    endif()
190*77c1e3ccSAndroid Build Coastguard Worker    set(AOM_AS_FLAGS -arch ${AOM_TARGET_CPU} -isysroot ${CMAKE_OSX_SYSROOT})
191*77c1e3ccSAndroid Build Coastguard Worker  elseif(AOM_TARGET_SYSTEM STREQUAL "Windows")
192*77c1e3ccSAndroid Build Coastguard Worker    if(NOT CMAKE_ASM_COMPILER)
193*77c1e3ccSAndroid Build Coastguard Worker      set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER} "-c -mimplicit-it=always")
194*77c1e3ccSAndroid Build Coastguard Worker    endif()
195*77c1e3ccSAndroid Build Coastguard Worker  else()
196*77c1e3ccSAndroid Build Coastguard Worker    if(NOT CMAKE_ASM_COMPILER)
197*77c1e3ccSAndroid Build Coastguard Worker      set(CMAKE_ASM_COMPILER as)
198*77c1e3ccSAndroid Build Coastguard Worker    endif()
199*77c1e3ccSAndroid Build Coastguard Worker  endif()
200*77c1e3ccSAndroid Build Coastguard Worker  include(CheckLanguage)
201*77c1e3ccSAndroid Build Coastguard Worker  check_language(ASM)
202*77c1e3ccSAndroid Build Coastguard Worker  if(NOT CMAKE_ASM_COMPILER)
203*77c1e3ccSAndroid Build Coastguard Worker    message(
204*77c1e3ccSAndroid Build Coastguard Worker      FATAL_ERROR
205*77c1e3ccSAndroid Build Coastguard Worker        "Unable to find assembler and optimizations are enabled."
206*77c1e3ccSAndroid Build Coastguard Worker        "Searched for ${CMAKE_ASM_COMPILER}. Install it, add it to your path,"
207*77c1e3ccSAndroid Build Coastguard Worker        "or set the assembler directly by adding "
208*77c1e3ccSAndroid Build Coastguard Worker        "-DCMAKE_ASM_COMPILER=<assembler path> to your CMake command line."
209*77c1e3ccSAndroid Build Coastguard Worker        "To build without optimizations, add -DAOM_TARGET_CPU=generic to your "
210*77c1e3ccSAndroid Build Coastguard Worker        "cmake command line.")
211*77c1e3ccSAndroid Build Coastguard Worker  endif()
212*77c1e3ccSAndroid Build Coastguard Worker  enable_language(ASM)
213*77c1e3ccSAndroid Build Coastguard Worker  string(STRIP "${AOM_AS_FLAGS}" AOM_AS_FLAGS)
214*77c1e3ccSAndroid Build Coastguard Workerendif()
215*77c1e3ccSAndroid Build Coastguard Worker
216*77c1e3ccSAndroid Build Coastguard Workerif(CONFIG_ANALYZER)
217*77c1e3ccSAndroid Build Coastguard Worker  find_package(wxWidgets REQUIRED adv base core)
218*77c1e3ccSAndroid Build Coastguard Worker  include(${wxWidgets_USE_FILE})
219*77c1e3ccSAndroid Build Coastguard Workerendif()
220*77c1e3ccSAndroid Build Coastguard Worker
221*77c1e3ccSAndroid Build Coastguard Workerif(NOT MSVC AND CMAKE_C_COMPILER_ID MATCHES "GNU\|Clang")
222*77c1e3ccSAndroid Build Coastguard Worker  set(CONFIG_GCC 1)
223*77c1e3ccSAndroid Build Coastguard Workerendif()
224*77c1e3ccSAndroid Build Coastguard Worker
225*77c1e3ccSAndroid Build Coastguard Workerif(CONFIG_GCOV)
226*77c1e3ccSAndroid Build Coastguard Worker  message("--- Testing for CONFIG_GCOV support.")
227*77c1e3ccSAndroid Build Coastguard Worker  require_linker_flag("-fprofile-arcs -ftest-coverage")
228*77c1e3ccSAndroid Build Coastguard Worker  require_compiler_flag("-fprofile-arcs -ftest-coverage" YES)
229*77c1e3ccSAndroid Build Coastguard Workerendif()
230*77c1e3ccSAndroid Build Coastguard Worker
231*77c1e3ccSAndroid Build Coastguard Workerif(CONFIG_GPROF)
232*77c1e3ccSAndroid Build Coastguard Worker  message("--- Testing for CONFIG_GPROF support.")
233*77c1e3ccSAndroid Build Coastguard Worker  require_compiler_flag("-pg" YES)
234*77c1e3ccSAndroid Build Coastguard Workerendif()
235*77c1e3ccSAndroid Build Coastguard Worker
236*77c1e3ccSAndroid Build Coastguard Workerif(AOM_TARGET_SYSTEM MATCHES "Darwin\|Linux\|Windows\|Android")
237*77c1e3ccSAndroid Build Coastguard Worker  set(CONFIG_OS_SUPPORT 1)
238*77c1e3ccSAndroid Build Coastguard Workerendif()
239*77c1e3ccSAndroid Build Coastguard Worker
240*77c1e3ccSAndroid Build Coastguard Workerif(AOM_TARGET_SYSTEM STREQUAL "Windows")
241*77c1e3ccSAndroid Build Coastguard Worker  # The default _WIN32_WINNT value in MinGW is 0x0502 (Windows XP with SP2). Set
242*77c1e3ccSAndroid Build Coastguard Worker  # it to 0x0601 (Windows 7).
243*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-D_WIN32_WINNT=0x0601")
244*77c1e3ccSAndroid Build Coastguard Worker  # Quiet warnings related to fopen, printf, etc.
245*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-D_CRT_SECURE_NO_WARNINGS")
246*77c1e3ccSAndroid Build Coastguard Workerendif()
247*77c1e3ccSAndroid Build Coastguard Worker
248*77c1e3ccSAndroid Build Coastguard Worker#
249*77c1e3ccSAndroid Build Coastguard Worker# Fix CONFIG_* dependencies. This must be done before including cpu.cmake to
250*77c1e3ccSAndroid Build Coastguard Worker# ensure RTCD_CONFIG_* are properly set.
251*77c1e3ccSAndroid Build Coastguard Workerfix_experiment_configs()
252*77c1e3ccSAndroid Build Coastguard Worker
253*77c1e3ccSAndroid Build Coastguard Worker# Don't just check for pthread.h, but use the result of the full pthreads
254*77c1e3ccSAndroid Build Coastguard Worker# including a linking check in FindThreads above.
255*77c1e3ccSAndroid Build Coastguard Workerset(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
256*77c1e3ccSAndroid Build Coastguard Workeraom_check_source_compiles("unistd_check" "#include <unistd.h>" HAVE_UNISTD_H)
257*77c1e3ccSAndroid Build Coastguard Worker
258*77c1e3ccSAndroid Build Coastguard Workerif(NOT WIN32)
259*77c1e3ccSAndroid Build Coastguard Worker  aom_push_var(CMAKE_REQUIRED_LIBRARIES "m")
260*77c1e3ccSAndroid Build Coastguard Worker  aom_check_c_compiles("fenv_check" "#define _GNU_SOURCE
261*77c1e3ccSAndroid Build Coastguard Worker                        #include <fenv.h>
262*77c1e3ccSAndroid Build Coastguard Worker                        void unused(void) {
263*77c1e3ccSAndroid Build Coastguard Worker                          (void)unused;
264*77c1e3ccSAndroid Build Coastguard Worker                          (void)feenableexcept(FE_DIVBYZERO | FE_INVALID);
265*77c1e3ccSAndroid Build Coastguard Worker                        }" HAVE_FEXCEPT)
266*77c1e3ccSAndroid Build Coastguard Worker  aom_pop_var(CMAKE_REQUIRED_LIBRARIES)
267*77c1e3ccSAndroid Build Coastguard Workerendif()
268*77c1e3ccSAndroid Build Coastguard Worker
269*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/cpu.cmake")
270*77c1e3ccSAndroid Build Coastguard Worker
271*77c1e3ccSAndroid Build Coastguard Workerif(ENABLE_CCACHE)
272*77c1e3ccSAndroid Build Coastguard Worker  set_compiler_launcher(ENABLE_CCACHE ccache)
273*77c1e3ccSAndroid Build Coastguard Workerendif()
274*77c1e3ccSAndroid Build Coastguard Worker
275*77c1e3ccSAndroid Build Coastguard Workerif(ENABLE_DISTCC)
276*77c1e3ccSAndroid Build Coastguard Worker  set_compiler_launcher(ENABLE_DISTCC distcc)
277*77c1e3ccSAndroid Build Coastguard Workerendif()
278*77c1e3ccSAndroid Build Coastguard Worker
279*77c1e3ccSAndroid Build Coastguard Workerif(ENABLE_GOMA)
280*77c1e3ccSAndroid Build Coastguard Worker  set_compiler_launcher(ENABLE_GOMA gomacc)
281*77c1e3ccSAndroid Build Coastguard Workerendif()
282*77c1e3ccSAndroid Build Coastguard Worker
283*77c1e3ccSAndroid Build Coastguard Workerif(NOT CONFIG_AV1_DECODER AND NOT CONFIG_AV1_ENCODER)
284*77c1e3ccSAndroid Build Coastguard Worker  message(FATAL_ERROR "Decoder and encoder disabled, nothing to build.")
285*77c1e3ccSAndroid Build Coastguard Workerendif()
286*77c1e3ccSAndroid Build Coastguard Worker
287*77c1e3ccSAndroid Build Coastguard Workerif(DECODE_HEIGHT_LIMIT OR DECODE_WIDTH_LIMIT)
288*77c1e3ccSAndroid Build Coastguard Worker  change_config_and_warn(CONFIG_SIZE_LIMIT 1
289*77c1e3ccSAndroid Build Coastguard Worker                         "DECODE_HEIGHT_LIMIT and DECODE_WIDTH_LIMIT")
290*77c1e3ccSAndroid Build Coastguard Workerendif()
291*77c1e3ccSAndroid Build Coastguard Worker
292*77c1e3ccSAndroid Build Coastguard Workerif(CONFIG_SIZE_LIMIT)
293*77c1e3ccSAndroid Build Coastguard Worker  if(NOT DECODE_HEIGHT_LIMIT OR NOT DECODE_WIDTH_LIMIT)
294*77c1e3ccSAndroid Build Coastguard Worker    message(FATAL_ERROR "When setting CONFIG_SIZE_LIMIT, DECODE_HEIGHT_LIMIT "
295*77c1e3ccSAndroid Build Coastguard Worker                        "and DECODE_WIDTH_LIMIT must be set.")
296*77c1e3ccSAndroid Build Coastguard Worker  endif()
297*77c1e3ccSAndroid Build Coastguard Workerendif()
298*77c1e3ccSAndroid Build Coastguard Worker
299*77c1e3ccSAndroid Build Coastguard Worker# Test compiler flags.
300*77c1e3ccSAndroid Build Coastguard Workerif(MSVC)
301*77c1e3ccSAndroid Build Coastguard Worker  # It isn't possible to specify C99 conformance for MSVC. MSVC doesn't support
302*77c1e3ccSAndroid Build Coastguard Worker  # C++ standards modes earlier than C++14.
303*77c1e3ccSAndroid Build Coastguard Worker  add_cxx_flag_if_supported("/std:c++14")
304*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("/W3")
305*77c1e3ccSAndroid Build Coastguard Worker
306*77c1e3ccSAndroid Build Coastguard Worker  # Disable MSVC warnings that suggest making code non-portable.
307*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("/wd4996")
308*77c1e3ccSAndroid Build Coastguard Worker  if(ENABLE_WERROR)
309*77c1e3ccSAndroid Build Coastguard Worker    add_compiler_flag_if_supported("/WX")
310*77c1e3ccSAndroid Build Coastguard Worker  endif()
311*77c1e3ccSAndroid Build Coastguard Workerelse()
312*77c1e3ccSAndroid Build Coastguard Worker  require_c_flag("-std=c99" YES)
313*77c1e3ccSAndroid Build Coastguard Worker  if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
314*77c1e3ccSAndroid Build Coastguard Worker     AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU"
315*77c1e3ccSAndroid Build Coastguard Worker     AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
316*77c1e3ccSAndroid Build Coastguard Worker    # Microsoft's C++ Standard Library requires C++14 as it's MSVC's default and
317*77c1e3ccSAndroid Build Coastguard Worker    # minimum supported C++ version. If Clang is using this Standard Library
318*77c1e3ccSAndroid Build Coastguard Worker    # implementation, it cannot target C++11.
319*77c1e3ccSAndroid Build Coastguard Worker    require_cxx_flag_nomsvc("-std=c++14" YES)
320*77c1e3ccSAndroid Build Coastguard Worker  elseif(CYGWIN AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
321*77c1e3ccSAndroid Build Coastguard Worker    # The GNU C++ compiler in Cygwin needs the -std=gnu++11 flag to make the
322*77c1e3ccSAndroid Build Coastguard Worker    # POSIX function declarations visible in the Standard C Library headers.
323*77c1e3ccSAndroid Build Coastguard Worker    require_cxx_flag_nomsvc("-std=gnu++11" YES)
324*77c1e3ccSAndroid Build Coastguard Worker  else()
325*77c1e3ccSAndroid Build Coastguard Worker    require_cxx_flag_nomsvc("-std=c++11" YES)
326*77c1e3ccSAndroid Build Coastguard Worker  endif()
327*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wall")
328*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wdisabled-optimization")
329*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wextra")
330*77c1e3ccSAndroid Build Coastguard Worker  # Prior to version 3.19.0 cmake would fail to parse the warning emitted by gcc
331*77c1e3ccSAndroid Build Coastguard Worker  # with this flag. Note the order of this check and -Wextra-semi-stmt is
332*77c1e3ccSAndroid Build Coastguard Worker  # important due to is_flag_present() matching substrings with string(FIND
333*77c1e3ccSAndroid Build Coastguard Worker  # ...).
334*77c1e3ccSAndroid Build Coastguard Worker  if(CMAKE_VERSION VERSION_LESS "3.19"
335*77c1e3ccSAndroid Build Coastguard Worker     AND CMAKE_C_COMPILER_ID STREQUAL "GNU"
336*77c1e3ccSAndroid Build Coastguard Worker     AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
337*77c1e3ccSAndroid Build Coastguard Worker    add_cxx_flag_if_supported("-Wextra-semi")
338*77c1e3ccSAndroid Build Coastguard Worker  else()
339*77c1e3ccSAndroid Build Coastguard Worker    add_compiler_flag_if_supported("-Wextra-semi")
340*77c1e3ccSAndroid Build Coastguard Worker  endif()
341*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wextra-semi-stmt")
342*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wfloat-conversion")
343*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wformat=2")
344*77c1e3ccSAndroid Build Coastguard Worker  add_c_flag_if_supported("-Wimplicit-function-declaration")
345*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wlogical-op")
346*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wmissing-declarations")
347*77c1e3ccSAndroid Build Coastguard Worker  if(CMAKE_C_COMPILER_ID MATCHES "Clang")
348*77c1e3ccSAndroid Build Coastguard Worker    add_compiler_flag_if_supported("-Wmissing-prototypes")
349*77c1e3ccSAndroid Build Coastguard Worker  else()
350*77c1e3ccSAndroid Build Coastguard Worker    add_c_flag_if_supported("-Wmissing-prototypes")
351*77c1e3ccSAndroid Build Coastguard Worker  endif()
352*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wpointer-arith")
353*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wshadow")
354*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wshorten-64-to-32")
355*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wsign-compare")
356*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wstring-conversion")
357*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wtype-limits")
358*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wundef")
359*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wuninitialized")
360*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wunreachable-code-aggressive")
361*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wunused")
362*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-Wvla")
363*77c1e3ccSAndroid Build Coastguard Worker  add_cxx_flag_if_supported("-Wc++14-extensions")
364*77c1e3ccSAndroid Build Coastguard Worker  add_cxx_flag_if_supported("-Wc++17-extensions")
365*77c1e3ccSAndroid Build Coastguard Worker  add_cxx_flag_if_supported("-Wc++20-extensions")
366*77c1e3ccSAndroid Build Coastguard Worker
367*77c1e3ccSAndroid Build Coastguard Worker  if(CMAKE_C_COMPILER_ID MATCHES "GNU" AND SANITIZE MATCHES "address|undefined")
368*77c1e3ccSAndroid Build Coastguard Worker
369*77c1e3ccSAndroid Build Coastguard Worker    # This combination has more stack overhead, so we account for it by
370*77c1e3ccSAndroid Build Coastguard Worker    # providing higher stack limit than usual.
371*77c1e3ccSAndroid Build Coastguard Worker    add_c_flag_if_supported("-Wstack-usage=285000")
372*77c1e3ccSAndroid Build Coastguard Worker    add_cxx_flag_if_supported("-Wstack-usage=270000")
373*77c1e3ccSAndroid Build Coastguard Worker  elseif(CONFIG_RD_DEBUG) # Another case where higher stack usage is expected.
374*77c1e3ccSAndroid Build Coastguard Worker    add_c_flag_if_supported("-Wstack-usage=135000")
375*77c1e3ccSAndroid Build Coastguard Worker    add_cxx_flag_if_supported("-Wstack-usage=240000")
376*77c1e3ccSAndroid Build Coastguard Worker  else()
377*77c1e3ccSAndroid Build Coastguard Worker    add_c_flag_if_supported("-Wstack-usage=100000")
378*77c1e3ccSAndroid Build Coastguard Worker    add_cxx_flag_if_supported("-Wstack-usage=240000")
379*77c1e3ccSAndroid Build Coastguard Worker  endif()
380*77c1e3ccSAndroid Build Coastguard Worker
381*77c1e3ccSAndroid Build Coastguard Worker  if(CMAKE_C_COMPILER_ID MATCHES "GNU" AND SANITIZE MATCHES "address")
382*77c1e3ccSAndroid Build Coastguard Worker    # Disable no optimization warning when compiling with sanitizers
383*77c1e3ccSAndroid Build Coastguard Worker    add_compiler_flag_if_supported("-Wno-disabled-optimization")
384*77c1e3ccSAndroid Build Coastguard Worker  endif()
385*77c1e3ccSAndroid Build Coastguard Worker
386*77c1e3ccSAndroid Build Coastguard Worker  # Quiet gcc 6 vs 7 abi warnings:
387*77c1e3ccSAndroid Build Coastguard Worker  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77728
388*77c1e3ccSAndroid Build Coastguard Worker  if(AOM_TARGET_CPU MATCHES "arm")
389*77c1e3ccSAndroid Build Coastguard Worker    add_cxx_flag_if_supported("-Wno-psabi")
390*77c1e3ccSAndroid Build Coastguard Worker  endif()
391*77c1e3ccSAndroid Build Coastguard Worker
392*77c1e3ccSAndroid Build Coastguard Worker  if(ENABLE_WERROR)
393*77c1e3ccSAndroid Build Coastguard Worker    add_compiler_flag_if_supported("-Werror")
394*77c1e3ccSAndroid Build Coastguard Worker  endif()
395*77c1e3ccSAndroid Build Coastguard Worker
396*77c1e3ccSAndroid Build Coastguard Worker  if(build_type_lowercase MATCHES "rel")
397*77c1e3ccSAndroid Build Coastguard Worker    add_compiler_flag_if_supported("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0")
398*77c1e3ccSAndroid Build Coastguard Worker  endif()
399*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-D_LARGEFILE_SOURCE")
400*77c1e3ccSAndroid Build Coastguard Worker  add_compiler_flag_if_supported("-D_FILE_OFFSET_BITS=64")
401*77c1e3ccSAndroid Build Coastguard Worker
402*77c1e3ccSAndroid Build Coastguard Worker  # Do not allow implicit vector type conversions on Clang builds (this is
403*77c1e3ccSAndroid Build Coastguard Worker  # already the default on GCC builds).
404*77c1e3ccSAndroid Build Coastguard Worker  if(CMAKE_C_COMPILER_ID MATCHES "Clang")
405*77c1e3ccSAndroid Build Coastguard Worker    # Clang 8.0.1 (in Cygwin) doesn't support -flax-vector-conversions=none.
406*77c1e3ccSAndroid Build Coastguard Worker    add_compiler_flag_if_supported("-flax-vector-conversions=none")
407*77c1e3ccSAndroid Build Coastguard Worker  endif()
408*77c1e3ccSAndroid Build Coastguard Workerendif()
409*77c1e3ccSAndroid Build Coastguard Worker
410*77c1e3ccSAndroid Build Coastguard Worker# Prior to r23, or with ANDROID_USE_LEGACY_TOOLCHAIN_FILE set,
411*77c1e3ccSAndroid Build Coastguard Worker# android.toolchain.cmake would set normal (non-cache) versions of variables
412*77c1e3ccSAndroid Build Coastguard Worker# like CMAKE_C_FLAGS_RELEASE which would mask the ones added to the cache
413*77c1e3ccSAndroid Build Coastguard Worker# variable in add_compiler_flag_if_supported(), etc. As a workaround we add
414*77c1e3ccSAndroid Build Coastguard Worker# everything accumulated in AOM_C/CXX_FLAGS to the normal versions. This could
415*77c1e3ccSAndroid Build Coastguard Worker# also be addressed by reworking the flag tests and adding the results directly
416*77c1e3ccSAndroid Build Coastguard Worker# to target_compile_options() as in e.g., libgav1, but that's a larger task.
417*77c1e3ccSAndroid Build Coastguard Worker# https://github.com/android/ndk/wiki/Changelog-r23#changes
418*77c1e3ccSAndroid Build Coastguard Workerif(ANDROID
419*77c1e3ccSAndroid Build Coastguard Worker   AND ("${ANDROID_NDK_MAJOR}" LESS 23 OR ANDROID_USE_LEGACY_TOOLCHAIN_FILE))
420*77c1e3ccSAndroid Build Coastguard Worker  foreach(lang C;CXX)
421*77c1e3ccSAndroid Build Coastguard Worker    string(STRIP "${AOM_${lang}_FLAGS}" AOM_${lang}_FLAGS)
422*77c1e3ccSAndroid Build Coastguard Worker    if(AOM_${lang}_FLAGS)
423*77c1e3ccSAndroid Build Coastguard Worker      foreach(config ${AOM_${lang}_CONFIGS})
424*77c1e3ccSAndroid Build Coastguard Worker        set(${config} "${${config}} ${AOM_${lang}_FLAGS}")
425*77c1e3ccSAndroid Build Coastguard Worker      endforeach()
426*77c1e3ccSAndroid Build Coastguard Worker    endif()
427*77c1e3ccSAndroid Build Coastguard Worker  endforeach()
428*77c1e3ccSAndroid Build Coastguard Workerendif()
429*77c1e3ccSAndroid Build Coastguard Worker
430*77c1e3ccSAndroid Build Coastguard Workerset(AOM_LIB_LINK_TYPE PUBLIC)
431*77c1e3ccSAndroid Build Coastguard Workerif(EMSCRIPTEN)
432*77c1e3ccSAndroid Build Coastguard Worker
433*77c1e3ccSAndroid Build Coastguard Worker  # Avoid CMake generation time errors resulting from collisions with the form
434*77c1e3ccSAndroid Build Coastguard Worker  # of target_link_libraries() used by Emscripten.cmake.
435*77c1e3ccSAndroid Build Coastguard Worker  unset(AOM_LIB_LINK_TYPE)
436*77c1e3ccSAndroid Build Coastguard Workerendif()
437*77c1e3ccSAndroid Build Coastguard Worker
438*77c1e3ccSAndroid Build Coastguard Worker# Generate aom_config templates.
439*77c1e3ccSAndroid Build Coastguard Workerset(aom_config_asm_template "${AOM_CONFIG_DIR}/config/aom_config.asm.cmake")
440*77c1e3ccSAndroid Build Coastguard Workerset(aom_config_h_template "${AOM_CONFIG_DIR}/config/aom_config.h.cmake")
441*77c1e3ccSAndroid Build Coastguard Workerexecute_process(
442*77c1e3ccSAndroid Build Coastguard Worker  COMMAND ${CMAKE_COMMAND}
443*77c1e3ccSAndroid Build Coastguard Worker          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR} -DAOM_ROOT=${AOM_ROOT} -P
444*77c1e3ccSAndroid Build Coastguard Worker          "${AOM_ROOT}/build/cmake/generate_aom_config_templates.cmake")
445*77c1e3ccSAndroid Build Coastguard Worker
446*77c1e3ccSAndroid Build Coastguard Worker# Generate aom_config.{asm,h}.
447*77c1e3ccSAndroid Build Coastguard Workerconfigure_file("${aom_config_asm_template}"
448*77c1e3ccSAndroid Build Coastguard Worker               "${AOM_CONFIG_DIR}/config/aom_config.asm")
449*77c1e3ccSAndroid Build Coastguard Workerconfigure_file("${aom_config_h_template}"
450*77c1e3ccSAndroid Build Coastguard Worker               "${AOM_CONFIG_DIR}/config/aom_config.h")
451*77c1e3ccSAndroid Build Coastguard Worker
452*77c1e3ccSAndroid Build Coastguard Worker# Read the current git hash.
453*77c1e3ccSAndroid Build Coastguard Workerfind_package(Git)
454*77c1e3ccSAndroid Build Coastguard Workerif(NOT GIT_FOUND)
455*77c1e3ccSAndroid Build Coastguard Worker  message("--- Git missing, version will be read from CHANGELOG.")
456*77c1e3ccSAndroid Build Coastguard Workerendif()
457*77c1e3ccSAndroid Build Coastguard Worker
458*77c1e3ccSAndroid Build Coastguard Workerstring(TIMESTAMP year "%Y")
459*77c1e3ccSAndroid Build Coastguard Workerconfigure_file("${AOM_ROOT}/build/cmake/aom_config.c.template"
460*77c1e3ccSAndroid Build Coastguard Worker               "${AOM_CONFIG_DIR}/config/aom_config.c")
461*77c1e3ccSAndroid Build Coastguard Worker
462*77c1e3ccSAndroid Build Coastguard Worker# Find Perl and generate the RTCD sources.
463*77c1e3ccSAndroid Build Coastguard Workerfind_package(Perl)
464*77c1e3ccSAndroid Build Coastguard Workerif(NOT PERL_FOUND)
465*77c1e3ccSAndroid Build Coastguard Worker  message(FATAL_ERROR "Perl is required to build libaom.")
466*77c1e3ccSAndroid Build Coastguard Workerendif()
467*77c1e3ccSAndroid Build Coastguard Worker
468*77c1e3ccSAndroid Build Coastguard Workerset(AOM_RTCD_CONFIG_FILE_LIST "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
469*77c1e3ccSAndroid Build Coastguard Worker                              "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
470*77c1e3ccSAndroid Build Coastguard Worker                              "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl")
471*77c1e3ccSAndroid Build Coastguard Workerset(AOM_RTCD_HEADER_FILE_LIST "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
472*77c1e3ccSAndroid Build Coastguard Worker                              "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
473*77c1e3ccSAndroid Build Coastguard Worker                              "${AOM_CONFIG_DIR}/config/av1_rtcd.h")
474*77c1e3ccSAndroid Build Coastguard Workerset(AOM_RTCD_SOURCE_FILE_LIST "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
475*77c1e3ccSAndroid Build Coastguard Worker                              "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
476*77c1e3ccSAndroid Build Coastguard Worker                              "${AOM_ROOT}/av1/common/av1_rtcd.c")
477*77c1e3ccSAndroid Build Coastguard Workerset(AOM_RTCD_SYMBOL_LIST aom_dsp_rtcd aom_scale_rtcd av1_rtcd)
478*77c1e3ccSAndroid Build Coastguard Workerlist(LENGTH AOM_RTCD_SYMBOL_LIST AOM_RTCD_CUSTOM_COMMAND_COUNT)
479*77c1e3ccSAndroid Build Coastguard Workermath(EXPR AOM_RTCD_CUSTOM_COMMAND_COUNT "${AOM_RTCD_CUSTOM_COMMAND_COUNT} - 1")
480*77c1e3ccSAndroid Build Coastguard Worker
481*77c1e3ccSAndroid Build Coastguard Workerforeach(NUM RANGE ${AOM_RTCD_CUSTOM_COMMAND_COUNT})
482*77c1e3ccSAndroid Build Coastguard Worker  list(GET AOM_RTCD_CONFIG_FILE_LIST ${NUM} AOM_RTCD_CONFIG_FILE)
483*77c1e3ccSAndroid Build Coastguard Worker  list(GET AOM_RTCD_HEADER_FILE_LIST ${NUM} AOM_RTCD_HEADER_FILE)
484*77c1e3ccSAndroid Build Coastguard Worker  list(GET AOM_RTCD_SOURCE_FILE_LIST ${NUM} AOM_RTCD_SOURCE_FILE)
485*77c1e3ccSAndroid Build Coastguard Worker  list(GET AOM_RTCD_SYMBOL_LIST ${NUM} AOM_RTCD_SYMBOL)
486*77c1e3ccSAndroid Build Coastguard Worker  execute_process(
487*77c1e3ccSAndroid Build Coastguard Worker    COMMAND
488*77c1e3ccSAndroid Build Coastguard Worker      ${PERL_EXECUTABLE} "${AOM_ROOT}/build/cmake/rtcd.pl"
489*77c1e3ccSAndroid Build Coastguard Worker      --arch=${AOM_TARGET_CPU}
490*77c1e3ccSAndroid Build Coastguard Worker      --sym=${AOM_RTCD_SYMBOL} ${AOM_RTCD_FLAGS}
491*77c1e3ccSAndroid Build Coastguard Worker      --config=${AOM_CONFIG_DIR}/config/aom_config.h ${AOM_RTCD_CONFIG_FILE}
492*77c1e3ccSAndroid Build Coastguard Worker    OUTPUT_FILE ${AOM_RTCD_HEADER_FILE})
493*77c1e3ccSAndroid Build Coastguard Workerendforeach()
494*77c1e3ccSAndroid Build Coastguard Worker
495*77c1e3ccSAndroid Build Coastguard Worker# Generate aom_version.h.
496*77c1e3ccSAndroid Build Coastguard Workerexecute_process(COMMAND ${CMAKE_COMMAND}
497*77c1e3ccSAndroid Build Coastguard Worker                        -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
498*77c1e3ccSAndroid Build Coastguard Worker                        -DAOM_ROOT=${AOM_ROOT}
499*77c1e3ccSAndroid Build Coastguard Worker                        -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
500*77c1e3ccSAndroid Build Coastguard Worker                        -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
501*77c1e3ccSAndroid Build Coastguard Worker                        "${AOM_ROOT}/build/cmake/version.cmake")
502