소스 검색

cmake: Build type set to Debug

Xenofon Karamanos 9 달 전
부모
커밋
b6f2503159
2개의 변경된 파일24개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 2
      CMakeLists.txt
  2. 21 0
      cmake/BuildType.cmake

+ 3 - 2
CMakeLists.txt

@@ -23,6 +23,9 @@ message(STATUS "VERSIONVAL: ${VERSIONVAL}")
 set(CMAKE_C_STANDARD 11)
 set(CMAKE_C_STANDARD_REQUIRED True)
 
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
+
+include(${CMAKE_SOURCE_DIR}/cmake/BuildType.cmake)
 # -----------------------
 # Main project name
 # -----------------------
@@ -37,8 +40,6 @@ set(CFG_NAME
     CACHE STRING "Config name"
 )
 
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
-
 # Add the source directory
 add_subdirectory(src)
 

+ 21 - 0
cmake/BuildType.cmake

@@ -0,0 +1,21 @@
+# Set a default build type if none was specified
+set(default_build_type "Release")
+if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
+  set(default_build_type "Debug")
+endif()
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+  message(
+    STATUS
+      "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()