forked from simdutf/simdutf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
205 lines (174 loc) · 6.1 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
cmake_minimum_required(VERSION 3.15)
project(simdutf
DESCRIPTION "Fast Unicode validation, transcoding and processing"
LANGUAGES CXX
VERSION 5.6.3
)
include (TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
message(STATUS "Big-endian system detected.")
endif()
include(GNUInstallDirs)
# The following requires CMake 3.21.
# if(PROJECT_IS_TOP_LEVEL)
# message(STATUS "Building simdutf as a top-level project.")
# include(CTest)
#else()
# message(STATUS "Building simdutf as a subproject.")
#endif(PROJECT_IS_TOP_LEVEL)
include(CTest)
include(cmake/simdutf-flags.cmake)
set(SIMDUTF_LIB_VERSION "11.0.0" CACHE STRING "simdutf library version")
set(SIMDUTF_LIB_SOVERSION "11" CACHE STRING "simdutf library soversion")
option(SIMDUTF_TESTS "Whether the tests are included as part of the CMake Build." ON)
option(SIMDUTF_BENCHMARKS "Whether the benchmarks are included as part of the CMake Build." OFF)
option(SIMDUTF_TOOLS "Whether the tools are included as part of the CMake build. Requires C++17 or better." ON)
option(SIMDUTF_ICONV "Whether to use iconv as part of the CMake build if available." ON)
option(SIMDUTF_FUZZERS "Whether to build the fuzzers." Off)
set(SIMDUTF_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(src)
add_subdirectory(singleheader)
if (SIMDUTF_TESTS)
message(STATUS "The tests are enabled.")
add_subdirectory(tests)
else(SIMDUTF_TESTS)
message(STATUS "The tests are disabled.")
endif(SIMDUTF_TESTS)
if (SIMDUTF_TOOLS)
if(CMAKE_CXX_COMPILER_ID MATCHES GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
message(STATUS "The benchmark tool requires GCC 8.0 or better.")
else()
add_subdirectory(tools)
endif()
endif()
if (SIMDUTF_BENCHMARKS)
if(NOT SIMDUTF_TESTS)
message(STATUS "You have enabled the benchmarks, but not the tests. We don't allow running the benchmarks without the tests.")
elif((CMAKE_CXX_COMPILER_ID MATCHES GNU) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0"))
message(STATUS "The benchmark tool requires GCC 8.0 or better.")
else()
message(STATUS "The benchmarks can be disabled by setting SIMDUTF_BENCHMARKS, e.g., -D SIMDUTF_BENCHMARKS=OFF.")
add_subdirectory(benchmarks)
endif()
else()
message(STATUS "The benchmarks can be enabled by setting SIMDUTF_BENCHMARKS, e.g., -D SIMDUTF_BENCHMARKS=ON.")
endif()
message(STATUS "Compiling using the C++ standard:" ${CMAKE_CXX_STANDARD})
# ---- Install rules ----
add_library(simdutf::simdutf ALIAS simdutf)
set_target_properties(
simdutf PROPERTIES
VERSION "${SIMDUTF_LIB_VERSION}"
SOVERSION "${SIMDUTF_LIB_SOVERSION}"
WINDOWS_EXPORT_ALL_SYMBOLS YES
)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
install(
FILES include/simdutf.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT simdutf_Development
)
install(
DIRECTORY include/simdutf
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT simdutf_Development
)
install(
TARGETS simdutf
EXPORT simdutfTargets
RUNTIME COMPONENT simdutf_Runtime
LIBRARY COMPONENT simdutf_Runtime
NAMELINK_COMPONENT simdutf_Development
ARCHIVE COMPONENT simdutf_Development
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
configure_file(cmake/simdutf-config.cmake.in simdutf-config.cmake @ONLY)
write_basic_package_version_file(
simdutf-config-version.cmake
COMPATIBILITY SameMinorVersion
)
set(
SIMDUTF_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/simdutf"
CACHE STRING "CMake package config location relative to the install prefix"
)
mark_as_advanced(SIMDUTF_INSTALL_CMAKEDIR)
install(
FILES
"${PROJECT_BINARY_DIR}/simdutf-config.cmake"
"${PROJECT_BINARY_DIR}/simdutf-config-version.cmake"
DESTINATION "${SIMDUTF_INSTALL_CMAKEDIR}"
COMPONENT simdutf_Development
)
install(
EXPORT simdutfTargets
NAMESPACE simdutf::
DESTINATION "${SIMDUTF_INSTALL_CMAKEDIR}"
COMPONENT example_Development
)
# pkg-config
include(cmake/JoinPaths.cmake)
join_paths(PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
join_paths(PKGCONFIG_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
configure_file("simdutf.pc.in" "simdutf.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/simdutf.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
#
# CPack
#
if(is_top_project)
set(CPACK_PACKAGE_VENDOR "Daniel Lemire")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE-MIT")
set(CPACK_RPM_PACKAGE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE-MIT")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
include(CPack)
endif()
# ----
if(NOT SIMDUTF_SANITIZE)
find_program(GREP grep)
find_program(NM nm)
if((NOT GREP) OR (NOT NM))
message("grep and nm are unavailable on this system.")
else()
add_test(
NAME "avoid_abort"
# Under FreeBSD, the __cxa_guard_abort symbol may appear but it is fine.
# So we want to look for <space><possibly _>abort as a test.
COMMAND sh -c "${NM} $<TARGET_FILE_NAME:simdutf> | ${GREP} ' _*abort' || exit 0 && exit 1"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
add_test(
NAME "avoid_cout"
COMMAND sh -c "${NM} $<TARGET_FILE_NAME:simdutf> | ${GREP} ' _*cout' || exit 0 && exit 1"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
add_test(
NAME "avoid_cerr"
COMMAND sh -c "${NM} $<TARGET_FILE_NAME:simdutf> | ${GREP} ' _*cerr' || exit 0 && exit 1"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
add_test(
NAME "avoid_printf"
COMMAND sh -c "${NM} $<TARGET_FILE_NAME:simdutf> | ${GREP} ' _*printf' || exit 0 && exit 1"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
add_test(
NAME "avoid_stdout"
COMMAND sh -c "${NM} $<TARGET_FILE_NAME:simdutf> | ${GREP} stdout || exit 0 && exit 1"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
add_test(
NAME "avoid_stderr"
COMMAND sh -c "${NM} $<TARGET_FILE_NAME:simdutf> | ${GREP} stderr || exit 0 && exit 1"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endif()
endif()
if(SIMDUTF_FUZZERS)
add_subdirectory(fuzz)
endif()