chore: Split out CMake policies into package/policies.cmake (#1236)

This commit is contained in:
Joey Parrish 2023-07-17 06:41:23 -07:00 committed by GitHub
parent 4b868de9f1
commit 53982dbab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 19 deletions

View File

@ -6,35 +6,20 @@
# Root-level CMake build file.
# Minimum CMake version.
# Minimum CMake version. This must be in the root level CMakeLists.txt.
# We could require as low as 3.10, but glog requires 3.16.
cmake_minimum_required(VERSION 3.16)
# These policy settings should be included before the project definition.
include("packager/policies.cmake")
# Project name. May not contain spaces. Versioning is managed elsewhere.
cmake_policy(SET CMP0048 NEW)
project(shaka-packager VERSION "")
# The only build option for Shaka Packager is whether to build a shared
# libpackager library. By default, don't.
option(LIBPACKAGER_SHARED "Build libpackager as a shared library" OFF)
# No in-source builds allowed.
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# TODO: Prevent accidental cmake invocation from deeper inside packager tree?
# Minimum C++ version.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Minimum GCC version, if using GCC.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Require at least GCC 9. Before GCC 9, C++17 filesystem libs don't link.
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
message(FATAL_ERROR "GCC version must be at least 9! (Found ${CMAKE_CXX_COMPILER_VERSION})")
endif()
endif()
# Global include paths.
# Project root, to reference packager/foo/bar/...
include_directories(.)

31
packager/policies.cmake Normal file
View File

@ -0,0 +1,31 @@
# Copyright 2023 Google LLC. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
# CMake policy settings. These will be included before the project definition.
# NOTE: Flags like MSVC are not available at this level.
# Do not set default warning levels for MSVC. We will choose the warning level.
cmake_policy(SET CMP0092 NEW)
# Use modern project versioning behavior to avoid a warning on newer CMake.
cmake_policy(SET CMP0048 NEW)
# No in-source builds allowed.
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# TODO: Prevent accidental cmake invocation from deeper inside packager tree?
# Minimum C++ version.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Minimum GCC version, if using GCC.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Require at least GCC 9. Before GCC 9, C++17 filesystem libs don't link.
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
message(FATAL_ERROR "GCC version must be at least 9! (Found ${CMAKE_CXX_COMPILER_VERSION})")
endif()
endif()