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 1) 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_WARNINGS" "NOMINMAX" 57 "_SCL_SECURE_NO_WARNINGS") 58 endif() 59 60 if(ANDROID) 61 if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a") 62 set(CMAKE_ANDROID_ARM_MODE ON) 63 endif() 64 65 if(build_type_lowercase MATCHES "rel") 66 list(APPEND libgav1_base_cxx_flags "-fno-stack-protector") 67 endif() 68 endif() 69 70 list(APPEND libgav1_base_cxx_flags "-Wall" "-Wextra" "-Wmissing-declarations" 71 "-Wno-sign-compare" "-fvisibility=hidden" 72 "-fvisibility-inlines-hidden") 73 74 if(BUILD_SHARED_LIBS) 75 set(CMAKE_POSITION_INDEPENDENT_CODE ON) 76 set(libgav1_dependency libgav1_shared) 77 else() 78 set(libgav1_dependency libgav1_static) 79 endif() 80 81 list(APPEND libgav1_clang_cxx_flags "-Wextra-semi" "-Wmissing-prototypes" 82 "-Wshorten-64-to-32") 83 84 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 85 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6") 86 # Quiet warnings in copy-list-initialization where {} elision has always 87 # been allowed. 88 list(APPEND libgav1_clang_cxx_flags "-Wno-missing-braces") 89 endif() 90 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8) 91 list(APPEND libgav1_clang_cxx_flags "-Wextra-semi-stmt") 92 endif() 93 endif() 94 95 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 96 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7") 97 # Quiet warnings due to potential snprintf() truncation in threadpool.cc. 98 list(APPEND libgav1_base_cxx_flags "-Wno-format-truncation") 99 100 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7") 101 # Quiet gcc 6 vs 7 abi warnings: 102 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77728 103 list(APPEND libgav1_base_cxx_flags "-Wno-psabi") 104 list(APPEND ABSL_GCC_FLAGS "-Wno-psabi") 105 endif() 106 endif() 107 endif() 108 109 if(build_type_lowercase MATCHES "rel") 110 list(APPEND libgav1_base_cxx_flags "-Wframe-larger-than=196608") 111 endif() 112 113 list(APPEND libgav1_msvc_cxx_flags 114 # Warning level 3. 115 "/W3" 116 # Disable warning C4018: 117 # '<comparison operator>' signed/unsigned mismatch 118 "/wd4018" 119 # Disable warning C4244: 120 # 'argument': conversion from '<double/int>' to 121 # '<float/smaller int type>', possible loss of data 122 "/wd4244" 123 # Disable warning C4267: 124 # '=': conversion from '<double/int>' to 125 # '<float/smaller int type>', possible loss of data 126 "/wd4267" 127 # Disable warning C4309: 128 # 'argument': truncation of constant value 129 "/wd4309" 130 # Disable warning C4551: 131 # function call missing argument list 132 "/wd4551") 133 134 if(BUILD_SHARED_LIBS) 135 list(APPEND libgav1_msvc_cxx_flags 136 # Disable warning C4251: 137 # 'libgav1::DecoderImpl class member' needs to have 138 # dll-interface to be used by clients of class 139 # 'libgav1::Decoder'. 140 "/wd4251") 141 endif() 142 143 if(NOT LIBGAV1_MAX_BITDEPTH) 144 set(LIBGAV1_MAX_BITDEPTH 12) 145 elseif(NOT LIBGAV1_MAX_BITDEPTH EQUAL 8 146 AND NOT LIBGAV1_MAX_BITDEPTH EQUAL 10 147 AND NOT LIBGAV1_MAX_BITDEPTH EQUAL 12) 148 libgav1_die("LIBGAV1_MAX_BITDEPTH must be 8, 10 or 12.") 149 endif() 150 151 list(APPEND libgav1_defines "LIBGAV1_MAX_BITDEPTH=${LIBGAV1_MAX_BITDEPTH}") 152 153 if(DEFINED LIBGAV1_THREADPOOL_USE_STD_MUTEX) 154 if(NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX EQUAL 0 155 AND NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX EQUAL 1) 156 libgav1_die("LIBGAV1_THREADPOOL_USE_STD_MUTEX must be 0 or 1.") 157 endif() 158 159 list(APPEND libgav1_defines 160 "LIBGAV1_THREADPOOL_USE_STD_MUTEX=${LIBGAV1_THREADPOOL_USE_STD_MUTEX}") 161 endif() 162 163 # Source file names ending in these suffixes will have the appropriate 164 # compiler flags added to their compile commands to enable intrinsics. 165 set(libgav1_avx2_source_file_suffix "avx2(_test)?.cc") 166 set(libgav1_neon_source_file_suffix "neon(_test)?.cc") 167 set(libgav1_sse4_source_file_suffix "sse4(_test)?.cc") 168endmacro() 169