Substitube build_type

This commit is contained in:
Nils O. Selåsdal
2025-10-04 21:35:39 +02:00
parent b2d56f8094
commit 82e2337ecc
+15 -12
View File
@@ -2,8 +2,7 @@ cmake_minimum_required(VERSION 3.12)
project(libucore C) project(libucore C)
execute_process(COMMAND git -C ${CMAKE_SOURCE_DIR} describe --abbrev=5 --dirty --always OUTPUT_VARIABLE version_revision WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND git -C ${CMAKE_SOURCE_DIR} describe --abbrev=5 --dirty --always OUTPUT_VARIABLE version_revision WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND hostname OUTPUT_VARIABLE build_host OUTPUT_STRIP_TRAILING_WHITESPACE) cmake_host_system_information(RESULT build_host QUERY HOSTNAME)
set(libucore_VERSION_MAJOR 1) set(libucore_VERSION_MAJOR 1)
set(libucore_VERSION_MINOR 0) set(libucore_VERSION_MINOR 0)
set(libucore_VERSION_PATCH 0) set(libucore_VERSION_PATCH 0)
@@ -11,28 +10,32 @@ set(libucore_VERSION ${libucore_VERSION_MAJOR}.${libucore_VERSION_MINOR}.${libuc
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wundef -Wcast-qual -Wshadow -Wcast-align -pipe -Wno-unused-parameter -Werror=implicit-function-declaration -Winit-self") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wundef -Wcast-qual -Wshadow -Wcast-align -pipe -Wno-unused-parameter -Werror=implicit-function-declaration -Winit-self")
add_definitions(-D_FILE_OFFSET_BITS=64) add_definitions(-D_FILE_OFFSET_BITS=64)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2")
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
option(CODE_COVERAGE "build with code coverage intrumentation" OFF) option(CODE_COVERAGE "build with code coverage intrumentation" OFF)
if (CODE_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
add_definitions(-DCOVERAGE)
endif()
option(BUILD_SANITIZE "build with address sanitizer" OFF)
if (BUILD_SANITIZE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
endif()
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
# Set the property for multi-config generators as well, if applicable # Set the property for multi-config generators as well, if applicable
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel)
endif() endif()
set(build_type ${CMAKE_BUILD_TYPE})
if (CODE_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
add_definitions(-DCOVERAGE)
set(build_type "${build_type}-coverage")
endif()
option(BUILD_SANITIZE "build with address sanitizer" OFF)
if (BUILD_SANITIZE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(build_type "${build_type}-sanitize")
endif()
include_directories(include) include_directories(include)