-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
209 lines (179 loc) · 5.66 KB
/
CMakeLists.txt
File metadata and controls
209 lines (179 loc) · 5.66 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
cmake_minimum_required(VERSION 3.16)
project(merve
DESCRIPTION "Fast lexer to extract named exports via analysis from CommonJS modules"
LANGUAGES C CXX
VERSION 1.2.2 # x-release-please-version
)
set(MERVE_LIB_VERSION "1.2.2" CACHE STRING "lexer library version") # x-release-please-version
set(MERVE_LIB_SOVERSION "1" CACHE STRING "lexer library soversion") # x-release-please-major
include(GNUInstallDirs)
# Optional simdutf support for optimized string operations
if(MERVE_USE_SIMDUTF)
# Try to find simdutf system package first
find_package(simdutf QUIET)
if(NOT simdutf_FOUND)
include(cmake/CPM.cmake)
find_package(Git QUIET)
if(Git_FOUND)
CPMAddPackage(
NAME simdutf
GITHUB_REPOSITORY simdutf/simdutf
VERSION 8.0.0
OPTIONS "SIMDUTF_TESTS OFF" "SIMDUTF_BENCHMARKS OFF" "SIMDUTF_TOOLS OFF"
)
set(simdutf_FOUND TRUE)
endif()
endif()
if(simdutf_FOUND)
message(STATUS "simdutf enabled for optimized string operations")
else()
message(WARNING "simdutf requested but not found, building without it")
set(MERVE_USE_SIMDUTF OFF)
endif()
endif()
include(CTest)
include(cmake/lexer-flags.cmake)
set(MERVE_SOURCE_DIR src)
add_subdirectory(src)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake)
option(MERVE_BENCHMARKS "Build benchmarks" OFF)
option(MERVE_TESTING "Build tests" ${BUILD_TESTING})
# There are cases where when embedding lexer as a dependency for other CMake
# projects as submodules or subdirectories (via FetchContent) can lead to
# errors due to CPM, so this is here to support disabling all the testing
# for lexer if one only wishes to use the lexer library.
if(MERVE_TESTING OR MERVE_BENCHMARKS)
# Try to find GTest system package first
find_package(GTest QUIET)
if(NOT GTest_FOUND)
include(cmake/CPM.cmake)
# CPM requires git as an implicit dependency
find_package(Git QUIET)
# We use googletest in the tests
if(Git_FOUND AND MERVE_TESTING)
CPMAddPackage(
NAME GTest
GITHUB_REPOSITORY google/googletest
VERSION 1.14.0
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF"
)
endif()
endif()
# We use Google Benchmark, but it does not build under several 32-bit systems.
if(Git_FOUND AND MERVE_BENCHMARKS AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
GIT_TAG f91b6b4
OPTIONS "BENCHMARK_ENABLE_TESTING OFF"
"BENCHMARK_ENABLE_INSTALL OFF"
"BENCHMARK_ENABLE_WERROR OFF"
)
endif()
if (MERVE_TESTING AND NOT EMSCRIPTEN)
if(Git_FOUND)
message(STATUS "The tests are enabled.")
add_subdirectory(tests)
else()
message(STATUS "The tests are disabled because git was not found.")
endif()
else()
if(is_top_project)
message(STATUS "The tests are disabled.")
endif()
endif(MERVE_TESTING AND NOT EMSCRIPTEN)
If(MERVE_BENCHMARKS AND NOT EMSCRIPTEN)
if(Git_FOUND)
message(STATUS "Lexer benchmarks enabled.")
add_subdirectory(benchmarks)
else()
message(STATUS "The benchmarks are disabled because git was not found.")
endif()
else(MERVE_BENCHMARKS AND NOT EMSCRIPTEN)
if(is_top_project)
message(STATUS "Lexer benchmarks disabled. Set MERVE_BENCHMARKS=ON to enable them.")
endif()
endif(MERVE_BENCHMARKS AND NOT EMSCRIPTEN)
if (MERVE_TESTING AND EMSCRIPTEN)
add_subdirectory(tests/wasm)
endif(MERVE_TESTING AND EMSCRIPTEN)
endif()
add_library(merve::merve ALIAS merve)
set_target_properties(
merve PROPERTIES
VERSION "${MERVE_LIB_VERSION}"
SOVERSION "${MERVE_LIB_SOVERSION}"
WINDOWS_EXPORT_ALL_SYMBOLS YES
)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
if(NOT MERVE_COVERAGE AND NOT EMSCRIPTEN)
add_subdirectory(singleheader)
endif()
install(
FILES include/merve.h include/merve_c.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT merve_development
)
install(
DIRECTORY include/merve
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT merve_development
)
install(
TARGETS merve
EXPORT merve_targets
RUNTIME COMPONENT merve_runtime
LIBRARY COMPONENT merve_runtime
NAMELINK_COMPONENT merve_development
ARCHIVE COMPONENT merve_development
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
configure_file(cmake/merve-config.cmake.in merve-config.cmake @ONLY)
write_basic_package_version_file(
merve-config-version.cmake
COMPATIBILITY SameMinorVersion
)
set(
MERVE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/merve"
CACHE STRING "CMake package config location relative to the install prefix"
)
mark_as_advanced(MERVE_INSTALL_CMAKEDIR)
configure_file(
"${PROJECT_SOURCE_DIR}/merve.pc.in"
"${PROJECT_BINARY_DIR}/merve.pc"
@ONLY
)
install(
FILES "${PROJECT_BINARY_DIR}/merve.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
COMPONENT nbytes_development
)
install(
FILES
"${PROJECT_BINARY_DIR}/merve-config.cmake"
"${PROJECT_BINARY_DIR}/merve-config-version.cmake"
DESTINATION "${MERVE_INSTALL_CMAKEDIR}"
COMPONENT merve_development
)
install(
EXPORT merve_targets
NAMESPACE merve::
DESTINATION "${MERVE_INSTALL_CMAKEDIR}"
COMPONENT merve_development
)
install(
EXPORT merve_targets
NAMESPACE merve::
DESTINATION "${MERVE_INSTALL_CMAKEDIR}"
COMPONENT example_development
)
if(is_top_project)
set(CPACK_PACKAGE_VENDOR "Merve Authors")
set(CPACK_PACKAGE_CONTACT "yagiz@nizipli.com")
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()