-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
84 lines (67 loc) · 2.41 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
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(cppinyin)
set(CPPINYIN_VERSION "0.6")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(NOT APPLE)
set(CPPINYIN_RPATH_ORIGIN "$ORIGIN")
else()
set(CPPINYIN_RPATH_ORIGIN "@loader_path")
endif()
set(CMAKE_INSTALL_RPATH ${CPPINYIN_RPATH_ORIGIN})
set(CMAKE_BUILD_RPATH ${CPPINYIN_RPATH_ORIGIN})
option(CPPINYIN_ENABLE_TESTS "Whether to build tests" OFF)
option(CPPINYIN_BUILD_PYTHON "Whether to build Python" ON)
option(BUILD_SHARED_LIBS "Whether to build shared libraries" ON)
if(WIN32)
message(STATUS "Set BUILD_SHARED_LIBS to OFF for Windows")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No CMAKE_BUILD_TYPE given, default to Release")
set(CMAKE_BUILD_TYPE Release)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(CheckCXXCompilerFlag)
if(NOT WIN32)
check_cxx_compiler_flag("-std=c++14" CPPINYIN_COMPILER_SUPPORTS_CXX14)
else()
# windows x86 or x86_64
check_cxx_compiler_flag("/std:c++14" CPPINYIN_COMPILER_SUPPORTS_CXX14)
endif()
if(NOT CPPINYIN_COMPILER_SUPPORTS_CXX14)
message(FATAL_ERROR "
cppinyin requires a compiler supporting at least C++14.
If you are using GCC, please upgrade it to at least version 7.0.
If you are using Clang, please upgrade it to at least version 3.4.")
endif()
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ version to be used.")
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "C++ Standard version: ${CMAKE_CXX_STANDARD}")
if(CPPINYIN_BUILD_PYTHON)
include(pybind11)
endif()
include_directories(${CMAKE_SOURCE_DIR})
if(WIN32)
# disable various warnings for MSVC
# 4244: 'initializing': conversion from 'float' to 'int32_t',
# 4267: 'argument': conversion from 'size_t' to 'uint32_t', possible loss of data
set(disabled_warnings
/wd4244
/wd4267
)
message(STATUS "Disabled warnings: ${disabled_warnings}")
foreach(w IN LISTS disabled_warnings)
string(APPEND CMAKE_CXX_FLAGS " ${w} ")
endforeach()
endif()
if(CPPINYIN_ENABLE_TESTS)
include(googletest)
enable_testing()
endif()
add_subdirectory(cppinyin)