aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 73f27a188c02f7e3ea6e70dba9325794e91a7921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Copyright 2019 The libgav1 Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# libgav1 requires modern CMake.
cmake_minimum_required(VERSION 3.7.1 FATAL_ERROR)

# libgav1 requires C++11.
set(CMAKE_CXX_STANDARD 11)
set(ABSL_CXX_STANDARD 11)
# libgav1 requires C99.
set(CMAKE_C_STANDARD 99)

project(libgav1 CXX C)

set(libgav1_root "${CMAKE_CURRENT_SOURCE_DIR}")
set(libgav1_build "${CMAKE_BINARY_DIR}")

if("${libgav1_root}" STREQUAL "${libgav1_build}")
  message(
    FATAL_ERROR
      "Building from within the libgav1 source tree is not supported.\n"
      "Hint: Run these commands\n" "$ rm -rf CMakeCache.txt CMakeFiles\n"
      "$ mkdir -p ../libgav1_build\n" "$ cd ../libgav1_build\n"
      "And re-run CMake from the libgav1_build directory.")
endif()

set(libgav1_examples "${libgav1_root}/examples")
set(libgav1_source "${libgav1_root}/src")

include("${libgav1_root}/cmake/libgav1_options.cmake")

libgav1_option(NAME LIBGAV1_ENABLE_OPTIMIZATIONS HELPSTRING
               "Enables optimized code." VALUE ON)
libgav1_option(NAME LIBGAV1_ENABLE_AVX2 HELPSTRING "Enables avx2 optimizations."
               VALUE ON)
libgav1_option(NAME LIBGAV1_ENABLE_NEON HELPSTRING "Enables neon optimizations."
               VALUE ON)
libgav1_option(NAME LIBGAV1_ENABLE_SSE4_1 HELPSTRING
               "Enables sse4.1 optimizations." VALUE ON)
libgav1_option(NAME LIBGAV1_ENABLE_EXAMPLES HELPSTRING "Enables examples." VALUE
               ON)
libgav1_option(NAME LIBGAV1_ENABLE_TESTS HELPSTRING "Enables tests." VALUE ON)
libgav1_option(
  NAME LIBGAV1_VERBOSE HELPSTRING
  "Enables verbose build system output. Higher numbers are more verbose." VALUE
  OFF)

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

# Enable generators like Xcode and Visual Studio to place projects in folders.
get_property(use_folders_is_set GLOBAL PROPERTY USE_FOLDERS SET)
if(NOT use_folders_is_set)
  set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
endif()

include(FindThreads)

include("${libgav1_examples}/libgav1_examples.cmake")
include("${libgav1_root}/cmake/libgav1_build_definitions.cmake")
include("${libgav1_root}/cmake/libgav1_cpu_detection.cmake")
include("${libgav1_root}/cmake/libgav1_flags.cmake")
include("${libgav1_root}/cmake/libgav1_helpers.cmake")
include("${libgav1_root}/cmake/libgav1_install.cmake")
include("${libgav1_root}/cmake/libgav1_intrinsics.cmake")
include("${libgav1_root}/cmake/libgav1_sanitizer.cmake")
include("${libgav1_root}/cmake/libgav1_targets.cmake")
include("${libgav1_root}/cmake/libgav1_variables.cmake")
include("${libgav1_root}/tests/libgav1_tests.cmake")
include("${libgav1_source}/dsp/libgav1_dsp.cmake")
include("${libgav1_source}/libgav1_decoder.cmake")
include("${libgav1_source}/utils/libgav1_utils.cmake")

libgav1_optimization_detect()
libgav1_set_build_definitions()
libgav1_set_cxx_flags()
libgav1_configure_sanitizer()

# Supported bit depth.
libgav1_track_configuration_variable(LIBGAV1_MAX_BITDEPTH)

# C++ and linker flags.
libgav1_track_configuration_variable(LIBGAV1_CXX_FLAGS)
libgav1_track_configuration_variable(LIBGAV1_EXE_LINKER_FLAGS)

# Sanitizer integration.
libgav1_track_configuration_variable(LIBGAV1_SANITIZE)

# Generated source file directory.
libgav1_track_configuration_variable(LIBGAV1_GENERATED_SOURCES_DIRECTORY)

# Controls use of std::mutex and absl::Mutex in ThreadPool.
libgav1_track_configuration_variable(LIBGAV1_THREADPOOL_USE_STD_MUTEX)
if((DEFINED
    LIBGAV1_THREADPOOL_USE_STD_MUTEX
    AND NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX)
   OR NOT (DEFINED LIBGAV1_THREADPOOL_USE_STD_MUTEX OR ANDROID OR IOS))
  set(use_absl_threading TRUE)
endif()

if(LIBGAV1_VERBOSE)
  libgav1_dump_cmake_flag_variables()
  libgav1_dump_tracked_configuration_variables()
  libgav1_dump_options()
endif()

set(libgav1_abseil_build "${libgav1_build}/abseil")
set(libgav1_gtest_build "${libgav1_build}/gtest")

# Compiler/linker flags must be lists, but come in from the environment as
# strings. Break them up:
if(NOT "${LIBGAV1_CXX_FLAGS}" STREQUAL "")
  separate_arguments(LIBGAV1_CXX_FLAGS)
endif()
if(NOT "${LIBGAV1_EXE_LINKER_FLAGS}" STREQUAL "")
  separate_arguments(LIBGAV1_EXE_LINKER_FLAGS)
endif()

# Set test-only flags based on LIBGAV1_CXX_FLAGS.
libgav1_set_test_flags()

set(libgav1_abseil "${libgav1_root}/third_party/abseil-cpp")
if(EXISTS "${libgav1_abseil}")
  set(ABSL_PROPAGATE_CXX_STD ON)
  add_subdirectory("${libgav1_abseil}" "${libgav1_abseil_build}"
                   EXCLUDE_FROM_ALL)
else()
  if(use_absl_threading OR LIBGAV1_ENABLE_EXAMPLES OR LIBGAV1_ENABLE_TESTS)
    message(
      FATAL_ERROR
        "Abseil not found. This dependency is required by the"
        " examples & tests and libgav1 when LIBGAV1_THREADPOOL_USE_STD_MUTEX is"
        " not defined. To continue, download the Abseil repository to"
        " third_party/abseil-cpp:\n  git \\\n    -C ${libgav1_root} \\\n"
        "    clone -b 20220623.0 --depth 1 \\\n"
        "    https://github.com/abseil/abseil-cpp.git third_party/abseil-cpp")
  endif()
endif()

libgav1_reset_target_lists()
libgav1_add_dsp_targets()
libgav1_add_decoder_targets()
libgav1_add_examples_targets()
libgav1_add_tests_targets()
libgav1_add_utils_targets()
libgav1_setup_install_target()

if(LIBGAV1_ENABLE_TESTS)
  # include(CTest) or -DBUILD_TESTING=1 aren't used to avoid enabling abseil
  # tests.
  enable_testing()
endif()

if(LIBGAV1_VERBOSE)
  libgav1_dump_cmake_flag_variables()
  libgav1_dump_tracked_configuration_variables()
  libgav1_dump_options()
endif()