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 15# libgav1 requires modern CMake. 16cmake_minimum_required(VERSION 3.7.1 FATAL_ERROR) 17 18# libgav1 requires C++11. 19set(CMAKE_CXX_STANDARD 11) 20set(ABSL_CXX_STANDARD 11) 21# libgav1 requires C99. 22set(CMAKE_C_STANDARD 99) 23 24project(libgav1 CXX C) 25 26set(libgav1_root "${CMAKE_CURRENT_SOURCE_DIR}") 27set(libgav1_build "${CMAKE_BINARY_DIR}") 28 29if("${libgav1_root}" STREQUAL "${libgav1_build}") 30 message( 31 FATAL_ERROR 32 "Building from within the libgav1 source tree is not supported.\n" 33 "Hint: Run these commands\n" "$ rm -rf CMakeCache.txt CMakeFiles\n" 34 "$ mkdir -p ../libgav1_build\n" "$ cd ../libgav1_build\n" 35 "And re-run CMake from the libgav1_build directory.") 36endif() 37 38set(libgav1_examples "${libgav1_root}/examples") 39set(libgav1_source "${libgav1_root}/src") 40 41include("${libgav1_root}/cmake/libgav1_options.cmake") 42 43libgav1_option(NAME LIBGAV1_ENABLE_OPTIMIZATIONS HELPSTRING 44 "Enables optimized code." VALUE ON) 45libgav1_option(NAME LIBGAV1_ENABLE_AVX2 HELPSTRING "Enables avx2 optimizations." 46 VALUE ON) 47libgav1_option(NAME LIBGAV1_ENABLE_NEON HELPSTRING "Enables neon optimizations." 48 VALUE ON) 49libgav1_option(NAME LIBGAV1_ENABLE_SSE4_1 HELPSTRING 50 "Enables sse4.1 optimizations." VALUE ON) 51libgav1_option(NAME LIBGAV1_ENABLE_EXAMPLES HELPSTRING "Enables examples." VALUE 52 ON) 53libgav1_option(NAME LIBGAV1_ENABLE_TESTS HELPSTRING "Enables tests." VALUE ON) 54libgav1_option( 55 NAME LIBGAV1_VERBOSE HELPSTRING 56 "Enables verbose build system output. Higher numbers are more verbose." VALUE 57 OFF) 58 59if(NOT CMAKE_BUILD_TYPE) 60 set(CMAKE_BUILD_TYPE Release) 61endif() 62 63# Enable generators like Xcode and Visual Studio to place projects in folders. 64get_property(use_folders_is_set GLOBAL PROPERTY USE_FOLDERS SET) 65if(NOT use_folders_is_set) 66 set_property(GLOBAL PROPERTY USE_FOLDERS TRUE) 67endif() 68 69include(FindThreads) 70 71include("${libgav1_examples}/libgav1_examples.cmake") 72include("${libgav1_root}/cmake/libgav1_build_definitions.cmake") 73include("${libgav1_root}/cmake/libgav1_cpu_detection.cmake") 74include("${libgav1_root}/cmake/libgav1_flags.cmake") 75include("${libgav1_root}/cmake/libgav1_helpers.cmake") 76include("${libgav1_root}/cmake/libgav1_install.cmake") 77include("${libgav1_root}/cmake/libgav1_intrinsics.cmake") 78include("${libgav1_root}/cmake/libgav1_sanitizer.cmake") 79include("${libgav1_root}/cmake/libgav1_targets.cmake") 80include("${libgav1_root}/cmake/libgav1_variables.cmake") 81include("${libgav1_root}/tests/libgav1_tests.cmake") 82include("${libgav1_source}/dsp/libgav1_dsp.cmake") 83include("${libgav1_source}/libgav1_decoder.cmake") 84include("${libgav1_source}/utils/libgav1_utils.cmake") 85 86libgav1_optimization_detect() 87libgav1_set_build_definitions() 88libgav1_set_cxx_flags() 89libgav1_configure_sanitizer() 90 91# Supported bit depth. 92libgav1_track_configuration_variable(LIBGAV1_MAX_BITDEPTH) 93 94# C++ and linker flags. 95libgav1_track_configuration_variable(LIBGAV1_CXX_FLAGS) 96libgav1_track_configuration_variable(LIBGAV1_EXE_LINKER_FLAGS) 97 98# Sanitizer integration. 99libgav1_track_configuration_variable(LIBGAV1_SANITIZE) 100 101# Generated source file directory. 102libgav1_track_configuration_variable(LIBGAV1_GENERATED_SOURCES_DIRECTORY) 103 104# Controls use of std::mutex and absl::Mutex in ThreadPool. 105libgav1_track_configuration_variable(LIBGAV1_THREADPOOL_USE_STD_MUTEX) 106if((DEFINED 107 LIBGAV1_THREADPOOL_USE_STD_MUTEX 108 AND NOT LIBGAV1_THREADPOOL_USE_STD_MUTEX) 109 OR NOT (DEFINED LIBGAV1_THREADPOOL_USE_STD_MUTEX OR ANDROID OR IOS)) 110 set(use_absl_threading TRUE) 111endif() 112 113if(LIBGAV1_VERBOSE) 114 libgav1_dump_cmake_flag_variables() 115 libgav1_dump_tracked_configuration_variables() 116 libgav1_dump_options() 117endif() 118 119set(libgav1_abseil_build "${libgav1_build}/abseil") 120set(libgav1_gtest_build "${libgav1_build}/gtest") 121 122# Compiler/linker flags must be lists, but come in from the environment as 123# strings. Break them up: 124if(NOT "${LIBGAV1_CXX_FLAGS}" STREQUAL "") 125 separate_arguments(LIBGAV1_CXX_FLAGS) 126endif() 127if(NOT "${LIBGAV1_EXE_LINKER_FLAGS}" STREQUAL "") 128 separate_arguments(LIBGAV1_EXE_LINKER_FLAGS) 129endif() 130 131# Set test-only flags based on LIBGAV1_CXX_FLAGS. 132libgav1_set_test_flags() 133 134set(libgav1_abseil "${libgav1_root}/third_party/abseil-cpp") 135if(EXISTS "${libgav1_abseil}") 136 set(ABSL_PROPAGATE_CXX_STD ON) 137 add_subdirectory("${libgav1_abseil}" "${libgav1_abseil_build}" 138 EXCLUDE_FROM_ALL) 139else() 140 if(use_absl_threading OR LIBGAV1_ENABLE_EXAMPLES OR LIBGAV1_ENABLE_TESTS) 141 message( 142 FATAL_ERROR 143 "Abseil not found. This dependency is required by the" 144 " examples & tests and libgav1 when LIBGAV1_THREADPOOL_USE_STD_MUTEX is" 145 " not defined. To continue, download the Abseil repository to" 146 " third_party/abseil-cpp:\n git \\\n -C ${libgav1_root} \\\n" 147 " clone \\\n" 148 " https://github.com/abseil/abseil-cpp.git third_party/abseil-cpp") 149 endif() 150endif() 151 152libgav1_reset_target_lists() 153libgav1_add_dsp_targets() 154libgav1_add_decoder_targets() 155libgav1_add_examples_targets() 156libgav1_add_tests_targets() 157libgav1_add_utils_targets() 158libgav1_setup_install_target() 159 160if(LIBGAV1_ENABLE_TESTS) 161 # include(CTest) or -DBUILD_TESTING=1 aren't used to avoid enabling abseil 162 # tests. 163 enable_testing() 164endif() 165 166if(LIBGAV1_VERBOSE) 167 libgav1_dump_cmake_flag_variables() 168 libgav1_dump_tracked_configuration_variables() 169 libgav1_dump_options() 170endif() 171