• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  set(LIBGAV1_SOVERSION 0)
25
26  list(APPEND libgav1_include_paths "${libgav1_root}" "${libgav1_root}/src"
27              "${libgav1_build}" "${libgav1_root}/third_party/abseil-cpp")
28  list(APPEND libgav1_gtest_include_paths
29              "third_party/googletest/googlemock/include"
30              "third_party/googletest/googletest/include"
31              "third_party/googletest/googletest")
32  list(APPEND libgav1_test_include_paths ${libgav1_include_paths}
33              ${libgav1_gtest_include_paths})
34  list(APPEND libgav1_defines "LIBGAV1_CMAKE=1"
35              "LIBGAV1_FLAGS_SRCDIR=\"${libgav1_root}\""
36              "LIBGAV1_FLAGS_TMPDIR=\"/tmp\"")
37
38  if(MSVC OR WIN32)
39    list(APPEND libgav1_defines "_CRT_SECURE_NO_DEPRECATE=1" "NOMINMAX=1")
40  endif()
41
42  if(ANDROID)
43    if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
44      set(CMAKE_ANDROID_ARM_MODE ON)
45    endif()
46
47    if(build_type_lowercase MATCHES "rel")
48      list(APPEND libgav1_base_cxx_flags "-fno-stack-protector")
49    endif()
50  endif()
51
52  list(APPEND libgav1_base_cxx_flags "-Wall" "-Wextra" "-Wmissing-declarations"
53              "-Wno-sign-compare" "-fvisibility=hidden"
54              "-fvisibility-inlines-hidden")
55
56  if(BUILD_SHARED_LIBS)
57    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
58    set(libgav1_dependency libgav1_shared)
59  else()
60    set(libgav1_dependency libgav1_static)
61  endif()
62
63  list(APPEND libgav1_clang_cxx_flags "-Wextra-semi" "-Wmissing-prototypes"
64              "-Wshorten-64-to-32")
65
66  if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
67    if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6")
68      # Quiet warnings in copy-list-initialization where {} elision has always
69      # been allowed.
70      list(APPEND libgav1_clang_cxx_flags "-Wno-missing-braces")
71    endif()
72    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8)
73      list(APPEND libgav1_clang_cxx_flags "-Wextra-semi-stmt")
74    endif()
75  endif()
76
77  if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
78    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7")
79      # Quiet warnings due to potential snprintf() truncation in threadpool.cc.
80      list(APPEND libgav1_base_cxx_flags "-Wno-format-truncation")
81
82      if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7")
83        # Quiet gcc 6 vs 7 abi warnings:
84        # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77728
85        list(APPEND libgav1_base_cxx_flags "-Wno-psabi")
86        list(APPEND ABSL_GCC_FLAGS "-Wno-psabi")
87      endif()
88    endif()
89  endif()
90
91  if(build_type_lowercase MATCHES "rel")
92    # TODO(tomfinegan): this value is only a concern for the core library and
93    # can be made smaller if the test targets are avoided.
94    list(APPEND libgav1_base_cxx_flags "-Wstack-usage=196608")
95  endif()
96
97  list(APPEND libgav1_msvc_cxx_flags
98              # Warning level 3.
99              "/W3"
100              # Disable warning C4018:
101              # '<comparison operator>' signed/unsigned mismatch
102              "/wd4018"
103              # Disable warning C4244:
104              # 'argument': conversion from '<double/int>' to
105              # '<float/smaller int type>', possible loss of data
106              "/wd4244"
107              # Disable warning C4267:
108              # '=': conversion from '<double/int>' to
109              # '<float/smaller int type>', possible loss of data
110              "/wd4267"
111              # Disable warning C4309:
112              # 'argument': truncation of constant value
113              "/wd4309"
114              # Disable warning C4551:
115              # function call missing argument list
116              "/wd4551")
117
118  if(BUILD_SHARED_LIBS)
119    list(APPEND libgav1_msvc_cxx_flags
120                # Disable warning C4251:
121                # 'libgav1::DecoderImpl class member' needs to have
122                # dll-interface to be used by clients of class
123                # 'libgav1::Decoder'.
124                "/wd4251")
125  endif()
126
127  if(NOT LIBGAV1_MAX_BITDEPTH)
128    set(LIBGAV1_MAX_BITDEPTH 10)
129  elseif(NOT LIBGAV1_MAX_BITDEPTH EQUAL 8 AND NOT LIBGAV1_MAX_BITDEPTH EQUAL 10)
130    libgav1_die("LIBGAV1_MAX_BITDEPTH must be 8 or 10.")
131  endif()
132
133  list(APPEND libgav1_defines "LIBGAV1_MAX_BITDEPTH=${LIBGAV1_MAX_BITDEPTH}")
134
135  if(DEFINED LIBGAV1_THREADPOOL_USE_STD_MUTEX)
136    if(NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX EQUAL 0
137       AND NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX EQUAL 1)
138      libgav1_die("LIBGAV1_THREADPOOL_USE_STD_MUTEX must be 0 or 1.")
139    endif()
140
141    list(APPEND libgav1_defines
142         "LIBGAV1_THREADPOOL_USE_STD_MUTEX=${LIBGAV1_THREADPOOL_USE_STD_MUTEX}")
143  endif()
144
145  # Source file names ending in these suffixes will have the appropriate
146  # compiler flags added to their compile commands to enable intrinsics.
147  set(libgav1_neon_source_file_suffix "neon.cc")
148  set(libgav1_sse4_source_file_suffix "sse4.cc")
149endmacro()
150