-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
225 lines (202 loc) · 7.81 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
# =============================================================================
#
# ztd.vargs
# Copyright © JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
# Contact: [email protected]
#
# Commercial License Usage
# Licensees holding valid commercial ztd.vargs licenses may use this file
# in accordance with the commercial license agreement provided with the
# Software or, alternatively, in accordance with the terms contained in
# a written agreement between you and Shepherd's Oasis, LLC.
# For licensing terms and conditions see your agreement. For
# further information contact [email protected].
#
# Apache License Version 2 Usage
# Alternatively, this file may be used under the terms of Apache License
# Version 2.0 (the "License") for non-commercial use; you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ============================================================================>
cmake_minimum_required(VERSION 3.21.0)
# # Project kickstart
# Includes a bunch of basic flags and utilities shared across projects
# See more at the github repository link below
include(FetchContent)
FetchContent_Declare(ztd.cmake
GIT_REPOSITORY https://github.com/soasis/cmake
GIT_TAG main)
FetchContent_MakeAvailable(ztd.cmake)
set(CMAKE_PROJECT_INCLUDE "${ZTD_CMAKE_PROJECT_PRELUDE}")
# # Project declaration
# informs about the project, gives a description, version and MOST IMPORTANTLY
# the languages the project is going to use. Required.
project(ztd.vargs
VERSION 0.0.0
DESCRIPTION [[Code to access Variable Arguments ("var args") without the cruft of an inital first parameter.]]
HOMEPAGE_URL "https://ztdvargs.readthedocs.io/en/latest/"
LANGUAGES C CXX ASM_MASM)
if(ZTD_VARGS_READTHEDOCS)
# ReadTheDocs seems unable to handle the include at the project level: something must be going wrong?
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)
include(CheckIPOSupported)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)
include(CMakePrintHelpers)
include(GNUInstallDirs)
include(FeatureSummary)
include(FetchContent)
include(CTest)
endif()
# # # Top-Level Directories
# Check if this is the top-level project or not
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(ZTD_IS_TOP_LEVEL_PROJECT YES)
else()
set(ZTD_IS_TOP_LEVEL_PROJECT NO)
endif()
# # Options
option(ZTD_VARGS_CI "Whether or not we are in continuous integration mode" OFF)
option(BUILD_TESTING "Enable build of tests" OFF)
option(ZTD_VARGS_DOCUMENTATION "Enable build of documentation" OFF)
option(ZTD_VARGS_DOCUMENTATION_NO_SPHINX "Turn off Sphinx usage (useful for ReadTheDocs builds)" OFF)
option(ZTD_VARGS_EXAMPLES "Enable build of examples" OFF)
option(ZTD_VARGS_BENCHMARKS "Enable build of benchmarks" OFF)
option(ZTD_VARGS_GENERATE_SINGLE "Enable generation of a single header and its target" OFF)
option(ZTD_VARGS_USE_VARGS "Enable generation of a single header and its target" OFF)
# Modify bad flags / change defaults if we are the top level
if(ZTD_IS_TOP_LEVEL_PROJECT)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if (NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 23)
endif()
if(ZTD_VARGS_BENCHMARKS OR ZTD_VARGS_EXAMPLES OR BUILD_TESTING OR ZTD_VARGS_SCRATCH)
# normal flags
check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic)
# Warning flags
check_compiler_flag(warn-pedantic MSVC /permissive- GCC -pedantic)
check_compiler_flag(warn-all MSVC /W4 GCC -Wall)
check_compiler_flag(warn-errors MSVC /WX GCC -Werror)
check_compiler_flag(warn-extra GCC -Wextra Clang -Wextra)
check_compiler_flag(utf8-literal-encoding MSVC /execution-charset:utf-8 GCC -fexec-charset=utf-8)
check_compiler_flag(utf8-source-encoding MSVC /source-charset:utf-8 GCC -finput-charset=utf-8)
check_compiler_flag(extra-constexpr-depth MSVC /constexpr:depth2147483647 GCC -fconstexpr-depth=2147483647 Clang -fconstexpr-depth=2147483647)
check_compiler_flag(extra-constexpr-steps MSVC /constexpr:steps2147483647 GCC -fconstexpr-ops-limit=2147483647 Clang -fconstexpr-steps=2147483647)
check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0)
endif()
endif()
# # Dependencies
# ztd.idk
FetchContent_Declare(ztd.idk
GIT_REPOSITORY https://github.com/soasis/idk.git
GIT_TAG main)
FetchContent_MakeAvailable(ztd.idk)
# # Main Library
file(GLOB ztd.vargs.includes CONFIGURE_DEPENDS include/*.hpp)
file(GLOB_RECURSE ztd.vargs.sources
LIST_DIRECTORIES FALSE
CONFIGURE_DEPENDS
source/*.c source/*.cpp)
set(ztd.vargs.sources.prefix "${CMAKE_CURRENT_SOURCE_DIR}/source/ztd/vargs")
if(WIN32)
# CMAKE_SYSTEM_PROCESSOR will be the result of %PROCESSOR_ARCHITEW6432%,
# and thus will be one of {AMD64, IA64, ARM64, x86, ARM}
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
set(arch_name "x64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
set(arch_name "x86")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
set(arch_name "arm64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM")
set(arch_name "arm")
endif()
if(MSVC)
message(STATUS "[ztd.vargs] Using VC++ ${arch_name} assembly files")
set(ztd.vargs.sources.asm
"${ztd.vargs.sources.prefix}/windows/${arch_name}.asm")
elseif (GCC OR MINGW)
message(STATUS "[ztd.vargs] Using mingw ${arch_name} assembly files")
set(ztd.vargs.sources.asm
"${ztd.vargs.sources.prefix}/mingw/${arch_name}.asm")
endif()
if(NOT EXISTS "${ztd.vargs.sources.asm}")
set(ztd.vargs.sources.asm "")
endif()
endif()
add_library(ztd.vargs ${ztd.vargs.sources} ${ztd.vargs.sources.asm})
add_library(ztd::vargs ALIAS ztd.vargs)
target_include_directories(ztd.vargs
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(ztd.vargs
PUBLIC
ztd::idk)
target_include_directories(ztd.vargs
PRIVATE ${PROJECT_SOURCE_DIR}/source/include)
target_compile_options(ztd.vargs PRIVATE ${ztd-vargs-disable-permissive})
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS ztd.vargs
PUBLIC_HEADER
RUNTIME
ARCHIVE
LIBRARY
)
# # Config / Version packaging
# Version configurations
configure_package_config_file(
cmake/ztd.vargs-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.vargs/ztd.vargs-config.cmake"
INSTALL_DESTINATION lib/cmake/ztd.vargs
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.vargs/ztd.vargs-config-version.cmake"
COMPATIBILITY SameMajorVersion)
export(TARGETS ztd.vargs
FILE
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.vargs/ztd.vargs-targets.cmake")
if(ZTD_VARGS_GENERATE_SINGLE)
add_subdirectory(single)
endif()
# # Benchmarks, Tests, Examples
if(BUILD_TESTING)
include(CTest)
add_subdirectory(tests)
endif()
if(ZTD_VARGS_DOCUMENTATION)
add_subdirectory(documentation)
endif()
if(ZTD_VARGS_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(ZTD_VARGS_EXAMPLES)
add_subdirectory(examples)
endif()
# For quick debugging and development only: don't peek! 🙈
mark_as_advanced(ZTD_VARGS_SCRATCH)
if(ZTD_VARGS_SCRATCH)
add_executable(scratch main.c scratch.c)
target_compile_options(scratch
PRIVATE
${--template-debugging-mode}
${--disable-permissive}
${--warn-pedantic}
${--warn-all}
${--warn-extra}
${--warn-errors})
target_compile_features(scratch PRIVATE cxx_std_20)
endif()