forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
477 lines (410 loc) · 15.9 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
cmake_minimum_required(VERSION 3.0.0)
project(awesome C)
# Require an out-of-source build. We generate an awesomerc.lua in the build dir
# from the one in the source dir and this does not work otherwise.
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(SEND_ERROR "\
You appear to be doing an in-source build, which means that the binaries are \
generated in the same directory where the source code is. This is currently not \
supported. Instead, do, for example, the following:\n\
mkdir build && cd build && cmake ..\n\
Beware that CMake likely already generated a CMakeCache.txt in the source \
directory which you first have to delete. \
")
message(FATAL_ERROR "In-source builds are not supported")
endif()
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
if(COMMAND cmake_policy)
cmake_policy(VERSION 2.6)
endif()
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
if(NOT EXISTS ${SOURCE_DIR}/awesomeConfig.cmake)
message(FATAL_ERROR "Please provide awesomeConfig.cmake")
endif()
# Define many variables
include(awesomeConfig.cmake)
include_directories(
${BUILD_DIR}
${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}
${AWESOME_REQUIRED_INCLUDE_DIRS}
${AWESOME_OPTIONAL_INCLUDE_DIRS})
set(AWE_ICON_DIR ${SOURCE_DIR}/icons)
set(AWE_THEMES_DIR ${SOURCE_DIR}/themes)
set(AWE_DOC_DIR ${BUILD_DIR}/docs)
set(AWE_DOC_FILES
${AWE_DOC_DIR}/00-authors.md
${AWE_DOC_DIR}/01-readme.md
${AWE_DOC_DIR}/02-contributing.md
${SOURCE_DIR}/LICENSE)
set(AWE_SRCS
${BUILD_DIR}/awesome.c
${BUILD_DIR}/banning.c
${BUILD_DIR}/color.c
${BUILD_DIR}/dbus.c
${BUILD_DIR}/draw.c
${BUILD_DIR}/event.c
${BUILD_DIR}/ewmh.c
${BUILD_DIR}/keygrabber.c
${BUILD_DIR}/luaa.c
${BUILD_DIR}/mouse.c
${BUILD_DIR}/mousegrabber.c
${BUILD_DIR}/property.c
${BUILD_DIR}/root.c
${BUILD_DIR}/selection.c
${BUILD_DIR}/spawn.c
${BUILD_DIR}/stack.c
${BUILD_DIR}/strut.c
${BUILD_DIR}/systray.c
${BUILD_DIR}/xwindow.c
${BUILD_DIR}/options.c
${BUILD_DIR}/xkb.c
${BUILD_DIR}/xrdb.c
${BUILD_DIR}/common/atoms.c
${BUILD_DIR}/common/backtrace.c
${BUILD_DIR}/common/buffer.c
${BUILD_DIR}/common/luaclass.c
${BUILD_DIR}/common/lualib.c
${BUILD_DIR}/common/luaobject.c
${BUILD_DIR}/common/util.c
${BUILD_DIR}/common/version.c
${BUILD_DIR}/common/xcursor.c
${BUILD_DIR}/common/xembed.c
${BUILD_DIR}/common/xutil.c
${BUILD_DIR}/objects/button.c
${BUILD_DIR}/objects/client.c
${BUILD_DIR}/objects/drawable.c
${BUILD_DIR}/objects/drawin.c
${BUILD_DIR}/objects/key.c
${BUILD_DIR}/objects/screen.c
${BUILD_DIR}/objects/selection_acquire.c
${BUILD_DIR}/objects/selection_transfer.c
${BUILD_DIR}/objects/selection_watcher.c
${BUILD_DIR}/objects/tag.c
${BUILD_DIR}/objects/selection_getter.c
${BUILD_DIR}/objects/window.c)
set(AWE_MAN_SRCS
${SOURCE_DIR}/manpages/awesome.1.txt
${SOURCE_DIR}/manpages/awesome-client.1.txt
${SOURCE_DIR}/manpages/awesomerc.5.txt)
set(AWE_MAN_LANGS it es fr de ru)
# Don't strip RPATH if compiling on Solaris
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
add_executable(${PROJECT_AWE_NAME}
${AWE_SRCS})
# CFLAGS
set(AWESOME_C_FLAGS
-O1 -std=gnu99 -ggdb3 -fno-strict-aliasing -Wall -Wextra
-Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings
-Wsign-compare -Wunused -Wno-unused-parameter -Wuninitialized -Winit-self
-Wpointer-arith -Wformat-nonliteral
-Wno-format-zero-length -Wmissing-format-attribute -Wmissing-prototypes
-Wstrict-prototypes
CACHE STRING "CFLAGS used to compile ${PROJECT_AWE_NAME}")
mark_as_advanced(AWESOME_C_FLAGS)
target_compile_options(${PROJECT_AWE_NAME} PRIVATE ${AWESOME_C_FLAGS})
# Make sure awesomerc.lua is generated
add_dependencies(${PROJECT_AWE_NAME} generate_awesomerc)
# Linux w/ GCC requires -rdynamic to get backtrace to fully work.
#
# For "historical reasons", CMake adds the option to the linker flags
# unnoticeably for Linux w/ GCC through its modules Linux-GNU.cmake
# and Linux-GNU-C.cmake. Our build system has counted on that. But
# just in case CMake should do away with the convention suddenly...
if(DEFINED CMAKE_SHARED_LIBRARY_LINK_C_FLAGS AND
NOT CMAKE_SHARED_LIBRARY_LINK_C_FLAGS MATCHES "-rdynamic")
target_link_libraries(${PROJECT_AWE_NAME}
$<$<AND:$<PLATFORM_ID:Linux>,$<C_COMPILER_ID:GNU>>:-rdynamic>)
endif()
# FreeBSD requires dynamic linking
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set_target_properties(${PROJECT_AWE_NAME}
PROPERTIES
LINK_FLAGS -export-dynamic)
endif()
target_link_libraries(${PROJECT_AWE_NAME}
${AWESOME_COMMON_REQUIRED_LDFLAGS}
${AWESOME_REQUIRED_LDFLAGS}
${AWESOME_OPTIONAL_LDFLAGS})
# {{{ Generated sources
# atoms
file(MAKE_DIRECTORY ${BUILD_DIR}/common)
add_custom_command(
COMMAND ${SOURCE_DIR}/build-utils/atoms-ext.sh ${SOURCE_DIR}/common/atoms.list
ARGS > ${BUILD_DIR}/common/atoms-extern.h
OUTPUT ${BUILD_DIR}/common/atoms-extern.h
WORKING_DIRECTORY ${SOURCE_DIR}
DEPENDS ${SOURCE_DIR}/common/atoms.list
COMMENT "Generating atoms-extern.h"
VERBATIM)
add_custom_command(
COMMAND ${SOURCE_DIR}/build-utils/atoms-int.sh ${SOURCE_DIR}/common/atoms.list
ARGS > ${BUILD_DIR}/common/atoms-intern.h
OUTPUT ${BUILD_DIR}/common/atoms-intern.h
WORKING_DIRECTORY ${SOURCE_DIR}
DEPENDS ${SOURCE_DIR}/common/atoms.list
COMMENT "Generating atoms-intern.h"
VERBATIM)
add_custom_target(generated_sources
DEPENDS ${BUILD_DIR}/common/atoms-intern.h
${BUILD_DIR}/common/atoms-extern.h)
# Default theme directory
file(MAKE_DIRECTORY ${BUILD_DIR}/themes/default)
file(MAKE_DIRECTORY ${BUILD_DIR}/themes/sky)
file(MAKE_DIRECTORY ${BUILD_DIR}/themes/zenburn)
file(MAKE_DIRECTORY ${BUILD_DIR}/themes/xresources)
add_dependencies(${PROJECT_AWE_NAME} generated_sources)
# }}}
# {{{ Version stamp
if(BUILD_FROM_GIT)
add_custom_target(version_stamp ALL
COMMAND ${SOURCE_DIR}/build-utils/git-version-stamp.sh
${VERSION_STAMP_FILE}
${BUILD_DIR}/awesome-version-internal.h
WORKING_DIRECTORY ${SOURCE_DIR})
add_dependencies(${PROJECT_AWE_NAME} version_stamp)
endif()
# }}}
# {{{ Manpages
if(GENERATE_MANPAGES)
if(NOT BUILD_DIR STREQUAL SOURCE_DIR)
file(MAKE_DIRECTORY ${BUILD_DIR}/manpages)
endif()
# add the default translation to the list of languages
set(AWE_MAN_LANGS default ${AWE_MAN_LANGS})
foreach(lang ${AWE_MAN_LANGS})
foreach(txtfile ${AWE_MAN_SRCS})
# figure the base name of the file (ie "awesome.1")
GET_FILENAME_COMPONENT(tmpname ${txtfile} NAME)
string(REGEX REPLACE ".txt\$" "" basename ${tmpname})
# figure the relative path of the file
GET_FILENAME_COMPONENT(tmppath ${txtfile} PATH)
string(REPLACE ${SOURCE_DIR}/ "" relpath ${tmppath})
# figure the manpage section to install to from filename
string(REGEX REPLACE "^.*\\.([0-9])$" "\\1" section ${basename})
# construct the language specific versions of the basename and path
if (lang STREQUAL default)
set(basename2 ${basename})
set(relpath2 ${relpath}/man${section})
else()
set(basename2 ${basename}.${lang})
set(relpath2 ${relpath}/${lang}/man${section})
endif()
# create the build directory (if it does not exist)
file(MAKE_DIRECTORY ${BUILD_DIR}/${relpath2})
# set the final filenames
set(txtfile ${SOURCE_DIR}/${relpath}/${basename2}.txt)
set(gzfile ${BUILD_DIR}/${relpath2}/${basename}.gz)
set(manfile ${BUILD_DIR}/${relpath2}/${basename})
if (lang STREQUAL default)
set(asciilang en)
else()
set(asciilang ${lang})
endif()
add_custom_command(
COMMAND ${ASCIIDOCTOR_EXECUTABLE} -a lang=${asciilang} -d manpage -b manpage -o ${manfile} ${txtfile}
WORKING_DIRECTORY ${BUILD_DIR}/${relpath2}
OUTPUT ${manfile}
DEPENDS ${txtfile}
VERBATIM)
if(COMPRESS_MANPAGES)
add_custom_command(
COMMAND ${GZIP_EXECUTABLE} < ${manfile} > ${gzfile}
OUTPUT ${gzfile}
WORKING_DIRECTORY ${BUILD_DIR}/${relpath2}
DEPENDS ${manfile}
VERBATIM)
set(MAN_FILES ${MAN_FILES} ${gzfile})
else()
set(MAN_FILES ${MAN_FILES} ${manfile})
endif()
endforeach()
endforeach()
add_custom_target(man ALL DEPENDS ${MAN_FILES})
endif()
# }}}
# {{{ Lua API Documentation
if(GENERATE_DOC)
if(NOT BUILD_DIR STREQUAL SOURCE_DIR)
file(MAKE_DIRECTORY ${BUILD_DIR}/lib)
file(MAKE_DIRECTORY ${BUILD_DIR}/doc)
endif()
file(GLOB_RECURSE AWE_LUA_FILES ${BUILD_DIR}/lib/*.lua)
file(GLOB_RECURSE AWE_MD_FILES ${AWE_DOC_DIR}/*.md)
file(GLOB_RECURSE AWE_MD_LUA_FILES RELATIVE "${SOURCE_DIR}/docs" docs/*.md.lua)
foreach(file ${AWE_MD_LUA_FILES})
# Remove .lua file extensions
string(REPLACE ".lua" "" file ${file})
list(APPEND AWE_MD_FILES "${AWE_DOC_DIR}/${file}")
endforeach()
# Copy the images to the build directory
file(COPY ${SOURCE_DIR}/docs/images DESTINATION ${BUILD_DIR}/doc)
# Copy ldoc files.
configure_file(${SOURCE_DIR}/docs/ldoc.css ${BUILD_DIR}/docs COPYONLY)
configure_file(${SOURCE_DIR}/docs/ldoc.ltp ${BUILD_DIR}/docs COPYONLY)
add_custom_target(ldoc ALL
DEPENDS ${BUILD_DIR}/doc/index.html DOC_EXAMPLES_PPOSTPROCESS_CLEANUP
)
if (STRICT_TESTS)
set(ldoc_args --fatalwarnings .)
set(ldoc_desc_suffix " (fatal warnings)")
else()
set(ldoc_args .)
endif()
add_custom_command(
OUTPUT ${BUILD_DIR}/doc/index.html
COMMAND ${LDOC_EXECUTABLE} ${ldoc_args}
WORKING_DIRECTORY ${AWE_DOC_DIR}
DEPENDS
${AWE_SRCS}
${AWE_LUA_FILES}
${AWE_MD_FILES}
${BUILD_DIR}/docs/config.ld
${BUILD_DIR}/docs/ldoc.css
${BUILD_DIR}/docs/ldoc.ltp
generate_awesomerc
generate-examples
COMMENT "Generating API documentation${ldoc_desc_suffix}")
endif()
# }}}
# {{{ Theme icons
file(GLOB_RECURSE icon_sources RELATIVE ${SOURCE_DIR} ${SOURCE_DIR}/themes/*.png)
foreach(icon ${icon_sources})
# Copy all icons to the build dir to simplify the following code.
# Source paths are interpreted relative to ${SOURCE_DIR}, target paths
# relative to ${BUILD_DIR}.
get_filename_component(icon_path ${icon} PATH)
get_filename_component(icon_name ${icon} NAME)
file(COPY ${icon} DESTINATION ${icon_path})
set(ALL_ICONS ${ALL_ICONS} "${icon_path}/${icon_name}")
endforeach()
macro(a_icon_convert match replacement input)
string(REPLACE ${match} ${replacement} output ${input})
if(NOT ${input} STREQUAL ${output} AND NOT ";${ALL_ICONS};" MATCHES ";${output};")
set(ALL_ICONS ${ALL_ICONS} ${output})
add_custom_command(
COMMAND ${CONVERT_EXECUTABLE} ${input} -strip ${ARGN} ${output}
OUTPUT ${output}
DEPENDS ${input}
VERBATIM)
endif()
endmacro()
foreach(icon ${ALL_ICONS})
# Make unfocused icons translucent
a_icon_convert("_focus" "_normal" ${icon}
-colorspace rgb -gamma 0.6 -channel A -evaluate Multiply 0.4)
endforeach()
foreach(icon ${ALL_ICONS})
# Make inactive icons grayscale
a_icon_convert("_active" "_inactive" ${icon}
-colorspace Gray)
endforeach()
add_custom_target(generated_icons ALL DEPENDS ${ALL_ICONS})
# }}}
# {{{ Dist tarball
if(BUILD_FROM_GIT)
add_custom_target(dist
COMMAND ${SOURCE_DIR}/build-utils/dist.sh ${VERSION}
WORKING_DIRECTORY ${SOURCE_DIR})
endif()
# }}}
# {{{ Installation
install(TARGETS ${PROJECT_AWE_NAME} RUNTIME DESTINATION bin)
install(FILES "utils/awesome-client" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY ${BUILD_DIR}/lib DESTINATION ${AWESOME_DATA_PATH}
PATTERN "*.in" EXCLUDE)
install(FILES ${BUILD_DIR}/awesomerc.lua DESTINATION ${AWESOME_SYSCONFDIR}
RENAME rc.lua)
if(GENERATE_MANPAGES)
if(COMPRESS_MANPAGES)
set(regex "\\.(xml|txt|[0-9])$")
else()
set(regex "\\.(xml|txt|gz)$")
endif()
install(DIRECTORY ${BUILD_DIR}/${relpath}/ DESTINATION ${AWESOME_MAN_PATH}
REGEX ${regex} EXCLUDE )
endif()
install(DIRECTORY ${AWE_ICON_DIR} DESTINATION ${AWESOME_DATA_PATH})
install(DIRECTORY ${SOURCE_DIR}/themes DESTINATION ${AWESOME_DATA_PATH}
PATTERN "*.lua" EXCLUDE)
install(DIRECTORY ${BUILD_DIR}/themes DESTINATION ${AWESOME_DATA_PATH}
PATTERN "*.lua")
install(FILES ${AWE_DOC_FILES} DESTINATION ${AWESOME_DOC_PATH})
install(FILES "awesome.desktop" DESTINATION ${AWESOME_XSESSION_PATH})
if(GENERATE_DOC)
install(DIRECTORY ${BUILD_DIR}/doc DESTINATION ${AWESOME_DOC_PATH})
endif()
# }}}
# {{{ Tests
add_custom_target(check DEPENDS check-integration)
add_executable(test-gravity tests/test-gravity.c)
target_link_libraries(test-gravity
${AWESOME_COMMON_REQUIRED_LDFLAGS} ${AWESOME_REQUIRED_LDFLAGS})
add_executable(test-systray tests/test-systray.c)
add_dependencies(test-systray generated_sources)
target_link_libraries(test-systray
${AWESOME_COMMON_REQUIRED_LDFLAGS} ${AWESOME_REQUIRED_LDFLAGS})
if(DO_COVERAGE)
set(TESTS_RUN_ENV DO_COVERAGE=1)
endif()
# Start AwesomeWM tests with `--screen off`
if ("${TEST_MANUAL_SCREENS}" MATCHES "1")
set(TEST_RUN_ARGS "--W --m")
endif()
add_custom_target(check-integration
${CMAKE_COMMAND} -E env CMAKE_BINARY_DIR='${CMAKE_BINARY_DIR}' LUA='${LUA_EXECUTABLE}' ${TESTS_RUN_ENV} ./tests/run.sh \$\${TEST_RUN_ARGS:--W}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running integration tests"
DEPENDS ${PROJECT_AWE_NAME}
USES_TERMINAL)
add_dependencies(check-integration test-gravity)
add_custom_target(check-themes
${CMAKE_COMMAND} -E env CMAKE_BINARY_DIR='${CMAKE_BINARY_DIR}' LUA='${LUA_EXECUTABLE}' ${TESTS_RUN_ENV} ./tests/themes/run.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Testing themes"
USES_TERMINAL
DEPENDS generated_icons generate_awesomerc ${PROJECT_AWE_NAME})
add_dependencies(check check-themes)
add_custom_target(check-requires
${LUA_EXECUTABLE} "${CMAKE_SOURCE_DIR}/build-utils/check_for_invalid_requires.lua"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Checking use of require()"
USES_TERMINAL
VERBATIM)
list(APPEND CHECK_QA_TARGETS check-requires)
a_find_program(BUSTED_EXECUTABLE busted FALSE)
if(BUSTED_EXECUTABLE)
if(DO_COVERAGE)
set(BUSTED_ARGS "--coverage")
else()
set(BUSTED_ARGS)
endif()
add_custom_target(check-unit
COMMAND ${BUSTED_EXECUTABLE} ${BUSTED_ARGS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running unit tests"
VERBATIM)
else()
add_custom_target(check-unit true
COMMENT "Skipping check-unit, since busted was not found (during configuration)"
VERBATIM)
endif()
add_dependencies(check check-unit)
a_find_program(LUACHECK_EXECUTABLE luacheck FALSE)
if(LUACHECK_EXECUTABLE)
add_custom_target(luacheck
${LUACHECK_EXECUTABLE} lib spec tests themes awesomerc.lua
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running Luacheck"
VERBATIM)
list(APPEND CHECK_QA_TARGETS luacheck)
endif()
add_custom_target(check-qa DEPENDS ${CHECK_QA_TARGETS})
add_dependencies(check check-qa check-examples)
# }}}
INCLUDE(${CMAKE_SOURCE_DIR}/Packaging.cmake)
# vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80:foldmethod=marker