forked from openvanilla/McBopomofo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
149 lines (130 loc) · 5.69 KB
/
Copy pathCMakeLists.txt
File metadata and controls
149 lines (130 loc) · 5.69 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
cmake_minimum_required(VERSION 3.12)
project(McBopomofoLMLib)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_subdirectory(gramambular2)
add_subdirectory(Mandarin)
add_library(McBopomofoLMLib
AssociatedPhrasesV2.h
AssociatedPhrasesV2.cpp
ByteBlockBackedDictionary.h
ByteBlockBackedDictionary.cpp
McBopomofoLM.cpp
McBopomofoLM.h
MemoryMappedFile.h
MemoryMappedFile.cpp
ParselessPhraseDB.cpp
ParselessPhraseDB.h
ParselessLM.cpp
ParselessLM.h
PhraseReplacementMap.h
PhraseReplacementMap.cpp
UTF8Helper.h
UTF8Helper.cpp
UserOverrideModel.h
UserOverrideModel.cpp
UserPhrasesLM.h
UserPhrasesLM.cpp
VariantAnnotator.h
VariantAnnotator.cpp)
if (ENABLE_CLANG_TIDY)
set_target_properties(McBopomofoLMLib PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
endif ()
if (ENABLE_EXPERIMENTAL_SIMD_SUPPORT_AVX512)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-mavx512f" HAS_AVX512F)
if(HAS_AVX512F)
message(STATUS "AVX-512 support detected")
target_compile_options(McBopomofoLMLib PRIVATE -mavx512f -march=native -DENABLE_EXPERIMENTAL_SIMD_SUPPORT_AVX512=1)
else()
message(FATAL_ERROR "AVX-512 not supported by the compiler")
endif()
endif ()
# NEON is supported by default on AArch64 (ARM64), so we can enable it automatically
# Users can disable it by setting ENABLE_EXPERIMENTAL_SIMD_SUPPORT_NEON to OFF
# if (NOT DEFINED ENABLE_EXPERIMENTAL_SIMD_SUPPORT_NEON)
# if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64")
# message(STATUS "Detected architecture: ${CMAKE_SYSTEM_PROCESSOR}, enabling NEON support automatically")
# set(ENABLE_EXPERIMENTAL_SIMD_SUPPORT_NEON ON)
# endif ()
# endif ()
if (ENABLE_EXPERIMENTAL_SIMD_SUPPORT_NEON)
target_compile_definitions(McBopomofoLMLib PRIVATE ENABLE_EXPERIMENTAL_SIMD_SUPPORT_NEON=1)
endif ()
if (ENABLE_TEST)
enable_testing()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# Test target declarations.
add_executable(McBopomofoLMLibTest
AssociatedPhrasesV2Test.cpp
ByteBlockBackedDictionaryTest.cpp
McBopomofoLMTest.cpp
MemoryMappedFileTest.cpp
ParselessLMTest.cpp
ParselessPhraseDBTest.cpp
PhraseReplacementMapTest.cpp
UTF8HelperTest.cpp
UserOverrideModelTest.cpp
UserPhrasesLMTest.cpp
VariantAnnotatorTest.cpp)
target_link_libraries(McBopomofoLMLibTest GTest::gtest_main McBopomofoLMLib gramambular2_lib)
include(GoogleTest)
gtest_discover_tests(McBopomofoLMLibTest)
add_custom_target(
runMcBopomofoLMLibTest
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/McBopomofoLMLibTest
)
add_dependencies(runMcBopomofoLMLibTest McBopomofoLMLibTest)
if (ENABLE_BENCHMARK)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_VERSION "v1.9.5")
MESSAGE(STATUS "Fetching Google Benchmark ${BENCHMARK_VERSION} from GitHub")
include(FetchContent)
FetchContent_Declare(
benchmark
URL "https://github.com/google/benchmark/archive/refs/tags/${BENCHMARK_VERSION}.zip"
)
FetchContent_MakeAvailable(benchmark)
add_executable(ByteBlockBackedDictionaryBenchmark
ByteBlockBackedDictionaryBenchmark.cpp)
target_link_libraries(ByteBlockBackedDictionaryBenchmark McBopomofoLMLib benchmark::benchmark)
if (ENABLE_EXPERIMENTAL_SIMD_SUPPORT_NEON)
target_compile_definitions(ByteBlockBackedDictionaryBenchmark PRIVATE ENABLE_EXPERIMENTAL_SIMD_SUPPORT_NEON=1)
endif ()
if (ENABLE_EXPERIMENTAL_SIMD_SUPPORT_AVX512)
target_compile_options(ByteBlockBackedDictionaryBenchmark PRIVATE -mavx512f -march=native -DENABLE_EXPERIMENTAL_SIMD_SUPPORT_AVX512=1)
endif ()
add_custom_target(
runByteBlockBackedDictionaryBenchmark
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ByteBlockBackedDictionaryBenchmark
)
add_dependencies(runByteBlockBackedDictionaryBenchmark ByteBlockBackedDictionaryBenchmark)
add_executable(ParselessLMBenchmark
ParselessLMBenchmark.cpp)
target_link_libraries(ParselessLMBenchmark McBopomofoLMLib benchmark::benchmark)
add_custom_target(
runParselessLMBenchmark
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ParselessLMBenchmark
)
add_dependencies(runParselessLMBenchmark ParselessLMBenchmark)
add_executable(ParselessPhraseDBBenchmark
ParselessPhraseDBBenchmark.cpp)
target_link_libraries(ParselessPhraseDBBenchmark McBopomofoLMLib benchmark::benchmark)
add_custom_target(
runParselessPhraseDBBenchmark
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ParselessPhraseDBBenchmark
)
add_dependencies(runParselessPhraseDBBenchmark ParselessPhraseDBBenchmark)
endif ()
endif ()
if (ENABLE_ENGINE_PROFILE)
add_executable(EngineProfile
EngineProfile.cpp)
target_link_libraries(EngineProfile
McBopomofoLMLib
MandarinLib
gramambular2_lib)
endif ()