-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
106 lines (88 loc) · 3.74 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
##########################################
## main library ##
##########################################
# /W3 warning in msvc fixed with 3.15
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
project(
mkpoker
VERSION 0.2.2
LANGUAGES CXX
DESCRIPTION "A Texas Holdem poker framework written in C++ 20."
)
# project options, these are off by default to not install gtest, propagate -Wpedantic etc.
option(MKPOKER_BUILD_EXAMPLES "Enable building the examples" OFF)
option(MKPOKER_BUILD_TESTS "Enable building the tests" OFF)
option(MKPOKER_BUILD_FOR_DEV "Use strict compiler warnings" OFF)
option(MKPOKER_ENABLE_CODE_COVERAGE "Enable test code coverage" OFF)
# VS Code C/C++ extension IntelliSense needs compile_commands.json for include paths
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# do not allow building in-source
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()
# add dependencies via CPM, see https://github.com/cpm-cmake/CPM.cmake for more info
include(cmake/CPM.cmake)
# until replace by std::format
CPMAddPackage(
NAME fmt
GIT_TAG 9.1.0
GITHUB_REPOSITORY fmtlib/fmt
OPTIONS "FMT_INSTALL YES"
)
# gather all used licenses
CPMAddPackage("gh:cpm-cmake/[email protected]")
# PackageProject.cmake will be used to make our project installable
CPMAddPackage("gh:TheLartians/[email protected]")
# base library, header only
set(PROJECT_NAMESPACE ${PROJECT_NAME})
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(
${PROJECT_NAME}
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)
target_compile_options(${PROJECT_NAME} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/permissive->)
# todo: remove c++ latest for msvc when std::format is supported by /std::c++20 set via cmake (or fmt has support for zoned_time)
target_compile_features(${PROJECT_NAME} INTERFACE $<$<CXX_COMPILER_ID:Clang,GNU,AppleClang>:cxx_std_20>)
target_compile_options(${PROJECT_NAME} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/std:c++latest>)
# before: target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20)
target_link_libraries(${PROJECT_NAME} INTERFACE fmt::fmt)
# configure according to options, build examples, tests etc.
if(MKPOKER_BUILD_FOR_DEV)
message(STATUS "mkpoker: strict compiler warnings enabled")
target_compile_options(${PROJECT_NAME} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/W4>)
target_compile_options(${PROJECT_NAME} INTERFACE $<$<CXX_COMPILER_ID:Clang,GNU,AppleClang>:-Wall -Wextra -Wpedantic>)
endif()
if(MKPOKER_BUILD_EXAMPLES)
message(STATUS "mkpoker: building samples enabled")
add_subdirectory(example)
else()
message(STATUS "mkpoker: building samples DISABLED")
endif()
if(MKPOKER_BUILD_TESTS)
message(STATUS "mkpoker: testing enabled")
enable_testing()
add_subdirectory(test)
else()
message(STATUS "mkpoker: testing DISABLED")
endif()
# create licenses file to include into the repository
# assuming build directory `build`, create with `cmake --build build --target write-licenses`
cpm_licenses_create_disclaimer_target(
write-licenses "${CMAKE_CURRENT_BINARY_DIR}/third_party.txt" "${CPM_PACKAGES}"
)
# make installable target
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)
packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
NAMESPACE ${PROJECT_NAMESPACE}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion
DEPENDENCIES "fmt 9.1.0;"
ARCH_INDEPENDENT YES
)