-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
192 lines (158 loc) · 5.28 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
cmake_minimum_required(VERSION 3.10)
# Project
project(chromashell
VERSION 1.0)
set(chromashell_VERSION_YEAR
2022)
set(OUTPUT_NAME
chromashell)
# Flags
set(CMAKE_CXX_FLAGS_DEBUG "-g")
# Executable
set(chromashell_CODE_SOURCE_DIR
${chromashell_SOURCE_DIR}/src)
set(chromashell_SYSTEM_DIR
share/chromashell)
configure_file(${chromashell_CODE_SOURCE_DIR}/config.h.in
${chromashell_CODE_SOURCE_DIR}/config.h)
set(chromashell_SOURCES
chromashell.c
color.c
errmsg.c
presets.c
shell.c
typecheck.c
vstrcmp.c)
list(TRANSFORM chromashell_SOURCES
PREPEND "${chromashell_CODE_SOURCE_DIR}/")
add_executable(${OUTPUT_NAME}
${chromashell_SOURCES})
target_include_directories(chromashell PUBLIC
"${chromashell_BINARY_DIR}")
# Internationalization
find_package(Intl REQUIRED)
if(Intl_FOUND)
message(STATUS "Internationalization found:")
message(STATUS " INTL_INCLUDE_DIRS: ${Intl_INCLUDE_DIRS}")
message(STATUS " INTL_LIBRARIES: ${Intl_LIBRARIES}")
message(STATUS " Version: ${Intl_VERSION}")
include_directories(${Intl_INCLUDE_DIRS})
link_directories(${Intl_LIBRARY_DIRS})
else()
message(STATUS "Internationalization not found!")
endif()
find_package(Gettext REQUIRED)
if(Gettext_FOUND)
message(STATUS "gettext found:")
message(STATUS " Version: ${GETTEXT_VERSION_STRING}")
else()
message(STATUS "gettext not found!")
endif()
find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
find_program(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
set(CMAKE_LOCALE_SOURCE_DIR
${CMAKE_SOURCE_DIR}/locale)
set(CMAKE_LOCALE_BINARY_DIR
${CMAKE_BINARY_DIR}/locale)
if(GETTEXT_XGETTEXT_EXECUTABLE)
message(DEBUG " xgettext: ${GETTEXT_XGETTEXT_EXECUTABLE}")
add_custom_target(
pot-update
DEPENDS "${CMAKE_LOCALE_SOURCE_DIR}/${OUTPUT_NAME}.pot"
COMMENT "pot-update: Done.")
add_custom_command(
OUTPUT "${CMAKE_LOCALE_SOURCE_DIR}/${OUTPUT_NAME}.pot"
COMMAND
${CMAKE_COMMAND}
-E make_directory "${CMAKE_LOCALE_SOURCE_DIR}"
COMMAND
${GETTEXT_XGETTEXT_EXECUTABLE}
--from-code=utf-8
--force-po
--output=${CMAKE_LOCALE_SOURCE_DIR}/${OUTPUT_NAME}.pot
--keyword=_
--width=80
${chromashell_SOURCES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "pot-update: pot file generated: ${CMAKE_LOCALE_SOURCE_DIR}/${OUTPUT_NAME}.pot")
endif(GETTEXT_XGETTEXT_EXECUTABLE)
if(GETTEXT_MSGMERGE_EXECUTABLE)
message(DEBUG " msgmerge: ${GETTEXT_MSGMERGE_EXECUTABLE}")
add_custom_target(
pot-merge
COMMENT "pot-merge: Done."
DEPENDS ${CMAKE_LOCALE_SOURCE_DIR}/${OUTPUT_NAME}.pot)
file(GLOB PO_FILES ${CMAKE_LOCALE_SOURCE_DIR}/*.po)
message(TRACE " PO_FILES: ${PO_FILES}")
foreach(PO_FILE IN ITEMS ${PO_FILES})
message(STATUS " Adding msgmerge for: ${PO_FILE}")
add_custom_command(
TARGET pot-merge
PRE_BUILD
COMMAND
${GETTEXT_MSGMERGE_EXECUTABLE}
${PO_FILE}
${CMAKE_LOCALE_SOURCE_DIR}/${OUTPUT_NAME}.pot
COMMENT "pot-merge: ${PO_FILE}")
endforeach()
endif(GETTEXT_MSGMERGE_EXECUTABLE)
if(GETTEXT_MSGFMT_EXECUTABLE)
message(DEBUG " msgmerge: ${GETTEXT_MSGFMT_EXECUTABLE}")
message(TRACE " PO_LANGS: ${PO_LANGS}")
add_custom_target(
po-compile
COMMENT "po-compile: Done.")
file(GLOB PO_FILES ${CMAKE_LOCALE_SOURCE_DIR}/*.po)
message(TRACE " PO_FILES: ${PO_FILES}")
foreach(PO_FILE IN ITEMS ${PO_FILES})
get_filename_component(PO_LANG
${PO_FILE}
NAME_WE)
message(STATUS " Adding msgfmt for: ${PO_LANG}")
add_custom_command(
TARGET po-compile
PRE_BUILD
COMMAND
${CMAKE_COMMAND}
-E make_directory ${CMAKE_LOCALE_BINARY_DIR}/${PO_LANG}/LC_MESSAGES
COMMAND
${GETTEXT_MSGFMT_EXECUTABLE}
--output-file=${CMAKE_LOCALE_BINARY_DIR}/${PO_LANG}/LC_MESSAGES/${OUTPUT_NAME}.mo
${PO_FILE}
COMMENT "po-compile: ${PO_LANG}")
endforeach()
endif(GETTEXT_MSGFMT_EXECUTABLE)
# Libraries
target_link_libraries(chromashell PRIVATE cjson)
# Post-build
add_custom_command(TARGET chromashell POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${chromashell_CODE_SOURCE_DIR}/presets.json
${CMAKE_CURRENT_BINARY_DIR})
# Install
install(TARGETS chromashell
RUNTIME
DESTINATION bin)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/presets.json
DESTINATION ${chromashell_SYSTEM_DIR})
file(GLOB PO_LANGS LIST_DIRECTORIES true ${CMAKE_LOCALE_BINARY_DIR}/*)
foreach(PO_LANG IN ITEMS ${PO_LANGS})
if(IS_DIRECTORY ${PO_LANG})
message(STATUS ${PO_LANG})
install(DIRECTORY
${PO_LANG}
DESTINATION locale)
endif()
endforeach()
# Uninstall
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
endif()