-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
186 lines (160 loc) · 6.33 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
# itsy.bitsy
#
# Copyright ⓒ 2019-present ThePhD.
#
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# See https://github.com/ThePhD/itsy_bitsy#using-the-library for documentation.
# Primary CMake File
# # Mimum required
cmake_minimum_required(VERSION 3.20.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(itsy.bitsy
VERSION 2.0.0
DESCRIPTION "Standard bit utilities to supplement the C and C++ standard libraries."
LANGUAGES C CXX)
# # Pre-dependencies
# this is for all the deps we may or may not need before-hand to make things right
if(ITSY_BITSY_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(ITSY_BITSY_IS_TOP_LEVEL_PROJECT ON)
else()
set(ITSY_BITSY_IS_TOP_LEVEL_PROJECT OFF)
endif()
# Modify bad flags / change defaults if we are the top level
if(ITSY_BITSY_IS_TOP_LEVEL_PROJECT)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/bin")
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/bin")
endif()
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_CUNEICODE_BENCHMARKS OR ZTD_CUNEICODE_EXAMPLES OR ZTD_CUNEICODE_TESTS OR ZTD_CUNEICODE_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()
# # Options
option(ITSY_BITSY_SINGLE "Enable build of tests" ON)
option(ITSY_BITSY_TESTS "Enable build of tests" ${BUILD_TESTING})
option(ITSY_BITSY_BENCHMARKS "Enable build of benchmarks" OFF)
option(ITSY_BITSY_EXAMPLES "Enable build of examples" OFF)
# # Dependencies
# ztd.idk
FetchContent_Declare(ztd.idk
GIT_REPOSITORY https://github.com/soasis/idk.git
GIT_TAG main)
FetchContent_MakeAvailable(ztd.idk)
# # itsy.bitsy Target
# Build Target
file(GLOB_RECURSE itsy-bitsy-sources
LIST_DIRECTORIES false
CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/itsy/*)
add_library(itsy.bitsy INTERFACE)
add_library(itsy::bitsy ALIAS itsy.bitsy)
target_link_libraries(itsy.bitsy
INTERFACE
ztd::idk)
target_include_directories(itsy.bitsy INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# # Install Target
# Version configurations
configure_package_config_file(
cmake/itsy.bitsy-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/itsy.bitsy-config.cmake"
INSTALL_DESTINATION lib/cmake/itsy.bitsy
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/itsy.bitsy-config-version.cmake"
COMPATIBILITY AnyNewerVersion)
export(TARGETS itsy.bitsy FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/itsy.bitsy-targets.cmake")
install(TARGETS itsy.bitsy
EXPORT itsy.bitsy)
install(DIRECTORY include/itsy
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/itsy.bitsy-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/itsy.bitsy-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/itsy.bitsy")
# pkg-config support, except on Windows
if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
set(PKGCONFIG_INSTALL_DIR
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
CACHE PATH "Path where itsy.bitsy.pc is installed")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/itsy.bitsy.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/itsy.bitsy.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/itsy.bitsy.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}")
endif()
if (ITSY_BITSY_SINGLE)
add_subdirectory(single)
endif()
# # Benchmarks, Tests, Examples
if (ITSY_BITSY_TESTS)
add_subdirectory(tests)
endif()
if (ITSY_BITSY_EXAMPLES)
add_subdirectory(examples)
endif()
if (ITSY_BITSY_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if (ITSY_BITSY_DOCS)
add_subdirectory(docs)
endif()
if (ITSY_BITSY_SCRATCH)
add_executable(scratch main.cpp)
target_link_libraries(scratch
PRIVATE
itsy::bitsy
)
target_compile_features(scratch
PRIVATE
cxx_std_20
)
endif()