1# Copyright 2019 The libgav1 Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15if(LIBGAV1_CMAKE_LIBGAV1_BUILD_DEFINITIONS_CMAKE_) 16 return() 17endif() # LIBGAV1_CMAKE_LIBGAV1_BUILD_DEFINITIONS_CMAKE_ 18set(LIBGAV1_CMAKE_LIBGAV1_BUILD_DEFINITIONS_CMAKE_ 1) 19 20macro(libgav1_set_build_definitions) 21 string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lowercase) 22 23 libgav1_load_version_info() 24 25 # Library version info. See the libtool docs for updating the values: 26 # https://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info 27 # 28 # c=<current>, r=<revision>, a=<age> 29 # 30 # libtool generates a .so file as .so.[c-a].a.r, while -version-info c:r:a is 31 # passed to libtool. 32 # 33 # We set LIBGAV1_SOVERSION = [c-a].a.r 34 set(LT_CURRENT 0) 35 set(LT_REVISION 0) 36 set(LT_AGE 0) 37 math(EXPR LIBGAV1_SOVERSION_MAJOR "${LT_CURRENT} - ${LT_AGE}") 38 set(LIBGAV1_SOVERSION "${LIBGAV1_SOVERSION_MAJOR}.${LT_AGE}.${LT_REVISION}") 39 unset(LT_CURRENT) 40 unset(LT_REVISION) 41 unset(LT_AGE) 42 43 list(APPEND libgav1_include_paths "${libgav1_root}" "${libgav1_root}/src" 44 "${libgav1_build}" "${libgav1_root}/third_party/abseil-cpp") 45 list(APPEND libgav1_gtest_include_paths 46 "third_party/googletest/googlemock/include" 47 "third_party/googletest/googletest/include" 48 "third_party/googletest/googletest") 49 list(APPEND libgav1_test_include_paths ${libgav1_include_paths} 50 ${libgav1_gtest_include_paths}) 51 list(APPEND libgav1_defines "LIBGAV1_CMAKE=1" 52 "LIBGAV1_FLAGS_SRCDIR=\"${libgav1_root}\"" 53 "LIBGAV1_FLAGS_TMPDIR=\"/tmp\"") 54 55 if(MSVC OR WIN32) 56 list(APPEND libgav1_defines "_CRT_SECURE_NO_DEPRECATE=1" "NOMINMAX=1") 57 endif() 58 59 if(ANDROID) 60 if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a") 61 set(CMAKE_ANDROID_ARM_MODE ON) 62 endif() 63 64 if(build_type_lowercase MATCHES "rel") 65 list(APPEND libgav1_base_cxx_flags "-fno-stack-protector") 66 endif() 67 endif() 68 69 list(APPEND libgav1_base_cxx_flags "-Wall" "-Wextra" "-Wmissing-declarations" 70 "-Wno-sign-compare" "-fvisibility=hidden" 71 "-fvisibility-inlines-hidden") 72 73 if(BUILD_SHARED_LIBS) 74 set(CMAKE_POSITION_INDEPENDENT_CODE ON) 75 set(libgav1_dependency libgav1_shared) 76 else() 77 set(libgav1_dependency libgav1_static) 78 endif() 79 80 list(APPEND libgav1_clang_cxx_flags "-Wextra-semi" "-Wmissing-prototypes" 81 "-Wshorten-64-to-32") 82 83 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 84 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6") 85 # Quiet warnings in copy-list-initialization where {} elision has always 86 # been allowed. 87 list(APPEND libgav1_clang_cxx_flags "-Wno-missing-braces") 88 endif() 89 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8) 90 list(APPEND libgav1_clang_cxx_flags "-Wextra-semi-stmt") 91 endif() 92 endif() 93 94 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 95 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7") 96 # Quiet warnings due to potential snprintf() truncation in threadpool.cc. 97 list(APPEND libgav1_base_cxx_flags "-Wno-format-truncation") 98 99 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7") 100 # Quiet gcc 6 vs 7 abi warnings: 101 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77728 102 list(APPEND libgav1_base_cxx_flags "-Wno-psabi") 103 list(APPEND ABSL_GCC_FLAGS "-Wno-psabi") 104 endif() 105 endif() 106 endif() 107 108 if(build_type_lowercase MATCHES "rel") 109 list(APPEND libgav1_base_cxx_flags "-Wframe-larger-than=196608") 110 endif() 111 112 list(APPEND libgav1_msvc_cxx_flags 113 # Warning level 3. 114 "/W3" 115 # Disable warning C4018: 116 # '<comparison operator>' signed/unsigned mismatch 117 "/wd4018" 118 # Disable warning C4244: 119 # 'argument': conversion from '<double/int>' to 120 # '<float/smaller int type>', possible loss of data 121 "/wd4244" 122 # Disable warning C4267: 123 # '=': conversion from '<double/int>' to 124 # '<float/smaller int type>', possible loss of data 125 "/wd4267" 126 # Disable warning C4309: 127 # 'argument': truncation of constant value 128 "/wd4309" 129 # Disable warning C4551: 130 # function call missing argument list 131 "/wd4551") 132 133 if(BUILD_SHARED_LIBS) 134 list(APPEND libgav1_msvc_cxx_flags 135 # Disable warning C4251: 136 # 'libgav1::DecoderImpl class member' needs to have 137 # dll-interface to be used by clients of class 138 # 'libgav1::Decoder'. 139 "/wd4251") 140 endif() 141 142 if(NOT LIBGAV1_MAX_BITDEPTH) 143 set(LIBGAV1_MAX_BITDEPTH 10) 144 elseif(NOT LIBGAV1_MAX_BITDEPTH EQUAL 8 AND NOT LIBGAV1_MAX_BITDEPTH EQUAL 10) 145 libgav1_die("LIBGAV1_MAX_BITDEPTH must be 8 or 10.") 146 endif() 147 148 list(APPEND libgav1_defines "LIBGAV1_MAX_BITDEPTH=${LIBGAV1_MAX_BITDEPTH}") 149 150 if(DEFINED LIBGAV1_THREADPOOL_USE_STD_MUTEX) 151 if(NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX EQUAL 0 152 AND NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX EQUAL 1) 153 libgav1_die("LIBGAV1_THREADPOOL_USE_STD_MUTEX must be 0 or 1.") 154 endif() 155 156 list(APPEND libgav1_defines 157 "LIBGAV1_THREADPOOL_USE_STD_MUTEX=${LIBGAV1_THREADPOOL_USE_STD_MUTEX}") 158 endif() 159 160 # Source file names ending in these suffixes will have the appropriate 161 # compiler flags added to their compile commands to enable intrinsics. 162 set(libgav1_avx2_source_file_suffix "avx2.cc") 163 set(libgav1_neon_source_file_suffix "neon.cc") 164 set(libgav1_sse4_source_file_suffix "sse4.cc") 165endmacro() 166