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