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_COMPILER_FLAGS_CMAKE_) 12*77c1e3ccSAndroid Build Coastguard Worker return() 13*77c1e3ccSAndroid Build Coastguard Workerendif() # AOM_BUILD_CMAKE_COMPILER_FLAGS_CMAKE_ 14*77c1e3ccSAndroid Build Coastguard Workerset(AOM_BUILD_CMAKE_COMPILER_FLAGS_CMAKE_ 1) 15*77c1e3ccSAndroid Build Coastguard Worker 16*77c1e3ccSAndroid Build Coastguard Workerinclude(CheckCCompilerFlag) 17*77c1e3ccSAndroid Build Coastguard Workerinclude(CheckCXXCompilerFlag) 18*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/compiler_tests.cmake") 19*77c1e3ccSAndroid Build Coastguard Worker 20*77c1e3ccSAndroid Build Coastguard Worker# Strings used to cache flags. 21*77c1e3ccSAndroid Build Coastguard Workerset(AOM_C_FLAGS) 22*77c1e3ccSAndroid Build Coastguard Workerset(AOM_CXX_FLAGS) 23*77c1e3ccSAndroid Build Coastguard Workerset(AOM_EXE_LINKER_FLAGS) 24*77c1e3ccSAndroid Build Coastguard Workerset(AOM_FAILED_C_FLAGS) 25*77c1e3ccSAndroid Build Coastguard Workerset(AOM_FAILED_CXX_FLAGS) 26*77c1e3ccSAndroid Build Coastguard Worker 27*77c1e3ccSAndroid Build Coastguard Worker# Sets variable named by $out_is_present to YES in the caller's scope when $flag 28*77c1e3ccSAndroid Build Coastguard Worker# is found in the string variable named by $flag_cache. Sets the var to NO 29*77c1e3ccSAndroid Build Coastguard Worker# otherwise. 30*77c1e3ccSAndroid Build Coastguard Workerfunction(is_flag_present flag_cache flag out_is_present) 31*77c1e3ccSAndroid Build Coastguard Worker string(FIND "${${flag_cache}}" "${flag}" flag_pos) 32*77c1e3ccSAndroid Build Coastguard Worker if(${flag_pos} EQUAL -1) 33*77c1e3ccSAndroid Build Coastguard Worker set(${out_is_present} NO PARENT_SCOPE) 34*77c1e3ccSAndroid Build Coastguard Worker else() 35*77c1e3ccSAndroid Build Coastguard Worker set(${out_is_present} YES PARENT_SCOPE) 36*77c1e3ccSAndroid Build Coastguard Worker endif() 37*77c1e3ccSAndroid Build Coastguard Workerendfunction() 38*77c1e3ccSAndroid Build Coastguard Worker 39*77c1e3ccSAndroid Build Coastguard Worker# Appends $flag to $flags. Ignores scope via use of FORCE with set() call. 40*77c1e3ccSAndroid Build Coastguard Workerfunction(append_flag flags flag) 41*77c1e3ccSAndroid Build Coastguard Worker string(FIND "${${flags}}" "${flag}" found) 42*77c1e3ccSAndroid Build Coastguard Worker if(${found} EQUAL -1) 43*77c1e3ccSAndroid Build Coastguard Worker set(${flags} "${${flags}} ${flag}" CACHE STRING "" FORCE) 44*77c1e3ccSAndroid Build Coastguard Worker endif() 45*77c1e3ccSAndroid Build Coastguard Workerendfunction() 46*77c1e3ccSAndroid Build Coastguard Worker 47*77c1e3ccSAndroid Build Coastguard Worker# Checks C compiler for support of $c_flag. Adds $c_flag to all 48*77c1e3ccSAndroid Build Coastguard Worker# $CMAKE_C_FLAGS_<CONFIG>s stored in AOM_C_CONFIGS when the compile test passes. 49*77c1e3ccSAndroid Build Coastguard Worker# Caches $c_flag in $AOM_C_FLAGS or $AOM_FAILED_C_FLAGS depending on test 50*77c1e3ccSAndroid Build Coastguard Worker# outcome. 51*77c1e3ccSAndroid Build Coastguard Workerfunction(add_c_flag_if_supported c_flag) 52*77c1e3ccSAndroid Build Coastguard Worker if(DEBUG_CMAKE_DISABLE_COMPILER_TESTS) 53*77c1e3ccSAndroid Build Coastguard Worker return() 54*77c1e3ccSAndroid Build Coastguard Worker endif() 55*77c1e3ccSAndroid Build Coastguard Worker 56*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_C_FLAGS "${c_flag}" flag_ok) 57*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_FAILED_C_FLAGS "${c_flag}" flag_failed) 58*77c1e3ccSAndroid Build Coastguard Worker if(${flag_ok} OR ${flag_failed}) 59*77c1e3ccSAndroid Build Coastguard Worker return() 60*77c1e3ccSAndroid Build Coastguard Worker endif() 61*77c1e3ccSAndroid Build Coastguard Worker 62*77c1e3ccSAndroid Build Coastguard Worker # Between 3.17.0 and 3.18.2 check_c_compiler_flag() sets a normal variable at 63*77c1e3ccSAndroid Build Coastguard Worker # parent scope while check_cxx_source_compiles() continues to set an internal 64*77c1e3ccSAndroid Build Coastguard Worker # cache variable, so we unset both to avoid the failure / success state 65*77c1e3ccSAndroid Build Coastguard Worker # persisting between checks. See 66*77c1e3ccSAndroid Build Coastguard Worker # https://gitlab.kitware.com/cmake/cmake/-/issues/21207. 67*77c1e3ccSAndroid Build Coastguard Worker unset(C_FLAG_SUPPORTED) 68*77c1e3ccSAndroid Build Coastguard Worker unset(C_FLAG_SUPPORTED CACHE) 69*77c1e3ccSAndroid Build Coastguard Worker message("Checking C compiler flag support for: " ${c_flag}) 70*77c1e3ccSAndroid Build Coastguard Worker check_c_compiler_flag("${c_flag}" C_FLAG_SUPPORTED) 71*77c1e3ccSAndroid Build Coastguard Worker 72*77c1e3ccSAndroid Build Coastguard Worker if(${C_FLAG_SUPPORTED}) 73*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_C_FLAGS "${c_flag}") 74*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_C_CONFIGS}) 75*77c1e3ccSAndroid Build Coastguard Worker unset(C_FLAG_FOUND) 76*77c1e3ccSAndroid Build Coastguard Worker append_flag("${config}" "${c_flag}") 77*77c1e3ccSAndroid Build Coastguard Worker endforeach() 78*77c1e3ccSAndroid Build Coastguard Worker else() 79*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_FAILED_C_FLAGS "${c_flag}") 80*77c1e3ccSAndroid Build Coastguard Worker endif() 81*77c1e3ccSAndroid Build Coastguard Workerendfunction() 82*77c1e3ccSAndroid Build Coastguard Worker 83*77c1e3ccSAndroid Build Coastguard Worker# Checks C++ compiler for support of $cxx_flag. Adds $cxx_flag to all 84*77c1e3ccSAndroid Build Coastguard Worker# $CMAKE_CXX_FLAGS_<CONFIG>s stored in AOM_CXX_CONFIGS when the compile test 85*77c1e3ccSAndroid Build Coastguard Worker# passes. Caches $cxx_flag in $AOM_CXX_FLAGS or $AOM_FAILED_CXX_FLAGS depending 86*77c1e3ccSAndroid Build Coastguard Worker# on test outcome. 87*77c1e3ccSAndroid Build Coastguard Workerfunction(add_cxx_flag_if_supported cxx_flag) 88*77c1e3ccSAndroid Build Coastguard Worker if(DEBUG_CMAKE_DISABLE_COMPILER_TESTS) 89*77c1e3ccSAndroid Build Coastguard Worker return() 90*77c1e3ccSAndroid Build Coastguard Worker endif() 91*77c1e3ccSAndroid Build Coastguard Worker 92*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_CXX_FLAGS "${cxx_flag}" flag_ok) 93*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_FAILED_CXX_FLAGS "${cxx_flag}" flag_failed) 94*77c1e3ccSAndroid Build Coastguard Worker if(${flag_ok} OR ${flag_failed}) 95*77c1e3ccSAndroid Build Coastguard Worker return() 96*77c1e3ccSAndroid Build Coastguard Worker endif() 97*77c1e3ccSAndroid Build Coastguard Worker 98*77c1e3ccSAndroid Build Coastguard Worker # Between 3.17.0 and 3.18.2 check_cxx_compiler_flag() sets a normal variable 99*77c1e3ccSAndroid Build Coastguard Worker # at parent scope while check_cxx_source_compiles() continues to set an 100*77c1e3ccSAndroid Build Coastguard Worker # internal cache variable, so we unset both to avoid the failure / success 101*77c1e3ccSAndroid Build Coastguard Worker # state persisting between checks. See 102*77c1e3ccSAndroid Build Coastguard Worker # https://gitlab.kitware.com/cmake/cmake/-/issues/21207. 103*77c1e3ccSAndroid Build Coastguard Worker unset(CXX_FLAG_SUPPORTED) 104*77c1e3ccSAndroid Build Coastguard Worker unset(CXX_FLAG_SUPPORTED CACHE) 105*77c1e3ccSAndroid Build Coastguard Worker message("Checking C++ compiler flag support for: " ${cxx_flag}) 106*77c1e3ccSAndroid Build Coastguard Worker check_cxx_compiler_flag("${cxx_flag}" CXX_FLAG_SUPPORTED) 107*77c1e3ccSAndroid Build Coastguard Worker 108*77c1e3ccSAndroid Build Coastguard Worker if(${CXX_FLAG_SUPPORTED}) 109*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_CXX_FLAGS "${cxx_flag}") 110*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_CXX_CONFIGS}) 111*77c1e3ccSAndroid Build Coastguard Worker unset(CXX_FLAG_FOUND) 112*77c1e3ccSAndroid Build Coastguard Worker append_flag("${config}" "${cxx_flag}") 113*77c1e3ccSAndroid Build Coastguard Worker endforeach() 114*77c1e3ccSAndroid Build Coastguard Worker else() 115*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_FAILED_CXX_FLAGS "${cxx_flag}") 116*77c1e3ccSAndroid Build Coastguard Worker endif() 117*77c1e3ccSAndroid Build Coastguard Workerendfunction() 118*77c1e3ccSAndroid Build Coastguard Worker 119*77c1e3ccSAndroid Build Coastguard Worker# Convenience method for adding a flag to both the C and C++ compiler command 120*77c1e3ccSAndroid Build Coastguard Worker# lines. 121*77c1e3ccSAndroid Build Coastguard Workerfunction(add_compiler_flag_if_supported flag) 122*77c1e3ccSAndroid Build Coastguard Worker add_c_flag_if_supported(${flag}) 123*77c1e3ccSAndroid Build Coastguard Worker add_cxx_flag_if_supported(${flag}) 124*77c1e3ccSAndroid Build Coastguard Workerendfunction() 125*77c1e3ccSAndroid Build Coastguard Worker 126*77c1e3ccSAndroid Build Coastguard Worker# Checks C compiler for support of $c_flag and terminates generation when 127*77c1e3ccSAndroid Build Coastguard Worker# support is not present. 128*77c1e3ccSAndroid Build Coastguard Workerfunction(require_c_flag c_flag update_c_flags) 129*77c1e3ccSAndroid Build Coastguard Worker if(DEBUG_CMAKE_DISABLE_COMPILER_TESTS) 130*77c1e3ccSAndroid Build Coastguard Worker return() 131*77c1e3ccSAndroid Build Coastguard Worker endif() 132*77c1e3ccSAndroid Build Coastguard Worker 133*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_C_FLAGS "${c_flag}" flag_ok) 134*77c1e3ccSAndroid Build Coastguard Worker if(${flag_ok}) 135*77c1e3ccSAndroid Build Coastguard Worker return() 136*77c1e3ccSAndroid Build Coastguard Worker endif() 137*77c1e3ccSAndroid Build Coastguard Worker 138*77c1e3ccSAndroid Build Coastguard Worker if(NOT "${AOM_EXE_LINKER_FLAGS}" STREQUAL "") 139*77c1e3ccSAndroid Build Coastguard Worker aom_push_var(CMAKE_EXE_LINKER_FLAGS "${AOM_EXE_LINKER_FLAGS}") 140*77c1e3ccSAndroid Build Coastguard Worker endif() 141*77c1e3ccSAndroid Build Coastguard Worker 142*77c1e3ccSAndroid Build Coastguard Worker unset(HAVE_C_FLAG CACHE) 143*77c1e3ccSAndroid Build Coastguard Worker message("Checking C compiler flag support for: " ${c_flag}) 144*77c1e3ccSAndroid Build Coastguard Worker check_c_compiler_flag("${c_flag}" HAVE_C_FLAG) 145*77c1e3ccSAndroid Build Coastguard Worker if(NOT HAVE_C_FLAG) 146*77c1e3ccSAndroid Build Coastguard Worker message( 147*77c1e3ccSAndroid Build Coastguard Worker FATAL_ERROR "${PROJECT_NAME} requires support for C flag: ${c_flag}.") 148*77c1e3ccSAndroid Build Coastguard Worker endif() 149*77c1e3ccSAndroid Build Coastguard Worker 150*77c1e3ccSAndroid Build Coastguard Worker if(NOT "${AOM_EXE_LINKER_FLAGS}" STREQUAL "") 151*77c1e3ccSAndroid Build Coastguard Worker aom_pop_var(CMAKE_EXE_LINKER_FLAGS) 152*77c1e3ccSAndroid Build Coastguard Worker endif() 153*77c1e3ccSAndroid Build Coastguard Worker 154*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_C_FLAGS "${c_flag}") 155*77c1e3ccSAndroid Build Coastguard Worker if(update_c_flags) 156*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_C_CONFIGS}) 157*77c1e3ccSAndroid Build Coastguard Worker set(${config} "${${config}} ${c_flag}" CACHE STRING "" FORCE) 158*77c1e3ccSAndroid Build Coastguard Worker endforeach() 159*77c1e3ccSAndroid Build Coastguard Worker endif() 160*77c1e3ccSAndroid Build Coastguard Workerendfunction() 161*77c1e3ccSAndroid Build Coastguard Worker 162*77c1e3ccSAndroid Build Coastguard Worker# Checks CXX compiler for support of $cxx_flag and terminates generation when 163*77c1e3ccSAndroid Build Coastguard Worker# support is not present. 164*77c1e3ccSAndroid Build Coastguard Workerfunction(require_cxx_flag cxx_flag update_cxx_flags) 165*77c1e3ccSAndroid Build Coastguard Worker if(DEBUG_CMAKE_DISABLE_COMPILER_TESTS) 166*77c1e3ccSAndroid Build Coastguard Worker return() 167*77c1e3ccSAndroid Build Coastguard Worker endif() 168*77c1e3ccSAndroid Build Coastguard Worker 169*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_CXX_FLAGS "${cxx_flag}" flag_ok) 170*77c1e3ccSAndroid Build Coastguard Worker if(${flag_ok}) 171*77c1e3ccSAndroid Build Coastguard Worker return() 172*77c1e3ccSAndroid Build Coastguard Worker endif() 173*77c1e3ccSAndroid Build Coastguard Worker 174*77c1e3ccSAndroid Build Coastguard Worker if(NOT "${AOM_EXE_LINKER_FLAGS}" STREQUAL "") 175*77c1e3ccSAndroid Build Coastguard Worker aom_push_var(CMAKE_EXE_LINKER_FLAGS "${AOM_EXE_LINKER_FLAGS}") 176*77c1e3ccSAndroid Build Coastguard Worker endif() 177*77c1e3ccSAndroid Build Coastguard Worker 178*77c1e3ccSAndroid Build Coastguard Worker unset(HAVE_CXX_FLAG CACHE) 179*77c1e3ccSAndroid Build Coastguard Worker message("Checking C++ compiler flag support for: " ${cxx_flag}) 180*77c1e3ccSAndroid Build Coastguard Worker check_cxx_compiler_flag("${cxx_flag}" HAVE_CXX_FLAG) 181*77c1e3ccSAndroid Build Coastguard Worker if(NOT HAVE_CXX_FLAG) 182*77c1e3ccSAndroid Build Coastguard Worker message( 183*77c1e3ccSAndroid Build Coastguard Worker FATAL_ERROR "${PROJECT_NAME} requires support for C++ flag: ${cxx_flag}.") 184*77c1e3ccSAndroid Build Coastguard Worker endif() 185*77c1e3ccSAndroid Build Coastguard Worker 186*77c1e3ccSAndroid Build Coastguard Worker if(NOT "${AOM_EXE_LINKER_FLAGS}" STREQUAL "") 187*77c1e3ccSAndroid Build Coastguard Worker aom_pop_var(CMAKE_EXE_LINKER_FLAGS) 188*77c1e3ccSAndroid Build Coastguard Worker endif() 189*77c1e3ccSAndroid Build Coastguard Worker 190*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_CXX_FLAGS "${cxx_flag}") 191*77c1e3ccSAndroid Build Coastguard Worker if(update_cxx_flags) 192*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_CXX_CONFIGS}) 193*77c1e3ccSAndroid Build Coastguard Worker set(${config} "${${config}} ${cxx_flag}" CACHE STRING "" FORCE) 194*77c1e3ccSAndroid Build Coastguard Worker endforeach() 195*77c1e3ccSAndroid Build Coastguard Worker endif() 196*77c1e3ccSAndroid Build Coastguard Workerendfunction() 197*77c1e3ccSAndroid Build Coastguard Worker 198*77c1e3ccSAndroid Build Coastguard Worker# Checks for support of $flag by both the C and CXX compilers. Terminates 199*77c1e3ccSAndroid Build Coastguard Worker# generation when support is not present in both compilers. 200*77c1e3ccSAndroid Build Coastguard Workerfunction(require_compiler_flag flag update_cmake_flags) 201*77c1e3ccSAndroid Build Coastguard Worker require_c_flag(${flag} ${update_cmake_flags}) 202*77c1e3ccSAndroid Build Coastguard Worker require_cxx_flag(${flag} ${update_cmake_flags}) 203*77c1e3ccSAndroid Build Coastguard Workerendfunction() 204*77c1e3ccSAndroid Build Coastguard Worker 205*77c1e3ccSAndroid Build Coastguard Worker# Checks only non-MSVC targets for support of $c_flag and terminates generation 206*77c1e3ccSAndroid Build Coastguard Worker# when support is not present. 207*77c1e3ccSAndroid Build Coastguard Workerfunction(require_c_flag_nomsvc c_flag update_c_flags) 208*77c1e3ccSAndroid Build Coastguard Worker if(NOT MSVC) 209*77c1e3ccSAndroid Build Coastguard Worker require_c_flag(${c_flag} ${update_c_flags}) 210*77c1e3ccSAndroid Build Coastguard Worker endif() 211*77c1e3ccSAndroid Build Coastguard Workerendfunction() 212*77c1e3ccSAndroid Build Coastguard Worker 213*77c1e3ccSAndroid Build Coastguard Worker# Checks only non-MSVC targets for support of $cxx_flag and terminates 214*77c1e3ccSAndroid Build Coastguard Worker# generation when support is not present. 215*77c1e3ccSAndroid Build Coastguard Workerfunction(require_cxx_flag_nomsvc cxx_flag update_cxx_flags) 216*77c1e3ccSAndroid Build Coastguard Worker if(NOT MSVC) 217*77c1e3ccSAndroid Build Coastguard Worker require_cxx_flag(${cxx_flag} ${update_cxx_flags}) 218*77c1e3ccSAndroid Build Coastguard Worker endif() 219*77c1e3ccSAndroid Build Coastguard Workerendfunction() 220*77c1e3ccSAndroid Build Coastguard Worker 221*77c1e3ccSAndroid Build Coastguard Worker# Checks only non-MSVC targets for support of $flag by both the C and CXX 222*77c1e3ccSAndroid Build Coastguard Worker# compilers. Terminates generation when support is not present in both 223*77c1e3ccSAndroid Build Coastguard Worker# compilers. 224*77c1e3ccSAndroid Build Coastguard Workerfunction(require_compiler_flag_nomsvc flag update_cmake_flags) 225*77c1e3ccSAndroid Build Coastguard Worker require_c_flag_nomsvc(${flag} ${update_cmake_flags}) 226*77c1e3ccSAndroid Build Coastguard Worker require_cxx_flag_nomsvc(${flag} ${update_cmake_flags}) 227*77c1e3ccSAndroid Build Coastguard Workerendfunction() 228*77c1e3ccSAndroid Build Coastguard Worker 229*77c1e3ccSAndroid Build Coastguard Worker# Adds $preproc_def to C compiler command line (as -D$preproc_def) if not 230*77c1e3ccSAndroid Build Coastguard Worker# already present. 231*77c1e3ccSAndroid Build Coastguard Workerfunction(add_c_preproc_definition preproc_def) 232*77c1e3ccSAndroid Build Coastguard Worker set(preproc_def "-D${preproc_def}") 233*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_C_FLAGS "${preproc_def}" flag_cached) 234*77c1e3ccSAndroid Build Coastguard Worker if(${flag_cached}) 235*77c1e3ccSAndroid Build Coastguard Worker return() 236*77c1e3ccSAndroid Build Coastguard Worker endif() 237*77c1e3ccSAndroid Build Coastguard Worker 238*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_C_CONFIGS}) 239*77c1e3ccSAndroid Build Coastguard Worker set(${config} "${${config}} ${preproc_def}" CACHE STRING "" FORCE) 240*77c1e3ccSAndroid Build Coastguard Worker endforeach() 241*77c1e3ccSAndroid Build Coastguard Workerendfunction() 242*77c1e3ccSAndroid Build Coastguard Worker 243*77c1e3ccSAndroid Build Coastguard Worker# Adds $preproc_def to CXX compiler command line (as -D$preproc_def) if not 244*77c1e3ccSAndroid Build Coastguard Worker# already present. 245*77c1e3ccSAndroid Build Coastguard Workerfunction(add_cxx_preproc_definition preproc_def) 246*77c1e3ccSAndroid Build Coastguard Worker set(preproc_def "-D${preproc_def}") 247*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_CXX_FLAGS "${preproc_def}" flag_cached) 248*77c1e3ccSAndroid Build Coastguard Worker if(${flag_cached}) 249*77c1e3ccSAndroid Build Coastguard Worker return() 250*77c1e3ccSAndroid Build Coastguard Worker endif() 251*77c1e3ccSAndroid Build Coastguard Worker 252*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_CXX_CONFIGS}) 253*77c1e3ccSAndroid Build Coastguard Worker set(${config} "${${config}} ${preproc_def}" CACHE STRING "" FORCE) 254*77c1e3ccSAndroid Build Coastguard Worker endforeach() 255*77c1e3ccSAndroid Build Coastguard Workerendfunction() 256*77c1e3ccSAndroid Build Coastguard Worker 257*77c1e3ccSAndroid Build Coastguard Worker# Adds $preproc_def to C and CXX compiler command line (as -D$preproc_def) if 258*77c1e3ccSAndroid Build Coastguard Worker# not already present. 259*77c1e3ccSAndroid Build Coastguard Workerfunction(add_preproc_definition preproc_def) 260*77c1e3ccSAndroid Build Coastguard Worker add_c_preproc_definition(${preproc_def}) 261*77c1e3ccSAndroid Build Coastguard Worker add_cxx_preproc_definition(${preproc_def}) 262*77c1e3ccSAndroid Build Coastguard Workerendfunction() 263*77c1e3ccSAndroid Build Coastguard Worker 264*77c1e3ccSAndroid Build Coastguard Worker# Adds $flag to assembler command line. 265*77c1e3ccSAndroid Build Coastguard Workerfunction(append_as_flag flag) 266*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_AS_FLAGS "${flag}" flag_cached) 267*77c1e3ccSAndroid Build Coastguard Worker if(${flag_cached}) 268*77c1e3ccSAndroid Build Coastguard Worker return() 269*77c1e3ccSAndroid Build Coastguard Worker endif() 270*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_AS_FLAGS "${flag}") 271*77c1e3ccSAndroid Build Coastguard Workerendfunction() 272*77c1e3ccSAndroid Build Coastguard Worker 273*77c1e3ccSAndroid Build Coastguard Worker# Adds $flag to the C compiler command line. 274*77c1e3ccSAndroid Build Coastguard Workerfunction(append_c_flag flag) 275*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_C_FLAGS "${flag}" flag_cached) 276*77c1e3ccSAndroid Build Coastguard Worker if(${flag_cached}) 277*77c1e3ccSAndroid Build Coastguard Worker return() 278*77c1e3ccSAndroid Build Coastguard Worker endif() 279*77c1e3ccSAndroid Build Coastguard Worker 280*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_C_CONFIGS}) 281*77c1e3ccSAndroid Build Coastguard Worker append_flag(${config} "${flag}") 282*77c1e3ccSAndroid Build Coastguard Worker endforeach() 283*77c1e3ccSAndroid Build Coastguard Workerendfunction() 284*77c1e3ccSAndroid Build Coastguard Worker 285*77c1e3ccSAndroid Build Coastguard Worker# Adds $flag to the CXX compiler command line. 286*77c1e3ccSAndroid Build Coastguard Workerfunction(append_cxx_flag flag) 287*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_CXX_FLAGS "${flag}" flag_cached) 288*77c1e3ccSAndroid Build Coastguard Worker if(${flag_cached}) 289*77c1e3ccSAndroid Build Coastguard Worker return() 290*77c1e3ccSAndroid Build Coastguard Worker endif() 291*77c1e3ccSAndroid Build Coastguard Worker 292*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_CXX_CONFIGS}) 293*77c1e3ccSAndroid Build Coastguard Worker append_flag(${config} "${flag}") 294*77c1e3ccSAndroid Build Coastguard Worker endforeach() 295*77c1e3ccSAndroid Build Coastguard Workerendfunction() 296*77c1e3ccSAndroid Build Coastguard Worker 297*77c1e3ccSAndroid Build Coastguard Worker# Adds $flag to the C and CXX compiler command lines. 298*77c1e3ccSAndroid Build Coastguard Workerfunction(append_compiler_flag flag) 299*77c1e3ccSAndroid Build Coastguard Worker append_c_flag(${flag}) 300*77c1e3ccSAndroid Build Coastguard Worker append_cxx_flag(${flag}) 301*77c1e3ccSAndroid Build Coastguard Workerendfunction() 302*77c1e3ccSAndroid Build Coastguard Worker 303*77c1e3ccSAndroid Build Coastguard Worker# Adds $flag to the executable linker command line when not present. 304*77c1e3ccSAndroid Build Coastguard Workerfunction(append_exe_linker_flag flag) 305*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_EXE_LINKER_FLAGS "${flag}" flag_cached) 306*77c1e3ccSAndroid Build Coastguard Worker if(${flag_cached}) 307*77c1e3ccSAndroid Build Coastguard Worker return() 308*77c1e3ccSAndroid Build Coastguard Worker endif() 309*77c1e3ccSAndroid Build Coastguard Worker 310*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_EXE_LINKER_FLAGS "${flag}") 311*77c1e3ccSAndroid Build Coastguard Worker foreach(config ${AOM_EXE_LINKER_CONFIGS}) 312*77c1e3ccSAndroid Build Coastguard Worker append_flag(${config} "${flag}") 313*77c1e3ccSAndroid Build Coastguard Worker endforeach() 314*77c1e3ccSAndroid Build Coastguard Workerendfunction() 315*77c1e3ccSAndroid Build Coastguard Worker 316*77c1e3ccSAndroid Build Coastguard Worker# Adds $flag to the link flags for $target. 317*77c1e3ccSAndroid Build Coastguard Workerfunction(append_link_flag_to_target target flag) 318*77c1e3ccSAndroid Build Coastguard Worker unset(target_link_flags) 319*77c1e3ccSAndroid Build Coastguard Worker get_target_property(target_link_flags ${target} LINK_FLAGS) 320*77c1e3ccSAndroid Build Coastguard Worker 321*77c1e3ccSAndroid Build Coastguard Worker if(target_link_flags) 322*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(target_link_flags "${flag}" flag_found) 323*77c1e3ccSAndroid Build Coastguard Worker if(${flag_found}) 324*77c1e3ccSAndroid Build Coastguard Worker return() 325*77c1e3ccSAndroid Build Coastguard Worker endif() 326*77c1e3ccSAndroid Build Coastguard Worker set(target_link_flags "${target_link_flags} ${flag}") 327*77c1e3ccSAndroid Build Coastguard Worker else() 328*77c1e3ccSAndroid Build Coastguard Worker set(target_link_flags "${flag}") 329*77c1e3ccSAndroid Build Coastguard Worker endif() 330*77c1e3ccSAndroid Build Coastguard Worker 331*77c1e3ccSAndroid Build Coastguard Worker set_target_properties(${target} PROPERTIES LINK_FLAGS ${target_link_flags}) 332*77c1e3ccSAndroid Build Coastguard Workerendfunction() 333*77c1e3ccSAndroid Build Coastguard Worker 334*77c1e3ccSAndroid Build Coastguard Worker# Adds $flag to executable linker flags, and makes sure C/CXX builds still work. 335*77c1e3ccSAndroid Build Coastguard Workerfunction(require_linker_flag flag) 336*77c1e3ccSAndroid Build Coastguard Worker if(DEBUG_CMAKE_DISABLE_COMPILER_TESTS) 337*77c1e3ccSAndroid Build Coastguard Worker return() 338*77c1e3ccSAndroid Build Coastguard Worker endif() 339*77c1e3ccSAndroid Build Coastguard Worker 340*77c1e3ccSAndroid Build Coastguard Worker append_exe_linker_flag(${flag}) 341*77c1e3ccSAndroid Build Coastguard Worker 342*77c1e3ccSAndroid Build Coastguard Worker unset(c_passed) 343*77c1e3ccSAndroid Build Coastguard Worker aom_check_c_compiles("LINKER_FLAG_C_TEST(${flag})" "" c_passed) 344*77c1e3ccSAndroid Build Coastguard Worker unset(cxx_passed) 345*77c1e3ccSAndroid Build Coastguard Worker aom_check_cxx_compiles("LINKER_FLAG_CXX_TEST(${flag})" "" cxx_passed) 346*77c1e3ccSAndroid Build Coastguard Worker 347*77c1e3ccSAndroid Build Coastguard Worker if(NOT c_passed OR NOT cxx_passed) 348*77c1e3ccSAndroid Build Coastguard Worker message(FATAL_ERROR "Linker flag test for ${flag} failed.") 349*77c1e3ccSAndroid Build Coastguard Worker endif() 350*77c1e3ccSAndroid Build Coastguard Workerendfunction() 351*77c1e3ccSAndroid Build Coastguard Worker 352*77c1e3ccSAndroid Build Coastguard Worker# Appends flags in $AOM_EXTRA_<TYPE>_FLAGS variables to the flags used at build 353*77c1e3ccSAndroid Build Coastguard Worker# time. 354*77c1e3ccSAndroid Build Coastguard Workerfunction(set_user_flags) 355*77c1e3ccSAndroid Build Coastguard Worker 356*77c1e3ccSAndroid Build Coastguard Worker # Linker flags are handled first because some C/CXX flags require that a 357*77c1e3ccSAndroid Build Coastguard Worker # linker flag is present at link time. 358*77c1e3ccSAndroid Build Coastguard Worker if(AOM_EXTRA_EXE_LINKER_FLAGS) 359*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_EXE_LINKER_FLAGS "${AOM_EXTRA_EXE_LINKER_FLAGS}" 360*77c1e3ccSAndroid Build Coastguard Worker extra_present) 361*77c1e3ccSAndroid Build Coastguard Worker if(NOT ${extra_present}) 362*77c1e3ccSAndroid Build Coastguard Worker require_linker_flag("${AOM_EXTRA_EXE_LINKER_FLAGS}") 363*77c1e3ccSAndroid Build Coastguard Worker endif() 364*77c1e3ccSAndroid Build Coastguard Worker endif() 365*77c1e3ccSAndroid Build Coastguard Worker if(AOM_EXTRA_AS_FLAGS) 366*77c1e3ccSAndroid Build Coastguard Worker 367*77c1e3ccSAndroid Build Coastguard Worker # TODO(tomfinegan): assembler flag testing would be a good thing to have. 368*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_AS_FLAGS "${AOM_EXTRA_AS_FLAGS}" extra_present) 369*77c1e3ccSAndroid Build Coastguard Worker if(NOT ${extra_present}) 370*77c1e3ccSAndroid Build Coastguard Worker append_flag(AOM_AS_FLAGS "${AOM_EXTRA_AS_FLAGS}") 371*77c1e3ccSAndroid Build Coastguard Worker endif() 372*77c1e3ccSAndroid Build Coastguard Worker endif() 373*77c1e3ccSAndroid Build Coastguard Worker if(AOM_EXTRA_C_FLAGS) 374*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_C_FLAGS "${AOM_EXTRA_C_FLAGS}" extra_present) 375*77c1e3ccSAndroid Build Coastguard Worker if(NOT ${extra_present}) 376*77c1e3ccSAndroid Build Coastguard Worker require_c_flag("${AOM_EXTRA_C_FLAGS}" YES) 377*77c1e3ccSAndroid Build Coastguard Worker endif() 378*77c1e3ccSAndroid Build Coastguard Worker endif() 379*77c1e3ccSAndroid Build Coastguard Worker if(AOM_EXTRA_CXX_FLAGS) 380*77c1e3ccSAndroid Build Coastguard Worker is_flag_present(AOM_CXX_FLAGS "${AOM_EXTRA_CXX_FLAGS}" extra_present) 381*77c1e3ccSAndroid Build Coastguard Worker if(NOT ${extra_present}) 382*77c1e3ccSAndroid Build Coastguard Worker require_cxx_flag("${AOM_EXTRA_CXX_FLAGS}" YES) 383*77c1e3ccSAndroid Build Coastguard Worker endif() 384*77c1e3ccSAndroid Build Coastguard Worker endif() 385*77c1e3ccSAndroid Build Coastguard Workerendfunction() 386