-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
80 lines (64 loc) · 2.03 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
###
# @file CMakeLists.txt
# @brief CMake source file
# @version 0.1
# @author dragon-archer
#
# @copyright Copyright (c) 2023 dragon-archer
#
cmake_minimum_required(VERSION 3.16)
project(dascript VERSION 0.1 LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
# Detect whether it is built as a subproject or a main project
set(MAIN_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MAIN_PROJECT ON)
endif()
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_23 dascript_HasCxx23)
option(dascript_BuildTests "Build unit tests" ${MAIN_PROJECT})
option(dascript_UseBundledDa "Use bundled da" OFF)
option(dascript_UseCxx23 "Enable C++23" ${dascript_HasCxx23})
option(dascript_UseStdFormat "Use std::format instead of fmtlib" OFF)
set(TARGET_NAME ${PROJECT_NAME})
if(dascript_UseBundledDa)
add_subdirectory(${PROJECT_SOURCE_DIR}/da)
else()
find_package(da REQUIRED)
endif()
find_package(spdlog REQUIRED)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp
)
set(PCH src/pch.hpp)
set(LIBS
da::da
spdlog::spdlog
)
add_executable(${TARGET_NAME} ${SRCS})
target_precompile_headers(${TARGET_NAME} PRIVATE ${PCH})
target_link_libraries(${TARGET_NAME} PRIVATE ${LIBS})
if(dascript_UseCxx23)
if(NOT dascript_HasCxx23)
message(FATAL_ERROR "dascript is configured to use C++23 but the compiler does not support C++23")
else()
target_compile_features(${TARGET_NAME} INTERFACE cxx_std_23)
endif()
else()
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_20 dascript_HasCxx20)
if(NOT dascript_HasCxx20)
message(FATAL_ERROR "dascript should be compiled under at least C++20")
endif()
target_compile_features(${TARGET_NAME} INTERFACE cxx_std_20)
endif()
if(dascript_UseStdFormat)
target_compile_definitions(${TARGET_NAME} PRIVATE DASCRIPT_USE_STD_FORMAT)
endif()
# Tests
if(dascript_BuildTests)
enable_testing()
add_subdirectory(tests)
endif()
if(dascript_Coverage)
include(coverage)
endif()