-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
156 lines (139 loc) · 5.86 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.20)
SET(name g3kb-switch)
SET(HOMEPAGE_URL https://github.com/lyokha/g3kb-switch)
STRING(TIMESTAMP BUILD_DATE "%d %B %Y")
# get version from git tag in github action
STRING(REGEX MATCH [[[0-9](\.[0-9])*]] VERSION "$ENV{GITHUB_REF_NAME}")
IF(NOT VERSION)
# a fallback
EXECUTE_PROCESS(COMMAND git describe OUTPUT_VARIABLE VERSION)
STRING(REGEX MATCH [[[0-9](\.[0-9])*]] VERSION "${VERSION}")
IF(NOT VERSION)
SET(VERSION 0.0.0.0)
ENDIF()
ENDIF()
PROJECT(${name}
LANGUAGES C
HOMEPAGE_URL ${HOMEPAGE_URL}
DESCRIPTION "CLI keyboard layout switcher for Gnome 3 and 4x"
VERSION ${VERSION})
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
ADD_DEFINITIONS(-D__OPTIMIZE__)
INCLUDE(GNUInstallDirs)
INCLUDE(CMakeDependentOption)
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_SEARCH_MODULE(GIO REQUIRED gio-2.0)
CONFIGURE_FILE(config.h.in config.h)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
SET(GNOME_SHELL_EXTENSIONS_DIR
${CMAKE_INSTALL_DATAROOTDIR}/gnome-shell/extensions)
SET(BASH_COMPLETION_COMPLETIONSDIR "" CACHE STRING
"The directory of bash completions, \
empty will use the default value coming from pkg-config")
SET(ZSH_COMPLETION_COMPLETIONSDIR "" CACHE STRING
"The directory of zsh completions, empty will use the default value")
OPTION(G3KBSWITCH_WITH_LEGACY_GNOME_SHELL_EXTENSION
"Use Gnome Shell extension (for Gnome Shell 44 and older)" OFF)
IF(G3KBSWITCH_WITH_LEGACY_GNOME_SHELL_EXTENSION)
ADD_DEFINITIONS(-DG3KBSWITCH_WITH_GNOME_SHELL_EXTENSION)
INSTALL(DIRECTORY extension/[email protected]/
DESTINATION ${GNOME_SHELL_EXTENSIONS_DIR}/[email protected])
ENDIF()
CMAKE_DEPENDENT_OPTION(G3KBSWITCH_WITH_GNOME_SHELL_EXTENSION
"Use Gnome Shell extension" ON
"NOT G3KBSWITCH_WITH_LEGACY_GNOME_SHELL_EXTENSION" OFF)
IF(G3KBSWITCH_WITH_GNOME_SHELL_EXTENSION)
ADD_DEFINITIONS(-DG3KBSWITCH_WITH_GNOME_SHELL_EXTENSION)
INSTALL(DIRECTORY extension/[email protected]
DESTINATION ${GNOME_SHELL_EXTENSIONS_DIR})
ENDIF()
ADD_EXECUTABLE(${name} main.c switch.c)
INCLUDE_DIRECTORIES(${GIO_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${name} ${GIO_LDFLAGS})
#TARGET_COMPILE_OPTIONS(${name} PUBLIC -Wall)
OPTION(G3KBSWITCH_BUILD_VIM_XKBSWITCH_LIB "Build plugin for vim-xkbswitch" ON)
IF(G3KBSWITCH_BUILD_VIM_XKBSWITCH_LIB)
SET(g3kblib g3kbswitch)
ADD_LIBRARY(${g3kblib} SHARED switch.c switch-api.c)
TARGET_LINK_LIBRARIES(${g3kblib} ${GIO_LDFLAGS})
#TARGET_COMPILE_OPTIONS(${g3kblib} PUBLIC -Wall)
ENDIF()
OPTION(G3KBSWITCH_INSTALL_BASH_COMPLETION "Install bash completion script" ON)
IF(G3KBSWITCH_INSTALL_BASH_COMPLETION)
IF(NOT BASH_COMPLETION_COMPLETIONSDIR)
FIND_PACKAGE(bash-completion)
ENDIF()
IF(NOT BASH_COMPLETION_COMPLETIONSDIR)
SET(BASH_COMPLETION_COMPLETIONSDIR
"${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions")
ENDIF()
INSTALL(FILES g3kb-switch-completion.bash
DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR}
RENAME ${name})
ENDIF()
OPTION(G3KBSWITCH_INSTALL_ZSH_COMPLETION "Install zsh completion script" ON)
IF(G3KBSWITCH_INSTALL_ZSH_COMPLETION)
IF(NOT ZSH_COMPLETION_COMPLETIONSDIR)
SET(ZSH_COMPLETION_COMPLETIONSDIR
${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions)
ENDIF()
INSTALL(FILES g3kb-switch-completion.zsh
DESTINATION ${ZSH_COMPLETION_COMPLETIONSDIR}
RENAME _${name})
ENDIF()
SET(G3KBSWITCH_VIM_XKBSWITCH_LIB_PATH ${CMAKE_INSTALL_LIBDIR} CACHE STRING
"Xkbswitch library path relative to ${CMAKE_INSTALL_PREFIX}")
INSTALL(TARGETS ${name} ${g3kblib}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${G3KBSWITCH_VIM_XKBSWITCH_LIB_PATH} OPTIONAL)
OPTION(G3KBSWITCH_INSTALL_PC_FILE "Install pkg-config file" ON)
IF(G3KBSWITCH_INSTALL_PC_FILE)
IF(G3KBSWITCH_BUILD_VIM_XKBSWITCH_LIB)
CMAKE_PATH(APPEND
G3KBSWITCH_PC_LIBPATH_DECL
"\${prefix}"
${G3KBSWITCH_VIM_XKBSWITCH_LIB_PATH}
"$<TARGET_FILE_NAME:g3kbswitch>")
STRING(PREPEND G3KBSWITCH_PC_LIBPATH_DECL "libpath=")
ENDIF()
IF(G3KBSWITCH_WITH_GNOME_SHELL_EXTENSION)
SET(G3KBSWITCH_PC_EXTNAME_DECL "[email protected]")
ENDIF()
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/${name}.pc.in
${CMAKE_BINARY_DIR}/${name}.pc.1.in
@ONLY)
FILE(GENERATE
OUTPUT ${CMAKE_BINARY_DIR}/${name}.pc
INPUT ${CMAKE_BINARY_DIR}/${name}.pc.1.in)
INSTALL(FILES ${CMAKE_BINARY_DIR}/${name}.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
ENDIF()
OPTION(G3KBSWITCH_INSTALL_MAN_PAGE "Install man documentation" ON)
IF(G3KBSWITCH_INSTALL_MAN_PAGE)
SET(man_page ${name}.1)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/docs/${man_page}.in
${CMAKE_BINARY_DIR}/docs/${man_page})
FIND_PROGRAM(GZIP gzip)
IF(GZIP)
SET(man_gz ${CMAKE_BINARY_DIR}/${man_page}.gz)
ADD_CUSTOM_TARGET(man-${name} ALL DEPENDS ${man_gz})
ADD_CUSTOM_COMMAND(
OUTPUT ${man_gz}
COMMAND ${GZIP} -9 --no-name --to-stdout "${man_page}" >"${man_gz}"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/docs)
SET(man_page ${man_gz})
ELSE()
SET(man_page ${CMAKE_BINARY_DIR}/docs/${man_page})
ENDIF()
INSTALL(FILES ${man_page}
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
ENDIF()
SET(CPACK_PACKAGE_CONTACT ${HOMEPAGE_URL}/issues)
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Alexey Radkov <[email protected]>")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS libglib2.0-0)
SET(CPACK_RPM_PACKAGE_REQUIRES glib2)
SET(CPACK_RPM_PACKAGE_LICENSE BSD2)
SET(CPACK_RPM_PACKAGE_URL ${HOMEPAGE_URL})
INCLUDE(CPack)
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
SET(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")