-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
256 lines (215 loc) · 8.29 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
cmake_minimum_required(VERSION 3.16.3)
project(
mh-stuff
VERSION 1.0
DESCRIPTION "stuff that i keep re-writing"
HOMEPAGE_URL "https://github.com/PazerOP/stuff"
LANGUAGES CXX
)
option(MH_STUFF_BUILD_SHARED_LIBS "Build stuff as a shared lib" OFF)
if (MH_STUFF_BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
option(MH_STUFF_COMPILE_LIBRARY "True to compile some code into to a static library for less overhead" ON)
if (MH_STUFF_COMPILE_LIBRARY)
set(MH_PUBLIC_OR_INTERFACE "PUBLIC")
set(MH_INTERFACE_OR_EMPTY "")
else()
set(MH_PUBLIC_OR_INTERFACE "INTERFACE")
set(MH_INTERFACE_OR_EMPTY "INTERFACE")
endif()
add_library(${PROJECT_NAME} ${MH_INTERFACE_OR_EMPTY}
"cpp/include/mh/algorithm/algorithm.hpp"
"cpp/include/mh/algorithm/multi_compare.hpp"
"cpp/include/mh/chrono/chrono_helpers.hpp"
"cpp/include/mh/chrono/chrono_helpers.inl"
"cpp/include/mh/concurrency/async.hpp"
"cpp/include/mh/concurrency/dispatcher.hpp"
"cpp/include/mh/concurrency/dispatcher.inl"
"cpp/include/mh/concurrency/locked_value.hpp"
"cpp/include/mh/concurrency/main_thread.hpp"
"cpp/include/mh/concurrency/mutex_debug.hpp"
"cpp/include/mh/concurrency/thread_pool.hpp"
"cpp/include/mh/concurrency/thread_pool.inl"
"cpp/include/mh/concurrency/thread_sentinel.hpp"
"cpp/include/mh/concurrency/thread_sentinel.inl"
"cpp/include/mh/containers/heap.hpp"
"cpp/include/mh/coroutine/coroutine_include.hpp"
"cpp/include/mh/coroutine/future.hpp"
"cpp/include/mh/coroutine/generator.hpp"
"cpp/include/mh/coroutine/task.hpp"
"cpp/include/mh/coroutine/thread.hpp"
"cpp/include/mh/coroutine/thread.inl"
"cpp/include/mh/data/bit_float.hpp"
"cpp/include/mh/data/bits.hpp"
"cpp/include/mh/data/lazy.hpp"
"cpp/include/mh/data/optional_ref.hpp"
"cpp/include/mh/data/variable_pusher.hpp"
"cpp/include/mh/error/ensure.inl"
"cpp/include/mh/error/ensure.hpp"
"cpp/include/mh/error/error_code_exception.hpp"
"cpp/include/mh/error/exception_details.hpp"
"cpp/include/mh/error/exception_details.inl"
"cpp/include/mh/error/expected.hpp"
"cpp/include/mh/error/nested_exception.hpp"
"cpp/include/mh/error/not_implemented_error.hpp"
"cpp/include/mh/error/status.hpp"
"cpp/include/mh/io/file.hpp"
"cpp/include/mh/io/filesystem_helpers.hpp"
"cpp/include/mh/io/filesystem_helpers.inl"
"cpp/include/mh/io/getopt.hpp"
"cpp/include/mh/math/angles.hpp"
"cpp/include/mh/math/interpolation.hpp"
"cpp/include/mh/math/random.hpp"
"cpp/include/mh/math/random.inl"
"cpp/include/mh/math/uint128.hpp"
"cpp/include/mh/memory/buffer.inl"
"cpp/include/mh/memory/buffer.hpp"
"cpp/include/mh/memory/cached_variable.hpp"
"cpp/include/mh/memory/checked_ptr.hpp"
"cpp/include/mh/memory/memory_helpers.hpp"
"cpp/include/mh/memory/stack_info.hpp"
"cpp/include/mh/memory/stack_info.inl"
"cpp/include/mh/memory/unique_object.hpp"
"cpp/include/mh/raii/scope_exit.hpp"
"cpp/include/mh/reflection/enum.hpp"
"cpp/include/mh/reflection/struct.hpp"
"cpp/include/mh/text/formatters/error_code.hpp"
"cpp/include/mh/text/case_insensitive_string.hpp"
"cpp/include/mh/text/charconv_helper.hpp"
"cpp/include/mh/text/codecvt.hpp"
"cpp/include/mh/text/codecvt.inl"
"cpp/include/mh/text/fmtstr.hpp"
"cpp/include/mh/text/format.hpp"
"cpp/include/mh/text/indenting_ostream.hpp"
"cpp/include/mh/text/insertion_conversion.hpp"
"cpp/include/mh/text/memstream.hpp"
"cpp/include/mh/text/multi_char.hpp"
"cpp/include/mh/text/string_insertion.hpp"
"cpp/include/mh/text/stringops.hpp"
"cpp/include/mh/types/disable_copy_move.hpp"
"cpp/include/mh/types/enum_class_bit_ops.hpp"
"cpp/include/mh/compiler.hpp"
"cpp/include/mh/future.hpp"
"cpp/include/mh/source_location.hpp"
"cpp/include/mh/utility.hpp"
"cpp/include/mh/variant.hpp"
)
add_library(mh::stuff ALIAS ${PROJECT_NAME})
find_package(mh-cmake-common CONFIG REQUIRED)
if (MH_STUFF_COMPILE_LIBRARY)
target_sources(${PROJECT_NAME} PRIVATE
"cpp/src/io/file.cpp"
"cpp/src/text/case_insensitive_string.cpp"
"cpp/src/text/string_insertion.cpp"
"cpp/src/source_location.cpp"
)
target_compile_definitions(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE}
"MH_COMPILE_LIBRARY"
"MH_COMPILE_LIBRARY_INLINE="
)
# Create a cpp file of all .inl files and add it to the target
set(MH_CPP_INCLUDE_ROOT "${PROJECT_SOURCE_DIR}/cpp/include")
file(GLOB_RECURSE MH_INL_FILES "${MH_CPP_INCLUDE_ROOT}/mh/*.inl")
# message("MH_INL_FILES = ${MH_INL_FILES}")
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/library.cpp")
foreach(X IN LISTS MH_INL_FILES)
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/library.cpp" "\n#include \"${X}\"")
endforeach()
target_sources(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/library.cpp")
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /permissive-)
endif()
include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME}
BASE_NAME ${PROJECT_NAME}
EXPORT_MACRO_NAME MH_STUFF_API
)
target_precompile_headers(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h")
else()
target_compile_definitions(${PROJECT_NAME} INTERFACE
"MH_COMPILE_LIBRARY_INLINE=inline"
"MH_STUFF_API="
)
endif()
mh_check_cxx_coroutine_support(SUPPORTS_COROUTINES COROUTINES_FLAGS)
target_compile_options(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} ${COROUTINES_FLAGS})
target_include_directories(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE}
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_compile_features(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} "cxx_std_20")
if (MSVC)
# There is a bug in visual studio that prevents intellisense from realizing
# /std:c++latest is on the command line if you only use target_compile_features(cxx_std_20)
target_compile_options(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} "/std:c++latest")
elseif (CMAKE_CXX_COMPILER_ID MATCHES GNU)
target_link_libraries(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} stdc++fs)
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
target_compile_options(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} -stdlib=libc++)
target_link_options(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} -stdlib=libc++)
target_link_libraries(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} c++abi)
if ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9"))
target_link_libraries(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} c++fs)
endif()
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
target_compile_options(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} -pthread)
target_link_options(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} -pthread)
endif()
if (NOT MSVC)
check_cxx_compiler_flag(-fconcepts FCONCEPTS_FLAG)
if (FCONCEPTS_FLAG)
target_compile_options(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} -fconcepts)
endif()
endif()
mh_check_cxx_unicode_support(SUPPORTS_UNICODE ${PROJECT_NAME})
if (NOT SUPPORTS_UNICODE)
target_compile_definitions(${PROJECT_NAME} ${MH_PUBLIC_OR_INTERFACE} "MH_BROKEN_UNICODE")
endif()
if (NOT DEFINED BUILD_TESTING)
if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(BUILD_TESTING ON)
else()
set(BUILD_TESTING OFF)
endif()
message("BUILD_TESTING not defined, changing to ${BUILD_TESTING}")
else()
message("BUILD_TESTING = ${BUILD_TESTING}, not modifying")
endif()
if (BUILD_TESTING)
include(CTest)
add_subdirectory("test")
endif()
mh_basic_install(
PROJ_INCLUDE_DIRS "cpp/include/"
)
###########################################
# "install" is intended for vcpkg support #
###########################################
# include(CMakePackageConfigHelpers)
# configure_package_config_file(
# cmake/config.cmake.in
# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
# INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}"
# )
# include(GNUInstallDirs)
# write_basic_package_version_file(
# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
# VERSION ${PROJECT_VERSION}
# COMPATIBILITY SameMajorVersion
# )
# install(
# FILES
# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
# DESTINATION
# "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}"
# )
# install(TARGETS stuff EXPORT ${PROJECT_NAME}_targets)
# install(DIRECTORY cpp/include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# install(
# EXPORT ${PROJECT_NAME}_targets
# NAMESPACE mh::
# DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}"
# )