-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
139 lines (117 loc) · 3.66 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#================================
# Project setup.
#================================
cmake_minimum_required(VERSION 3.30)
project(zeus VERSION 1.5.0 LANGUAGES CXX C)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Don't allow builds for Apple.
if (APPLE)
message(ERROR "Zeus does not support Apple platforms")
endif()
# Generate compilation database on all Unix systems
if (NOT MSVC)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
#================================
# Option variables.
#================================
option(ZEUS_BUILD_TESTS "Build Zeus unit tests" OFF)
option(ZEUS_INSTALL_TARGET "Create install target" OFF)
#================================
# Directory variables.
#================================
set(ZEUS_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(ZEUS_SOURCE_ROOT ${ZEUS_SOURCE_DIR}/include)
set(ZEUS_TEST_ROOT ${ZEUS_SOURCE_DIR}/test)
set(ZEUS_CMAKE_ROOT ${ZEUS_SOURCE_DIR}/cmake)
#================================
# Find Packages.
#================================
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ZEUS_CMAKE_ROOT})
include(FetchContent)
include(FetchLibrary)
#================================
# SDK Versions.
#================================
set(ZEUS_FMT_VERSION 11.0.0)
set(ZEUS_MAGIC_ENUM_VERSION 0.9.6)
set(ZEUS_CATCH_VERSION 3.7.1)
find_package(fmt ${ZEUS_FMT_VERSION} QUIET)
find_package(magic_enum ${ZEUS_MAGIC_ENUM_VERSION} QUIET)
if (NOT fmt_FOUND)
fetch_library(
NAME fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 67c0c0c09cf74d407d71a29c194761981614df3e
)
endif()
if (NOT magic_enum_FOUND)
fetch_library(
NAME magic_enum
GIT_REPOSITORY https://github.com/Neargye/magic_enum
GIT_TAG e55b9b54d5cf61f8e117cafb17846d7d742dd3b4
)
endif()
#================================
# Add subdirectories.
#================================
add_subdirectory(${ZEUS_SOURCE_ROOT}/zeus)
#================================
# Install targets.
#================================
if (ZEUS_INSTALL_TARGET)
install(TARGETS zeus
EXPORT zeus
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION lib
INCLUDES DESTINATION include
)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/zeusConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
install(EXPORT zeus
FILE zeusTargets.cmake
NAMESPACE zeus::
DESTINATION lib/cmake/zeus
)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/zeusConfig.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FetchLibrary.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zeusConfigVersion.cmake"
DESTINATION lib/cmake/zeus
)
install(FILES
${ZEUS_INSTALL_FILES}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/zeus"
)
endif()
#================================
# Build the tests.
#================================
if (ZEUS_BUILD_TESTS)
find_package(Catch2 ${ZEUS_CATCH_VERSION} QUIET)
if (NOT Catch2_FOUND)
fetch_library(
NAME Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG f981c9cbcac07a2690e5a86767eba490b5465463
)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
endif()
include(CTest)
include(Catch)
add_subdirectory(${ZEUS_TEST_ROOT})
endif()
# Make a symlink for the compile_commands.json file
if (NOT MSVC)
file(CREATE_LINK
"${CMAKE_BINARY_DIR}/compile_commands.json"
"${ZEUS_SOURCE_DIR}/compile_commands.json"
SYMBOLIC)
endif()