From 53982dbab4fd3eb01b0712b2eacbdb38ea15d850 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Mon, 17 Jul 2023 06:41:23 -0700 Subject: [PATCH] chore: Split out CMake policies into package/policies.cmake (#1236) --- CMakeLists.txt | 23 ++++------------------- packager/policies.cmake | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 packager/policies.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 55a815d0c8..412f911b93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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(.) diff --git a/packager/policies.cmake b/packager/policies.cmake new file mode 100644 index 0000000000..c6ba4451b3 --- /dev/null +++ b/packager/policies.cmake @@ -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()