image: copy data before using it
[awesome.git] / CMakeLists.txt
blob494d2cf1c63328271a50db941c739256ba7afe49
1 cmake_minimum_required(VERSION 2.6.0)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS  TRUE)
4 if(COMMAND cmake_policy)
5     cmake_policy(VERSION 2.6)
6 endif()
8 set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9 set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
11 if(NOT EXISTS ${SOURCE_DIR}/awesomeConfig.cmake)
12     message(FATAL_ERROR "Please provide awesomeConfig.cmake")
13 endif()
15 include(awesomeConfig.cmake)
17 include_directories(
18     ${SOURCE_DIR}
19     ${BUILD_DIR}
20     ${BUILD_DIR}/common
21     ${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}
22     ${AWESOME_REQUIRED_INCLUDE_DIRS}
23     ${AWESOME_OPTIONAL_INCLUDE_DIRS})
25 file(GLOB_RECURSE AWE_LUA_FILES ${BUILD_DIR}/lib/*.lua)
27 set(AWE_CONF_FILE_DEFAULT ${BUILD_DIR}/awesomerc.lua)
28 set(AWE_CONF_FILE rc.lua)
30 set(AWE_ICON_DIR ${SOURCE_DIR}/icons)
31 set(AWE_THEMES_DIR ${SOURCE_DIR}/themes)
33 set(AWE_DOC_FILES
34     ${SOURCE_DIR}/AUTHORS
35     ${SOURCE_DIR}/BUGS
36     ${SOURCE_DIR}/README
37     ${SOURCE_DIR}/LICENSE)
39 set(AWE_SRCS
40     ${SOURCE_DIR}/awesome.c
41     ${SOURCE_DIR}/client.c
42     ${SOURCE_DIR}/cnode.c
43     ${SOURCE_DIR}/dbus.c
44     ${SOURCE_DIR}/event.c
45     ${SOURCE_DIR}/property.c
46     ${SOURCE_DIR}/ewmh.c
47     ${SOURCE_DIR}/keybinding.c
48     ${SOURCE_DIR}/keygrabber.c
49     ${SOURCE_DIR}/mousegrabber.c
50     ${SOURCE_DIR}/layout.c
51     ${SOURCE_DIR}/luaa.c
52     ${SOURCE_DIR}/hooks.c
53     ${SOURCE_DIR}/mouse.c
54     ${SOURCE_DIR}/screen.c
55     ${SOURCE_DIR}/stack.c
56     ${SOURCE_DIR}/wibox.c
57     ${SOURCE_DIR}/systray.c
58     ${SOURCE_DIR}/tag.c
59     ${SOURCE_DIR}/titlebar.c
60     ${SOURCE_DIR}/widget.c
61     ${SOURCE_DIR}/window.c
62     ${SOURCE_DIR}/image.c
63     ${SOURCE_DIR}/draw.c
64     ${SOURCE_DIR}/swindow.c
65     ${SOURCE_DIR}/common/buffer.c
66     ${SOURCE_DIR}/common/atoms.c
67     ${SOURCE_DIR}/common/socket.c
68     ${SOURCE_DIR}/common/util.c
69     ${SOURCE_DIR}/common/version.c
70     ${SOURCE_DIR}/common/xembed.c
71     ${SOURCE_DIR}/common/xutil.c
72     ${SOURCE_DIR}/common/xcursor.c
73     ${SOURCE_DIR}/widgets/graph.c
74     ${SOURCE_DIR}/widgets/progressbar.c
75     ${SOURCE_DIR}/widgets/textbox.c
76     ${SOURCE_DIR}/widgets/systray.c
77     ${SOURCE_DIR}/widgets/imagebox.c)
79 set(AWE_CLIENT_SRCS
80     ${SOURCE_DIR}/awesome-client.c
81     ${SOURCE_DIR}/common/socket.c
82     ${SOURCE_DIR}/common/util.c
83     ${SOURCE_DIR}/common/version.c)
85 set(AWE_MAN_SRCS
86     ${SOURCE_DIR}/awesome.1.txt
87     ${SOURCE_DIR}/awsetbg.1.txt
88     ${SOURCE_DIR}/awesome-client.1.txt
89     ${SOURCE_DIR}/awesomerc.5.txt)
91 add_executable(${PROJECT_AWE_NAME}
92     ${AWE_SRCS}
93     ${BUILD_DIR}/common/tokenize.c)
95 add_executable(${PROJECT_AWECLIENT_NAME}
96     ${AWE_CLIENT_SRCS}
97     ${BUILD_DIR}/common/tokenize.c)
99 set_target_properties(${PROJECT_AWE_NAME}
100     PROPERTIES
101     LINK_FLAGS -export-dynamic)
103 target_link_libraries(${PROJECT_AWE_NAME}
104     ${AWESOME_COMMON_REQUIRED_LIBRARIES}
105     ${AWESOME_REQUIRED_LIBRARIES}
106     ${AWESOME_OPTIONAL_LIBRARIES})
108 target_link_libraries(${PROJECT_AWECLIENT_NAME}
109     ${AWESOME_COMMON_REQUIRED_LIBRARIES}
110     ${AWESOMECLIENT_LIBRARIES})
112 # {{{ Generated sources
113 add_custom_command(
114     COMMAND ${SOURCE_DIR}/build-utils/widgetgen.sh
115     ARGS    > ${BUILD_DIR}/widgetgen.h
116     OUTPUT  ${BUILD_DIR}/widgetgen.h
117     WORKING_DIRECTORY ${SOURCE_DIR}
118     DEPENDS ${SOURCE_DIR}/widget.h
119     COMMENT "Generating widgetgen.h"
120     VERBATIM)
122 # atoms
123 file(MAKE_DIRECTORY ${BUILD_DIR}/common)
124 add_custom_command(
125     COMMAND ${SOURCE_DIR}/build-utils/atoms-ext.sh ${SOURCE_DIR}/common/atoms.list
126     ARGS    > ${BUILD_DIR}/common/atoms-extern.h
127     OUTPUT  ${BUILD_DIR}/common/atoms-extern.h
128     WORKING_DIRECTORY ${SOURCE_DIR}
129     DEPENDS ${SOURCE_DIR}/common/atoms.list
130     COMMENT "Generating atoms-extern.h"
131     VERBATIM)
133 add_custom_command(
134     COMMAND ${SOURCE_DIR}/build-utils/atoms-int.sh ${SOURCE_DIR}/common/atoms.list
135     ARGS    > ${BUILD_DIR}/common/atoms-intern.h
136     OUTPUT  ${BUILD_DIR}/common/atoms-intern.h
137     WORKING_DIRECTORY ${SOURCE_DIR}
138     DEPENDS ${SOURCE_DIR}/common/atoms.list
139     COMMENT "Generating atoms-intern.h"
140     VERBATIM)
142 # gperf
143 add_custom_command(
144     COMMAND ${SOURCE_DIR}/build-utils/gperf.sh
145     ARGS    ${SOURCE_DIR}/common/tokenize.gperf
146             ${BUILD_DIR}/common/tokenize.h
147     OUTPUT  ${BUILD_DIR}/common/tokenize.h
148     DEPENDS ${SOURCE_DIR}/common/tokenize.gperf
149             ${SOURCE_DIR}/build-utils/gperf.sh
150     COMMENT "Generating common/tokenize.h")
152 add_custom_command(
153     COMMAND ${SOURCE_DIR}/build-utils/gperf.sh
154     ARGS    ${SOURCE_DIR}/common/tokenize.gperf
155             ${BUILD_DIR}/common/tokenize.c
156     OUTPUT  ${BUILD_DIR}/common/tokenize.c
157     DEPENDS ${SOURCE_DIR}/common/tokenize.gperf
158             ${SOURCE_DIR}/build-utils/gperf.sh
159     COMMENT "Generating common/tokenize.c")
161 add_custom_target(generated_sources
162     DEPENDS ${BUILD_DIR}/widgetgen.h
163             ${BUILD_DIR}/common/atoms-intern.h
164             ${BUILD_DIR}/common/atoms-extern.h
165             ${BUILD_DIR}/common/tokenize.c
166             ${BUILD_DIR}/common/tokenize.h)
168 # Default theme directory
169 file(MAKE_DIRECTORY ${BUILD_DIR}/themes/default)
170 file(MAKE_DIRECTORY ${BUILD_DIR}/themes/sky)
171 add_dependencies(${PROJECT_AWE_NAME} generated_sources)
172 add_dependencies(${PROJECT_AWECLIENT_NAME} generated_sources)
173 # }}}
175 # {{{ Version stamp
176 if(BUILD_FROM_GIT)
177     add_custom_target(version_stamp ALL
178         COMMAND ${SOURCE_DIR}/build-utils/git-version-stamp.sh
179                 ${VERSION_STAMP_FILE}
180                 ${BUILD_DIR}/awesome-version-internal.h
181         WORKING_DIRECTORY ${SOURCE_DIR})
183     add_dependencies(${PROJECT_AWE_NAME} version_stamp)
184     add_dependencies(${PROJECT_AWECLIENT_NAME} version_stamp)
185 endif()
186 # }}}
188 # {{{ Manpages
189 if(GENERATE_MANPAGES)
190     foreach(txtfile ${AWE_MAN_SRCS})
191         string(REGEX REPLACE ".txt\$" ".xml" xmlfile ${txtfile})
192         string(REPLACE ${SOURCE_DIR}
193                        ${BUILD_DIR} xmlfile ${xmlfile})
194         string(REGEX REPLACE ".xml\$" ".gz" gzfile ${xmlfile})
195         string(REGEX REPLACE ".gz\$" "" manfile ${gzfile})
197         add_custom_command(
198             COMMAND ${CAT_EXECUTABLE} ${txtfile}
199                     | ${ASCIIDOC_EXECUTABLE} -d manpage -b docbook -o ${xmlfile} -
200             WORKING_DIRECTORY ${BUILD_DIR}
201             OUTPUT  ${xmlfile}
202             DEPENDS ${txtfile}
203             VERBATIM)
204         add_custom_command(
205             COMMAND ${XMLTO_EXECUTABLE} man ${xmlfile}
206             OUTPUT  ${manfile}
207             DEPENDS ${xmlfile})
208         add_custom_command(
209             COMMAND ${CAT_EXECUTABLE} ${manfile}
210                     | ${GZIP_EXECUTABLE}
211                     > ${gzfile}
212             OUTPUT  ${gzfile}
213             DEPENDS ${manfile}
214             VERBATIM)
216         set(MAN_FILES ${MAN_FILES} ${gzfile})
218         # figure out in what section to install to from filename
219         string(REGEX REPLACE "^.*\\.([0-9])\\.gz\$" "\\1" section ${gzfile})
220         set(AWE_MAN${section}_FILES ${AWE_MAN${section}_FILES} ${gzfile})
221     endforeach()
223     add_custom_target(man ALL DEPENDS ${MAN_FILES})
224 endif()
225 # }}}
227 # {{{ Doxygen
228 if(DOXYGEN_EXECUTABLE)
229     add_custom_target(doc
230         COMMAND ${DOXYGEN_EXECUTABLE} awesome.doxygen
231         WORKING_DIRECTORY ${BUILD_DIR})
232 endif()
233 # }}}
235 # {{{ Lua API Documentation
236 if(GENERATE_LUADOC)
238     set(capi_lua ${BUILD_DIR}/lib/capi.lua)
240     if(NOT BUILD_DIR STREQUAL SOURCE_DIR)
241         file(MAKE_DIRECTORY ${BUILD_DIR}/lib)
242     endif()
244     # {{{ setup a command for ${capi_lua}
245     macro(a_file_match infile regex result_var)
246         file(STRINGS ${infile} match REGEX ${regex} LIMIT_COUNT 1)
247         if(match)
248             set(${result_var} TRUE)
249         else()
250             set(${result_var} FALSE)
251         endif()
252     endmacro()
254     set(luadoc_c_srcs "")
256     # find .c files exporting lua functions
257     foreach(cfile ${AWE_SRCS})
258         a_file_match(${cfile} "const struct luaL_reg" result)
259         if(result)
260             set(luadoc_c_srcs ${luadoc_c_srcs} ${cfile})
261         else()
262             a_file_match(${cfile} "luaA_.*_index" result)
263             if(result)
264                 set(luadoc_c_srcs ${luadoc_c_srcs} ${cfile})
265         endif()
266         endif()
267     endforeach()
269     # create fake lua source file to process by luadoc
270     add_custom_command(
271         COMMAND ${CAT_EXECUTABLE} ${luadoc_c_srcs}
272                 | ${LUA_EXECUTABLE} ${SOURCE_DIR}/build-utils/fake-lua-src.lua
273                 > ${capi_lua}
274         OUTPUT  ${capi_lua}
275         DEPENDS ${luadoc_c_srcs}
276         COMMENT "Generating fake lua source."
277         VERBATIM)
278     # }}}
280     # Generate documentation of lib//0lua
281     file(GLOB_RECURSE lua_lib_files ${BUILD_DIR}/lib/*.lua)
282     foreach(filename ${lua_lib_files})
283         file(RELATIVE_PATH filename ${BUILD_DIR}/lib ${filename})
284         set(luadoc_srcs ${luadoc_srcs} ${filename})
285     endforeach()
287     add_custom_target(luadoc ALL
288         COMMAND ${LUADOC_EXECUTABLE} ${luadoc_srcs} -d ${BUILD_DIR}/luadoc
289         WORKING_DIRECTORY ${BUILD_DIR}/lib
290         DEPENDS ${AWE_LUA_FILES} ${capi_lua})
291 endif()
292 # }}}
294 # {{{ Dist tarball
295 if(BUILD_FROM_GIT)
296     add_custom_target(dist
297         COMMAND ${SOURCE_DIR}/build-utils/dist.sh ${VERSION}
298         WORKING_DIRECTORY ${SOURCE_DIR})
299 endif()
300 # }}}
302 # {{{ Installation
303 install(TARGETS ${PROJECT_AWE_NAME} ${PROJECT_AWECLIENT_NAME} RUNTIME DESTINATION bin)
304 install(FILES "utils/awsetbg" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
305 install(DIRECTORY ${BUILD_DIR}/lib DESTINATION ${AWESOME_DATA_PATH})
306 install(FILES ${AWE_CONF_FILE_DEFAULT} DESTINATION ${AWESOME_SYSCONFDIR}
307         RENAME ${AWE_CONF_FILE})
308 if(GENERATE_MANPAGES)
309     install(FILES ${AWE_MAN1_FILES} DESTINATION ${AWESOME_MAN_PATH}/man1)
310     install(FILES ${AWE_MAN5_FILES} DESTINATION ${AWESOME_MAN_PATH}/man5)
311 endif()
312 install(DIRECTORY ${AWE_ICON_DIR} DESTINATION ${AWESOME_DATA_PATH})
313 install(DIRECTORY ${BUILD_DIR}/themes DESTINATION ${AWESOME_DATA_PATH})
314 install(DIRECTORY ${SOURCE_DIR}/themes DESTINATION ${AWESOME_DATA_PATH}
315     PATTERN "*.in" EXCLUDE)
316 install(FILES ${AWE_DOC_FILES} DESTINATION ${AWESOME_DOC_PATH})
317 install(FILES "awesome.desktop" DESTINATION ${AWESOME_XSESSION_PATH})
318 if(GENERATE_LUADOC)
319     install(DIRECTORY ${BUILD_DIR}/luadoc DESTINATION ${AWESOME_DOC_PATH})
320 endif()
321 # }}}
323 # vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80