DESCRIPTION "Unit Testing Framework for C"
LANGUAGES C)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
+
+###############################################################################
+# Set build features
+
+# Set CMAKE_BUILD_TYPE to Debug if source directory is a Git repository
+# or user does not override on the command line
+include(BuildType)
+
###############################################################################
# Configure a project for testing with CTest/CDash
include(CTest)
-set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-
macro(extract_version file setting_name)
file(STRINGS ${file} VERSION_NUMBER REGEX "^${setting_name}")
string(REPLACE "=" ";" VERSION_NUMBER_LIST ${VERSION_NUMBER})
set(PROJECT_VERSION_PATCH ${CHECK_MICRO_VERSION})
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
-###############################################################################
-# Set build features
-set(CMAKE_BUILD_TYPE Debug)
-
###############################################################################
# Provides install directory variables as defined by the GNU Coding Standards.
include(GNUInstallDirs)
--- /dev/null
+# 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()
+