forked from wangfenjin/simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
84 lines (72 loc) · 2.62 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
cmake_minimum_required(VERSION 3.19)
set(CMAKE_CXX_STANDARD 14)
set(CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
if (APPLE)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "Minimum OS X deployment version")
endif()
if (IOS)
list(APPEND CMAKE_ARGS
"-DPLATFORM=${PLATFORM}"
)
endif()
# put project after CMAKE_OSX_DEPLOYMENT_TARGET
project(simple-tokenizer)
if (MSVC)
# https://stackoverflow.com/a/65128497/1203241
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(BUILD_SHARED_LIBS TRUE)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
endif()
set(SQLITE3_HEADERS_DIR ${PROJECT_SOURCE_DIR}/contrib/sqlite3)
set(SIMPLE_HEADERS_DIR ${PROJECT_SOURCE_DIR}/src)
# setup sqlite
option(BUILD_SQLITE3 "Enable build SQLite3" ON)
if(BUILD_SQLITE3)
set(SQLITE_ROOT ${PROJECT_SOURCE_DIR}/build/sqlite)
set(SQLITE_INSTALL_DIR ${SQLITE_ROOT})
set(SQLITE_INCLUDE_DIR ${SQLITE_INSTALL_DIR}/include)
set(SQLITE_LIB_DIR ${SQLITE_INSTALL_DIR}/lib)
if (NOT IOS)
option(SQLITE_ENABLE_FTS5 "enables full text searches version 5" ON)
option(BUILD_SHELL "build SQLite3 shell application" ON)
add_subdirectory(contrib/sqlite3)
endif()
endif()
include(contrib/CMakeRC.cmake)
cmrc_add_resource_library(PINYIN_TEXT TYPE OBJECT NAMESPACE pinyin_text contrib/pinyin.txt)
# https://github.com/vector-of-bool/cmrc/issues/17#issuecomment-659501280
set_property(TARGET PINYIN_TEXT PROPERTY POSITION_INDEPENDENT_CODE ON)
# Code Coverage Configuration
if(NOT TARGET coverage_config)
add_library(coverage_config INTERFACE)
endif()
option(CODE_COVERAGE "Enable coverage reporting" OFF)
# if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if(CODE_COVERAGE)
# Add required flags (GCC & LLVM/Clang)
target_compile_options(coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(coverage_config INTERFACE --coverage)
else()
target_link_libraries(coverage_config INTERFACE --coverage)
endif()
endif(CODE_COVERAGE)
# endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# https://stackoverflow.com/a/15212881/1203241
OPTION(SIMPLE_WITH_JIEBA "Option to build with cppjieba" ON)
if(SIMPLE_WITH_JIEBA)
add_definitions(-DUSE_JIEBA=1)
endif()
add_subdirectory(src)
OPTION(BUILD_TEST_EXAMPLE "Option to build tests and examples" ON)
if (NOT IOS AND BUILD_TEST_EXAMPLE)
add_subdirectory(examples/cpp)
enable_testing()
add_subdirectory(test)
endif()