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