dc/CMakeLists.txt

59 lines
1.6 KiB
CMake
Raw Permalink Normal View History

2023-11-09 10:31:50 +01:00
cmake_minimum_required(VERSION 3.12)
2024-03-14 10:24:25 +01:00
# Project name and version
project(dc VERSION 1.0.6)
2024-03-14 10:24:25 +01:00
# Retrieve build date
string(TIMESTAMP BUILD_DATE "%d-%b-%Y %H:%M:%S")
2024-03-14 10:24:25 +01:00
# Retrieve git hash
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE DC_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Set C++ version
2023-11-09 10:31:50 +01:00
set(CMAKE_CXX_STANDARD 20)
2024-03-14 10:24:25 +01:00
# Set debug flags by default
2024-03-11 16:37:55 +01:00
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
2024-03-14 10:24:25 +01:00
# Debug build flags
2024-03-11 16:37:55 +01:00
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \
-Wall -Wextra -pedantic -Werror \
2023-11-09 10:31:50 +01:00
-fstack-protector-strong -D_FORTIFY_SOURCE=2 \
-Wformat-security -fsanitize=address -fsanitize=undefined \
-fstack-clash-protection -Wundef -Wshadow -Wpointer-arith \
2024-03-11 16:37:55 +01:00
-Wcast-align -Wwrite-strings -ftrapv -std=c++20 -g -O2")
2024-03-14 10:24:25 +01:00
# Release build flags
2024-03-11 16:37:55 +01:00
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -std=c++20")
2023-11-09 10:31:50 +01:00
2024-03-14 10:24:25 +01:00
# Get build flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DC_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(DC_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}")
endif()
# Main file
2023-11-09 10:31:50 +01:00
add_executable(dc main.cpp)
2024-03-11 16:37:55 +01:00
2024-03-14 10:24:25 +01:00
# Source files
include_directories(src)
2023-11-09 10:31:50 +01:00
add_subdirectory(src)
2024-03-14 10:24:25 +01:00
# Link sources to main
target_link_libraries(dc src)
# Pass variables to the preprocessor
add_compile_definitions(DC_VER="${PROJECT_VERSION}")
add_compile_definitions(DC_HASH="${DC_GIT_HASH}")
add_compile_definitions(DC_BUILD="${CMAKE_BUILD_TYPE}")
add_compile_definitions(DC_FLAGS="${DC_FLAGS}")
add_compile_definitions(DC_BUILD_DATE="${BUILD_DATE}")