Skip to content

Commit 43365df

Browse files
committed
Add default build type and validate against default cmake build types
1 parent 700831f commit 43365df

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cmake_minimum_required(VERSION 3.17)
33
project(Torch-TensorRT LANGUAGES CXX)
44

5-
# use c++14
5+
# use c++17
66
set(CMAKE_CXX_STANDARD 17)
77

88
# Build the libraries with -fPIC
@@ -12,6 +12,7 @@ if (DEFINED CMAKE_MODULE_PATH)
1212
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CACHE PATH "Path to the folder containing finders")
1313
endif()
1414

15+
include(cmake/build_options.cmake)
1516
include(cmake/dependencies.cmake)
1617
include(cmake/paths.cmake)
1718
if(MSVC)

cmake/build_options.cmake

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# set CMAKE_BUILD_TYPE default value
2+
if(NOT CMAKE_CONFIGURATION_TYPES)
3+
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
4+
set(CMAKE_BUILD_TYPE
5+
"Release"
6+
CACHE STRING "Build configuration" FORCE)
7+
endif()
8+
endif()
9+
10+
# validate CMAKE_BUILD_TYPE against default CMake build types
11+
set(VALID_BUILD_TYPES "Release" "Debug" "RelWithDebInfo" "MinSizeRel")
12+
if(NOT CMAKE_CONFIGURATION_TYPES)
13+
list(FIND VALID_BUILD_TYPES "${CMAKE_BUILD_TYPE}" INDEX)
14+
if(${INDEX} MATCHES -1)
15+
message(
16+
FATAL_ERROR
17+
"Invalid build type. Valid types are [${VALID_BUILD_TYPES}]")
18+
endif()
19+
endif()
20+
21+
if(NOT CMAKE_CONFIGURATION_TYPES)
22+
if(DEFINED CMAKE_BUILD_TYPE)
23+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
24+
${VALID_BUILD_TYPES})
25+
endif()
26+
endif()
27+
28+

0 commit comments

Comments
 (0)