Verified Commit 265d37d2 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Better handling of CMake build configurations

parent 59e48292
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -22,34 +22,41 @@
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################


# ##############################################################################
# Configure CMake
# Define the CMake project and configure CMake
# ##############################################################################

# FetchContent_MakeAvailable() was introduced in 3.14
cmake_minimum_required(VERSION 3.14)

# Set default build type and also populate a list of available options
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "[hermes] Setting build type to '${default_build_type}' as none was specified.")
  set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
      STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
    "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# ##############################################################################
# Define the CMake project
# ##############################################################################
project(
  scord
  VERSION 0.1.0
  LANGUAGES CXX
)

# Set default build type and also populate a list of available options
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)

if(NOT is_multi_config)
  set(default_build_type "Release")
  set(allowed_build_types Debug Release MinSizeRel RelWithDebInfo)

  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowed_build_types}")

  if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE
        "${default_build_type}"
        CACHE STRING "Choose the type of build." FORCE
    )
  elseif(NOT CMAKE_BUILD_TYPE IN_LIST allowed_build_types)
    message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
  endif()
endif()

# make sure that debug versions for targets are used (if provided) in Debug mode
set_property(GLOBAL APPEND PROPERTY DEBUG_CONFIGURATIONS Debug)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)