Skip to content

Commit 5723b02

Browse files
committed
[Build] Set a default build type of Release
The default is toolchain-specific (i.e. CMake generator-specific) and this can cause unexpected errors. E.g. if we've installed Python as a Release library, but this project is built as a Debug library, then on Windows we'll try to link to `python39_d`, i.e. the debug lib, which may not exist. We could enforce that `CMAKE_BUILD_TYPE` is always set externally, however if we forget then builds might just work, but then fail unexpectedly if we swap the toolchain. So better to just be consistent and default to Release in all cases, unless explicitly overridden. Signed-off-by: David Feltell <david.feltell@foundry.com>
1 parent 27e5926 commit 5723b02

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@
33

44
cmake_minimum_required(VERSION 3.21)
55

6-
project(OpenAssetIO-Test-CMake)
6+
# Set a default build type if none was specified.
7+
# The CMake default is toolchain-specific so ensure consistency by
8+
# having an explicit default.
9+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
10+
message(STATUS "Setting build type to 'Release' as none was specified.")
11+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
12+
# Set the possible values of build type for cmake-gui, ccmake
13+
set_property(
14+
CACHE CMAKE_BUILD_TYPE
15+
PROPERTY STRINGS
16+
"Debug"
17+
"Release"
18+
"MinSizeRel"
19+
"RelWithDebInfo")
20+
endif ()
721

22+
project(OpenAssetIO-Test-CMake)
823
enable_testing()
924

1025
#-----------------------------------------------------------------------

0 commit comments

Comments
 (0)