This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
forked from hunspell/hunspell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
158 lines (131 loc) · 5.6 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
# ---------------------------------------------------------------------------- #
cmake_minimum_required(VERSION 3.13)
project(hunspell LANGUAGES C CXX VERSION 1.7.2)
# ~~~ Options
option(HUNSPELL_BUILD_TOOLS "Build Hunspell tools and parser." OFF)
option(HUNSPELL_BUILD_STATIC_LIB "Build static hunspell library." ON)
option(HUNSPELL_BUILD_SHARED_LIB "Build shared hunspell library." OFF)
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# ~~~ Setup paths and vars
set(HUNSPELL_NAMESPACE "${PROJECT_NAME}::")
set(HUNSPELL_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(HUNSPELL_INCLUDE_INSTALL_DIR "include")
set(HUNSPELL_LIBRARY_INSTALL_DIR "lib")
set(HUNSPELL_RUNTIME_INSTALL_DIR "bin")
set(HUNSPELL_INSTALL_TARGETS "" CACHE INTERNAL "")
set(HUNSPELL_EXTRA_EXPORT_TARGETS "" CACHE INTERNAL "")
set(VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
# Set RPATH for installed executables
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${HUNSPELL_LIBRARY_INSTALL_DIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# ~~~ Compiler options and definitions
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITY)
if(NOT HAVE_VISIBILITY)
set(HAVE_VISIBILITY 0)
endif()
if(MSVC)
# Group targets in folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_compile_definitions(
"_CRT_SECURE_NO_WARNINGS"
)
# Set warning level; disable specific warnings
add_compile_options(
"-W4"
"-wd4251"
"-wd4267"
"-wd4706"
)
endif()
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# ~~~ Macro for adding install targets
macro(add_install_target arg1)
set(HUNSPELL_INSTALL_TARGETS ${HUNSPELL_INSTALL_TARGETS} ${arg1} CACHE INTERNAL "")
endmacro()
# ~~~ Macro for adding extra export targets in build-tree
macro(add_extra_export_target arg1)
set(HUNSPELL_EXTRA_EXPORT_TARGETS ${HUNSPELL_EXTRA_EXPORT_TARGETS} ${arg1} CACHE INTERNAL "")
endmacro()
# ~~~ Copy dll, don't use GENERATOR_IS_MULTI_CONFIG as it doesn't get set for some reason
function(copy_dll_if_changed arg1 arg2)
set(LIB_DIR "$<TARGET_PROPERTY:${arg1},BINARY_DIR>")
set(LIB_FILE "$<TARGET_FILE_NAME:${arg1}>")
add_custom_command(TARGET ${arg2} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${LIB_DIR}/$<$<BOOL:CMAKE_CONFIGURATION_TYPES>:$<CONFIG>/>${LIB_FILE}
$<TARGET_FILE_DIR:${arg2}>
)
endfunction()
# Add source subdirectory
add_subdirectory(src)
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# ~~~ Configure install and export
include(CMakePackageConfigHelpers)
# ~~~ Set paths
set(HUNSPELL_CONFIG_INSTALL_DIR "${HUNSPELL_LIBRARY_INSTALL_DIR}/cmake/${PROJECT_NAME}")
set(HUNSPELL_PKG_CONFIG_INSTALL_DIR "${HUNSPELL_LIBRARY_INSTALL_DIR}/pkgconfig")
set(HUNSPELL_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(HUNSPELL_VERSION_CONFIG_FILE "${PROJECT_NAME}ConfigVersion.cmake")
set(HUNSPELL_PROJECT_CONFIG_FILE "${PROJECT_NAME}Config.cmake")
# ~~~ Install targets
install(
TARGETS ${HUNSPELL_INSTALL_TARGETS}
EXPORT ${HUNSPELL_TARGETS_EXPORT_NAME}
RUNTIME DESTINATION ${HUNSPELL_RUNTIME_INSTALL_DIR}
LIBRARY DESTINATION ${HUNSPELL_LIBRARY_INSTALL_DIR}
ARCHIVE DESTINATION ${HUNSPELL_LIBRARY_INSTALL_DIR}
)
# ~~~ Write config version file
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${HUNSPELL_VERSION_CONFIG_FILE}
COMPATIBILITY SameMinorVersion
)
# Install project version file
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${HUNSPELL_VERSION_CONFIG_FILE}
DESTINATION ${HUNSPELL_CONFIG_INSTALL_DIR}
)
# ~~~ Generate and install project config file
install(
EXPORT ${HUNSPELL_TARGETS_EXPORT_NAME}
NAMESPACE ${HUNSPELL_NAMESPACE}
DESTINATION ${HUNSPELL_CONFIG_INSTALL_DIR}
FILE ${HUNSPELL_PROJECT_CONFIG_FILE}
)
# Export project config file separately in build tree
export(
TARGETS
${HUNSPELL_INSTALL_TARGETS}
${HUNSPELL_EXTRA_EXPORT_TARGETS}
NAMESPACE ${HUNSPELL_NAMESPACE}
FILE ${HUNSPELL_PROJECT_CONFIG_FILE}
)
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# ~~~ Write pkg-config pc file
set(PKG_PC_FILE_IN ${CMAKE_CURRENT_BINARY_DIR}/hunspell.pc.in)
set(PKG_PC_FILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/hunspell.pc)
if (UNIX)
file(WRITE ${PKG_PC_FILE_IN} [=[
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@HUNSPELL_LIBRARY_INSTALL_DIR@
includedir=${prefix}/@HUNSPELL_INCLUDE_INSTALL_DIR@
Name: hunspell
Description: Hunspell spellchecking library
Version: @VERSION@
Libs: -L${libdir} -l@HUNSPELL_LIB_OUTPUT_NAME@
Cflags: -I${includedir}/@HUNSPELL_LIB_INCLUDE_PREFIX@
]=])
configure_file(${PKG_PC_FILE_IN} ${PKG_PC_FILE_OUT} @ONLY)
install(
FILES ${PKG_PC_FILE_OUT}
DESTINATION ${HUNSPELL_PKG_CONFIG_INSTALL_DIR}
)
endif()
# ---------------------------------------------------------------------------- #