-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
223 lines (184 loc) · 8.43 KB
/
Copy pathCMakeLists.txt
File metadata and controls
223 lines (184 loc) · 8.43 KB
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
#
# Copyright 2018-2024 Apple Inc. All rights reserved.
#
cmake_minimum_required(VERSION 3.24)
include(ExternalProject)
include(CheckCXXCompilerFlag)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(inflectionMacros)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_INSTALL_MESSAGE NEVER)
# Declare inflection project
project(
Inflection
LANGUAGES C CXX
)
# Configure number of processors
get_num_processors(NUM_PROCESSORS_VAL)
inflection_debug_vars(NUM_PROCESSORS_VAL)
# Unicode Inflection cache variables
set(NUM_PROCESSORS ${NUM_PROCESSORS_VAL} CACHE STRING "Number of cores to be used in make")
option(PROFILING "Turn on code profiling" OFF)
option(ALIGNMENT_TEST "Turn on data alignment testing" OFF)
add_compile_options(${CXX_STD_LIB_FLAG})
add_link_options(${CXX_STD_LIB_FLAG})
# Setting c++20 standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# Equivalent to -fvisibility=hidden flag
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Unicode Inflection version
set(TAG_PREFIX Inflection)
get_inflection_version(INFLECTION_VERSION_TAG)
set(INFLECTION_VERSION ${INFLECTION_VERSION_TAG} CACHE STRING "Version of inflection to be used in publishing")
inflection_debug_vars(INFLECTION_VERSION)
set(CMAKE_INSTALL_LIBDIR lib)
include(GNUInstallDirs)
# Optionally compile with code profiling
if(PROFILING)
message("-- PROFILING TURNED ON")
add_compile_options(-g -fprofile-instr-generate -fcoverage-mapping)
add_link_options(-g -fprofile-instr-generate -fcoverage-mapping)
endif()
# Set these warning properties on a project level
if(MSVC)
add_compile_options(/W4 /utf-8)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
else()
add_compile_options(-Wall -Weffc++ -Wextra)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wglobal-constructors -Wexit-time-destructors -Wweak-vtables -Wvla-extension -Wctad-maybe-unsupported)
endif()
# Improve code security
add_compile_options(-Werror=format-security -fstack-protector-strong)
endif()
add_compile_definitions(_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE)
# Add link time optimization for release build types
if("${CMAKE_BUILD_TYPE}" MATCHES "MinSizeRel" OR "${CMAKE_BUILD_TYPE}" MATCHES "Release")
if(MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG")
else()
add_compile_options(-flto)
add_link_options(-flto)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Improve code security
add_compile_definitions(_FORTIFY_SOURCE=2)
# lld has native LTO support, unlike the gold/bfd plugin path, whose separately
# versioned LLVMgold.so can drift out of sync with the compiler and break LTO linking.
add_link_options(-fuse-ld=lld)
endif()
endif()
if(ALIGNMENT_TEST)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message("-- ALIGNMENT_TEST turned on")
# Data alignment of data structures isn't normally an issue for ARM CPUs.
# Some CPU configurations can cause SIGBUS or SIGILL to occur, like x86-64 with -O3 -march=native optimization turned on.
# Such configurations are hard for ARM CPUs to natively emulate.
# So we add this alignment flag for testing such configurations in debug mode.
add_compile_options(-fsanitize=alignment)
add_link_options(-fsanitize=alignment)
else()
message("-- ALIGNMENT_TEST not valid for current compiler configuration: " ${CMAKE_CXX_COMPILER_ID})
endif()
endif()
# Set Unicode Inflection include, data directories
set(INFLECTION_INCLUDE_ROOT ${CMAKE_BINARY_DIR}/inflection_headers)
set(INFLECTION_DATA_ROOT_PREFIX ${CMAKE_BINARY_DIR}/inflection_data)
cmake_path(GET CMAKE_INSTALL_PREFIX RELATIVE_PART INFLECTION_DATA_ROOT_INSTALL_PREFIX)
cmake_path(APPEND INFLECTION_DATA_ROOT_PREFIX "${INFLECTION_DATA_ROOT_INSTALL_PREFIX}" "${CMAKE_INSTALL_DATADIR}" OUTPUT_VARIABLE INFLECTION_DATA_ROOT)
file(MAKE_DIRECTORY ${INFLECTION_DATA_ROOT})
file(MAKE_DIRECTORY ${INFLECTION_INCLUDE_ROOT})
include(dependICU)
find_package(LibXml2 REQUIRED)
# Runs Unicode Inflection unit tests: "make check"
cmake_path(CONVERT "${ICU_LIB_DIRECTORY};$<TARGET_FILE_DIR:inflection>" TO_NATIVE_PATH_LIST DYLD_LIBRARY_PATH)
add_subdirectory(ext EXCLUDE_FROM_ALL)
add_subdirectory(tools EXCLUDE_FROM_ALL)
add_subdirectory(resources)
add_subdirectory(src)
add_subdirectory(test EXCLUDE_FROM_ALL)
# Runs inflection unit tests: "make check"
add_custom_target(check
DEPENDS itest
COMMAND ${CMAKE_COMMAND} "-DDYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}" -DEXECUTABLE=$<TARGET_FILE:itest> -P ${CMAKE_SOURCE_DIR}/cmake/runTests.cmake
COMMENT "Running inflection tests"
VERBATIM
)
add_custom_target(dist
COMMAND ${CMAKE_COMMAND} -E env "DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/dist"
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
add_dependencies(dist inflection inflection-headers inflection-data docs)
add_subdirectory(docs EXCLUDE_FROM_ALL)
# make list-commands
add_custom_target(list-commands
COMMAND echo "\
make list-commands : Shows this message\\n\\n\
make check : Runs unit tests\\n\
make check-headers : Tests whether all exported headers can be compiled independently.\\n\
make inflection : Builds the shared library.\\n\
make inflection-headers : Copy all inflection public headers to <build>/inflection_headers.\\n\
make inflection-data : Generate all inflection data under <build>/inflection_data.\\n\
make docs : Generate all inflection docs.\\n\
make dist : Builds inflection, the headers, and the data.\\n\
"
VERBATIM
)
# end section
install(TARGETS inflection LIBRARY COMPONENT inflection_library)
install(DIRECTORY ${INFLECTION_INCLUDE_ROOT}/ TYPE INCLUDE COMPONENT inflection_headers)
install(DIRECTORY ${INFLECTION_DATA_ROOT}/ TYPE DATA COMPONENT inflection_data)
# ----------------------------------------------------------------------------------------
# CPack Configuration for Ubuntu Packaging
#
# To update ICU version:
# 1. Update ICU_VERSION in the GitHub Actions workflow (.github/workflows/create-ubuntu-distribution-packaging.yml)
# 2. Make sure the downloaded ICU binary file matches the filename format
# (e.g., icu4c-78_1-Ubuntu22.04-x64.tgz)
# 3. Update the line below to match the correct ICU dependency in Debian packaging
# ----------------------------------------------------------------------------------------
set(CPACK_PACKAGE_NAME "unicode-inflection")
# Apply the current tagged Inflection version to the CPack version.
# CPack may inherit a default or cached version, so we explicitly set it here.
set(CPACK_PACKAGE_VERSION "${INFLECTION_VERSION}")
# Extract version components
string(REPLACE "." ";" INFLECTION_VERSION_LIST "${INFLECTION_VERSION}")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
list(LENGTH INFLECTION_VERSION_LIST _len)
if(_len GREATER 0)
list(GET INFLECTION_VERSION_LIST 0 CPACK_PACKAGE_VERSION_MAJOR)
endif()
if(_len GREATER 1)
list(GET INFLECTION_VERSION_LIST 1 CPACK_PACKAGE_VERSION_MINOR)
endif()
if(_len GREATER 2)
list(GET INFLECTION_VERSION_LIST 2 CPACK_PACKAGE_VERSION_PATCH)
endif()
# Basic package metadata
set(CPACK_PACKAGE_VENDOR "Unicode Consortium")
set(CPACK_PACKAGE_CONTACT "https://github.com/unicode-org/inflection")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unicode Inflection Library")
set(CPACK_GENERATOR "DEB;TGZ")
# DEB-specific options
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Unicode Consortium <inflection-team@unicode.org>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libicu79 (>= ${ICU_VERSION_MINIMUM})")
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_VERSION "${INFLECTION_VERSION}")
# Source package config
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES "/build/;/.git/;/.vscode/;/.idea/")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${INFLECTION_VERSION}")
include(CPack)