1*77c1e3ccSAndroid Build Coastguard Worker# 2*77c1e3ccSAndroid Build Coastguard Worker# Copyright (c) 2017, 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_UTIL_CMAKE_) 12*77c1e3ccSAndroid Build Coastguard Worker return() 13*77c1e3ccSAndroid Build Coastguard Workerendif() # AOM_BUILD_CMAKE_UTIL_CMAKE_ 14*77c1e3ccSAndroid Build Coastguard Workerset(AOM_BUILD_CMAKE_UTIL_CMAKE_ 1) 15*77c1e3ccSAndroid Build Coastguard Worker 16*77c1e3ccSAndroid Build Coastguard Worker# Directory where generated sources will be written. 17*77c1e3ccSAndroid Build Coastguard Workerset(AOM_GEN_SRC_DIR "${AOM_CONFIG_DIR}/gen_src") 18*77c1e3ccSAndroid Build Coastguard Worker 19*77c1e3ccSAndroid Build Coastguard Worker# Creates a no-op source file in $AOM_GEN_SRC_DIR named $basename.$extension and 20*77c1e3ccSAndroid Build Coastguard Worker# returns the full path to the source file via appending it to the list variable 21*77c1e3ccSAndroid Build Coastguard Worker# referred to by $out_file_list_var parameter. 22*77c1e3ccSAndroid Build Coastguard Workermacro(create_no_op_source_file basename extension out_file_list_var) 23*77c1e3ccSAndroid Build Coastguard Worker set(no_op_source_file "${AOM_GEN_SRC_DIR}/${basename}_no_op.${extension}") 24*77c1e3ccSAndroid Build Coastguard Worker file(WRITE "${no_op_source_file}" 25*77c1e3ccSAndroid Build Coastguard Worker "// Generated file. DO NOT EDIT!\n" 26*77c1e3ccSAndroid Build Coastguard Worker "// ${target_name} needs a ${extension} file to force link language, \n" 27*77c1e3ccSAndroid Build Coastguard Worker "// or to silence a harmless CMake warning: Ignore me.\n" 28*77c1e3ccSAndroid Build Coastguard Worker "void aom_${target_name}_no_op_function(void);\n" 29*77c1e3ccSAndroid Build Coastguard Worker "void aom_${target_name}_no_op_function(void) {}\n") 30*77c1e3ccSAndroid Build Coastguard Worker list(APPEND "${out_file_list_var}" "${no_op_source_file}") 31*77c1e3ccSAndroid Build Coastguard Workerendmacro() 32*77c1e3ccSAndroid Build Coastguard Worker 33*77c1e3ccSAndroid Build Coastguard Worker# Convenience function for adding a no-op source file to $target_name using 34*77c1e3ccSAndroid Build Coastguard Worker# $extension as the file extension. Wraps create_no_op_source_file(). 35*77c1e3ccSAndroid Build Coastguard Workerfunction(add_no_op_source_file_to_target target_name extension) 36*77c1e3ccSAndroid Build Coastguard Worker create_no_op_source_file("${target_name}" "${extension}" 37*77c1e3ccSAndroid Build Coastguard Worker "no_op_source_file_list") 38*77c1e3ccSAndroid Build Coastguard Worker target_sources(${target_name} PRIVATE ${no_op_source_file_list}) 39*77c1e3ccSAndroid Build Coastguard Workerendfunction() 40*77c1e3ccSAndroid Build Coastguard Worker 41*77c1e3ccSAndroid Build Coastguard Worker# Sets the value of the variable referenced by $feature to $value, and reports 42*77c1e3ccSAndroid Build Coastguard Worker# the change to the user via call to message(WARNING ...). $cause is expected to 43*77c1e3ccSAndroid Build Coastguard Worker# be a configuration variable that conflicts with $feature in some way. This 44*77c1e3ccSAndroid Build Coastguard Worker# function is a no-op if $feature is already set to $value. 45*77c1e3ccSAndroid Build Coastguard Workerfunction(change_config_and_warn feature value cause) 46*77c1e3ccSAndroid Build Coastguard Worker if(${feature} EQUAL ${value}) 47*77c1e3ccSAndroid Build Coastguard Worker return() 48*77c1e3ccSAndroid Build Coastguard Worker endif() 49*77c1e3ccSAndroid Build Coastguard Worker set(${feature} ${value} PARENT_SCOPE) 50*77c1e3ccSAndroid Build Coastguard Worker if(${value} EQUAL 1) 51*77c1e3ccSAndroid Build Coastguard Worker set(verb "Enabled") 52*77c1e3ccSAndroid Build Coastguard Worker set(reason "required for") 53*77c1e3ccSAndroid Build Coastguard Worker else() 54*77c1e3ccSAndroid Build Coastguard Worker set(verb "Disabled") 55*77c1e3ccSAndroid Build Coastguard Worker set(reason "incompatible with") 56*77c1e3ccSAndroid Build Coastguard Worker endif() 57*77c1e3ccSAndroid Build Coastguard Worker set(warning_message "${verb} ${feature}, ${reason} ${cause}.") 58*77c1e3ccSAndroid Build Coastguard Worker message(WARNING "--- ${warning_message}") 59*77c1e3ccSAndroid Build Coastguard Workerendfunction() 60*77c1e3ccSAndroid Build Coastguard Worker 61*77c1e3ccSAndroid Build Coastguard Worker# Extracts the version string from $version_file and returns it to the user via 62*77c1e3ccSAndroid Build Coastguard Worker# $version_string_out_var. To achieve this VERSION_STRING_NOSP is located in 63*77c1e3ccSAndroid Build Coastguard Worker# $version_file and then everything but the string literal assigned to the 64*77c1e3ccSAndroid Build Coastguard Worker# variable is removed. Quotes and the leading 'v' are stripped from the returned 65*77c1e3ccSAndroid Build Coastguard Worker# string. 66*77c1e3ccSAndroid Build Coastguard Workerfunction(extract_version_string version_file version_string_out_var) 67*77c1e3ccSAndroid Build Coastguard Worker file(STRINGS "${version_file}" aom_version REGEX "VERSION_STRING_NOSP") 68*77c1e3ccSAndroid Build Coastguard Worker string(REPLACE "#define VERSION_STRING_NOSP " "" aom_version "${aom_version}") 69*77c1e3ccSAndroid Build Coastguard Worker string(REPLACE "\"" "" aom_version "${aom_version}") 70*77c1e3ccSAndroid Build Coastguard Worker string(REPLACE " " "" aom_version "${aom_version}") 71*77c1e3ccSAndroid Build Coastguard Worker string(FIND "${aom_version}" "v" v_pos) 72*77c1e3ccSAndroid Build Coastguard Worker if(${v_pos} EQUAL 0) 73*77c1e3ccSAndroid Build Coastguard Worker string(SUBSTRING "${aom_version}" 1 -1 aom_version) 74*77c1e3ccSAndroid Build Coastguard Worker endif() 75*77c1e3ccSAndroid Build Coastguard Worker set("${version_string_out_var}" "${aom_version}" PARENT_SCOPE) 76*77c1e3ccSAndroid Build Coastguard Workerendfunction() 77*77c1e3ccSAndroid Build Coastguard Worker 78*77c1e3ccSAndroid Build Coastguard Worker# Sets CMake compiler launcher to $launcher_name when $launcher_name is found in 79*77c1e3ccSAndroid Build Coastguard Worker# $PATH. Warns user about ignoring build flag $launcher_flag when $launcher_name 80*77c1e3ccSAndroid Build Coastguard Worker# is not found in $PATH. 81*77c1e3ccSAndroid Build Coastguard Workerfunction(set_compiler_launcher launcher_flag launcher_name) 82*77c1e3ccSAndroid Build Coastguard Worker find_program(launcher_path "${launcher_name}") 83*77c1e3ccSAndroid Build Coastguard Worker if(launcher_path) 84*77c1e3ccSAndroid Build Coastguard Worker set(CMAKE_C_COMPILER_LAUNCHER "${launcher_path}" PARENT_SCOPE) 85*77c1e3ccSAndroid Build Coastguard Worker set(CMAKE_CXX_COMPILER_LAUNCHER "${launcher_path}" PARENT_SCOPE) 86*77c1e3ccSAndroid Build Coastguard Worker message("--- Using ${launcher_name} as compiler launcher.") 87*77c1e3ccSAndroid Build Coastguard Worker else() 88*77c1e3ccSAndroid Build Coastguard Worker message( 89*77c1e3ccSAndroid Build Coastguard Worker WARNING "--- Cannot find ${launcher_name}, ${launcher_flag} ignored.") 90*77c1e3ccSAndroid Build Coastguard Worker endif() 91*77c1e3ccSAndroid Build Coastguard Workerendfunction() 92*77c1e3ccSAndroid Build Coastguard Worker 93*77c1e3ccSAndroid Build Coastguard Worker# Sentinel value used to detect when a variable has been set via the -D argument 94*77c1e3ccSAndroid Build Coastguard Worker# passed to CMake on the command line. 95*77c1e3ccSAndroid Build Coastguard Workerset(cmake_cmdline_helpstring "No help, variable specified on the command line.") 96*77c1e3ccSAndroid Build Coastguard Worker 97*77c1e3ccSAndroid Build Coastguard Worker# Wrapper macro for set() that does some book keeping to help with storage of 98*77c1e3ccSAndroid Build Coastguard Worker# build configuration information. 99*77c1e3ccSAndroid Build Coastguard Worker# 100*77c1e3ccSAndroid Build Coastguard Worker# Sets the default value for variable $name when the value of $name has not 101*77c1e3ccSAndroid Build Coastguard Worker# already been set via the CMake command line. 102*77c1e3ccSAndroid Build Coastguard Worker# 103*77c1e3ccSAndroid Build Coastguard Worker# The names of variables defaulted through this macro are added to 104*77c1e3ccSAndroid Build Coastguard Worker# $AOM_DETECT_VARS to facilitate build logging and diagnostics. 105*77c1e3ccSAndroid Build Coastguard Workermacro(set_aom_detect_var name value helpstring) 106*77c1e3ccSAndroid Build Coastguard Worker unset(list_index) 107*77c1e3ccSAndroid Build Coastguard Worker list(FIND AOM_DETECT_VARS ${name} list_index) 108*77c1e3ccSAndroid Build Coastguard Worker if(${list_index} EQUAL -1) 109*77c1e3ccSAndroid Build Coastguard Worker list(APPEND AOM_DETECT_VARS ${name}) 110*77c1e3ccSAndroid Build Coastguard Worker endif() 111*77c1e3ccSAndroid Build Coastguard Worker 112*77c1e3ccSAndroid Build Coastguard Worker # Update the variable only when it does not carry the CMake assigned help 113*77c1e3ccSAndroid Build Coastguard Worker # string for variables specified via the command line. 114*77c1e3ccSAndroid Build Coastguard Worker unset(cache_helpstring) 115*77c1e3ccSAndroid Build Coastguard Worker get_property(cache_helpstring CACHE ${name} PROPERTY HELPSTRING) 116*77c1e3ccSAndroid Build Coastguard Worker if(NOT "${cache_helpstring}" STREQUAL "${cmake_cmdline_helpstring}") 117*77c1e3ccSAndroid Build Coastguard Worker set(${name} ${value} CACHE STRING "${helpstring}") 118*77c1e3ccSAndroid Build Coastguard Worker mark_as_advanced(${name}) 119*77c1e3ccSAndroid Build Coastguard Worker else() 120*77c1e3ccSAndroid Build Coastguard Worker message( 121*77c1e3ccSAndroid Build Coastguard Worker WARNING 122*77c1e3ccSAndroid Build Coastguard Worker "${name} has been set by CMake, but it may be overridden by the build " 123*77c1e3ccSAndroid Build Coastguard Worker "system during environment detection") 124*77c1e3ccSAndroid Build Coastguard Worker endif() 125*77c1e3ccSAndroid Build Coastguard Workerendmacro() 126*77c1e3ccSAndroid Build Coastguard Worker 127*77c1e3ccSAndroid Build Coastguard Worker# Wrapper macro for set() that does some book keeping to help with storage of 128*77c1e3ccSAndroid Build Coastguard Worker# build configuration information. 129*77c1e3ccSAndroid Build Coastguard Worker# 130*77c1e3ccSAndroid Build Coastguard Worker# Sets the default value for variable $name when the value of $name has not 131*77c1e3ccSAndroid Build Coastguard Worker# already been set via the CMake command line. 132*77c1e3ccSAndroid Build Coastguard Worker# 133*77c1e3ccSAndroid Build Coastguard Worker# The names of variables defaulted through this macro are added to 134*77c1e3ccSAndroid Build Coastguard Worker# $AOM_CONFIG_VARS to facilitate build logging and diagnostics. 135*77c1e3ccSAndroid Build Coastguard Workermacro(set_aom_config_var name value helpstring) 136*77c1e3ccSAndroid Build Coastguard Worker unset(list_index) 137*77c1e3ccSAndroid Build Coastguard Worker list(FIND AOM_CONFIG_VARS ${name} list_index) 138*77c1e3ccSAndroid Build Coastguard Worker if(${list_index} EQUAL -1) 139*77c1e3ccSAndroid Build Coastguard Worker list(APPEND AOM_CONFIG_VARS ${name}) 140*77c1e3ccSAndroid Build Coastguard Worker endif() 141*77c1e3ccSAndroid Build Coastguard Worker 142*77c1e3ccSAndroid Build Coastguard Worker # Update the variable only when it does not carry the CMake assigned help 143*77c1e3ccSAndroid Build Coastguard Worker # string for variables specified via the command line. 144*77c1e3ccSAndroid Build Coastguard Worker unset(cache_helpstring) 145*77c1e3ccSAndroid Build Coastguard Worker get_property(cache_helpstring CACHE ${name} PROPERTY HELPSTRING) 146*77c1e3ccSAndroid Build Coastguard Worker if(NOT "${cache_helpstring}" STREQUAL "${cmake_cmdline_helpstring}") 147*77c1e3ccSAndroid Build Coastguard Worker set(${name} ${value} CACHE STRING "${helpstring}") 148*77c1e3ccSAndroid Build Coastguard Worker endif() 149*77c1e3ccSAndroid Build Coastguard Workerendmacro() 150*77c1e3ccSAndroid Build Coastguard Worker 151*77c1e3ccSAndroid Build Coastguard Worker# Wrapper macro for option() that does some book keeping to help with storage of 152*77c1e3ccSAndroid Build Coastguard Worker# build configuration information. 153*77c1e3ccSAndroid Build Coastguard Worker# 154*77c1e3ccSAndroid Build Coastguard Worker# Sets the default value for variable $name when the value of $name has not 155*77c1e3ccSAndroid Build Coastguard Worker# already been set via the CMake command line. 156*77c1e3ccSAndroid Build Coastguard Worker# 157*77c1e3ccSAndroid Build Coastguard Worker# The names of variables defaulted through this macro are added to 158*77c1e3ccSAndroid Build Coastguard Worker# $AOM_OPTION_VARS to facilitate build logging and diagnostics. 159*77c1e3ccSAndroid Build Coastguard Workermacro(set_aom_option_var name helpstring value) 160*77c1e3ccSAndroid Build Coastguard Worker unset(list_index) 161*77c1e3ccSAndroid Build Coastguard Worker list(FIND AOM_OPTION_VARS ${name} list_index) 162*77c1e3ccSAndroid Build Coastguard Worker if(${list_index} EQUAL -1) 163*77c1e3ccSAndroid Build Coastguard Worker list(APPEND AOM_OPTION_VARS ${name}) 164*77c1e3ccSAndroid Build Coastguard Worker endif() 165*77c1e3ccSAndroid Build Coastguard Worker 166*77c1e3ccSAndroid Build Coastguard Worker # Update the variable only when it does not carry the CMake assigned help 167*77c1e3ccSAndroid Build Coastguard Worker # string for variables specified via the command line. 168*77c1e3ccSAndroid Build Coastguard Worker unset(cache_helpstring) 169*77c1e3ccSAndroid Build Coastguard Worker get_property(cache_helpstring CACHE ${name} PROPERTY HELPSTRING) 170*77c1e3ccSAndroid Build Coastguard Worker if(NOT "${cache_helpstring}" STREQUAL "${cmake_cmdline_helpstring}") 171*77c1e3ccSAndroid Build Coastguard Worker option(${name} "${helpstring}" ${value}) 172*77c1e3ccSAndroid Build Coastguard Worker endif() 173*77c1e3ccSAndroid Build Coastguard Workerendmacro() 174