Skip to content

Commit 1b1592f

Browse files
committed
build: ensure build type is set
1 parent 3db74db commit 1b1592f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#######################################################
44
# Project information
55
cmake_minimum_required(VERSION 3.15)
6+
include(cmake/functions/ensure_build_type.cmake)
67
project(Matplot++ VERSION 1.2.0)
78
set(MATPLOT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
89
set(MATPLOT_VERSION ${CMAKE_PROJECT_VERSION})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Copyright (c) 2023 Alan de Freitas ([email protected])
3+
#
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt
6+
#
7+
# Official repository: https://github.com/alandefreitas/futures
8+
#
9+
10+
if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
11+
return()
12+
endif ()
13+
14+
# Set a default build type if none was specified
15+
set(default_build_type "Release")
16+
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
17+
set(default_build_type "Debug")
18+
endif ()
19+
20+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
21+
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
22+
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
23+
if (NOT IS_MULTICONFIG)
24+
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
25+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
26+
else ()
27+
set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
28+
endif()
29+
endif ()
30+
31+
32+
if(NOT gen_multi AND NOT (CMAKE_BUILD_TYPE OR DEFINED ENV{CMAKE_BUILD_TYPE}))
33+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Release can have faster run time than Debug")
34+
endif()

0 commit comments

Comments
 (0)