Don't strip RPATH on Solaris (FS#744)
[awesome.git] / CMakeLists.txt
blobaa09f48e7058c4785cb6a3943f668e7b50d5b732
1 cmake_minimum_required(VERSION 2.8.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     ${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}
21     ${AWESOME_REQUIRED_INCLUDE_DIRS}
22     ${AWESOME_OPTIONAL_INCLUDE_DIRS})
24 file(GLOB_RECURSE AWE_LUA_FILES ${BUILD_DIR}/lib/*.lua ${BUILD_DIR}/luadoc/*.lua)
26 set(AWE_CONF_FILE_DEFAULT ${BUILD_DIR}/awesomerc.lua)
27 set(AWE_CONF_FILE rc.lua)
29 set(AWE_ICON_DIR ${SOURCE_DIR}/icons)
30 set(AWE_THEMES_DIR ${SOURCE_DIR}/themes)
32 set(AWE_DOC_FILES
33     ${SOURCE_DIR}/AUTHORS
34     ${SOURCE_DIR}/BUGS
35     ${SOURCE_DIR}/README
36     ${SOURCE_DIR}/LICENSE)
38 set(AWE_SRCS
39     ${SOURCE_DIR}/awesome.c
40     ${SOURCE_DIR}/banning.c
41     ${SOURCE_DIR}/color.c
42     ${SOURCE_DIR}/dbus.c
43     ${SOURCE_DIR}/draw.c
44     ${SOURCE_DIR}/event.c
45     ${SOURCE_DIR}/ewmh.c
46     ${SOURCE_DIR}/keygrabber.c
47     ${SOURCE_DIR}/keyresolv.c
48     ${SOURCE_DIR}/luaa.c
49     ${SOURCE_DIR}/mouse.c
50     ${SOURCE_DIR}/mousegrabber.c
51     ${SOURCE_DIR}/property.c
52     ${SOURCE_DIR}/root.c
53     ${SOURCE_DIR}/screen.c
54     ${SOURCE_DIR}/selection.c
55     ${SOURCE_DIR}/spawn.c
56     ${SOURCE_DIR}/stack.c
57     ${SOURCE_DIR}/strut.c
58     ${SOURCE_DIR}/systray.c
59     ${SOURCE_DIR}/xwindow.c
60     ${SOURCE_DIR}/common/atoms.c
61     ${SOURCE_DIR}/common/backtrace.c
62     ${SOURCE_DIR}/common/buffer.c
63     ${SOURCE_DIR}/common/luaclass.c
64     ${SOURCE_DIR}/common/lualib.c
65     ${SOURCE_DIR}/common/luaobject.c
66     ${SOURCE_DIR}/common/util.c
67     ${SOURCE_DIR}/common/version.c
68     ${SOURCE_DIR}/common/xcursor.c
69     ${SOURCE_DIR}/common/xembed.c
70     ${SOURCE_DIR}/common/xutil.c
71     ${SOURCE_DIR}/objects/button.c
72     ${SOURCE_DIR}/objects/client.c
73     ${SOURCE_DIR}/objects/drawin.c
74     ${SOURCE_DIR}/objects/key.c
75     ${SOURCE_DIR}/objects/tag.c
76     ${SOURCE_DIR}/objects/timer.c
77     ${SOURCE_DIR}/objects/window.c)
79 set(AWE_MAN_SRCS
80     ${SOURCE_DIR}/manpages/awesome.1.txt
81     ${SOURCE_DIR}/manpages/awesome-client.1.txt
82     ${SOURCE_DIR}/manpages/awesomerc.5.txt)
83 set(AWE_MAN_LANGS it es fr de ru)
85 # Don't strip RPATH if compiling on Solaris
86 if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
87     set(CMAKE_SKIP_BUILD_RPATH FALSE)
88     set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
89     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
90 endif()
92 add_executable(${PROJECT_AWE_NAME}
93     ${AWE_SRCS})
95 set_target_properties(${PROJECT_AWE_NAME}
96     PROPERTIES
97     LINK_FLAGS -export-dynamic)
99 target_link_libraries(${PROJECT_AWE_NAME}
100     ${AWESOME_COMMON_REQUIRED_LDFLAGS}
101     ${AWESOME_REQUIRED_LDFLAGS}
102     ${AWESOME_OPTIONAL_LDFLAGS})
104 # atoms
105 file(MAKE_DIRECTORY ${BUILD_DIR}/common)
106 add_custom_command(
107     COMMAND ${SOURCE_DIR}/build-utils/atoms-ext.sh ${SOURCE_DIR}/common/atoms.list
108     ARGS    > ${BUILD_DIR}/common/atoms-extern.h
109     OUTPUT  ${BUILD_DIR}/common/atoms-extern.h
110     WORKING_DIRECTORY ${SOURCE_DIR}
111     DEPENDS ${SOURCE_DIR}/common/atoms.list
112     COMMENT "Generating atoms-extern.h"
113     VERBATIM)
115 add_custom_command(
116     COMMAND ${SOURCE_DIR}/build-utils/atoms-int.sh ${SOURCE_DIR}/common/atoms.list
117     ARGS    > ${BUILD_DIR}/common/atoms-intern.h
118     OUTPUT  ${BUILD_DIR}/common/atoms-intern.h
119     WORKING_DIRECTORY ${SOURCE_DIR}
120     DEPENDS ${SOURCE_DIR}/common/atoms.list
121     COMMENT "Generating atoms-intern.h"
122     VERBATIM)
124 add_custom_target(generated_sources
125     DEPENDS ${BUILD_DIR}/common/atoms-intern.h
126             ${BUILD_DIR}/common/atoms-extern.h)
128 # Default theme directory
129 file(MAKE_DIRECTORY ${BUILD_DIR}/themes/default)
130 file(MAKE_DIRECTORY ${BUILD_DIR}/themes/sky)
131 file(MAKE_DIRECTORY ${BUILD_DIR}/themes/zenburn)
132 add_dependencies(${PROJECT_AWE_NAME} generated_sources)
133 # }}}
135 # {{{ Version stamp
136 if(BUILD_FROM_GIT)
137     add_custom_target(version_stamp ALL
138         COMMAND ${SOURCE_DIR}/build-utils/git-version-stamp.sh
139                 ${VERSION_STAMP_FILE}
140                 ${BUILD_DIR}/awesome-version-internal.h
141         WORKING_DIRECTORY ${SOURCE_DIR})
143     add_dependencies(${PROJECT_AWE_NAME} version_stamp)
144 endif()
145 # }}}
147 # {{{ Manpages
148 if(GENERATE_MANPAGES)
149     if(NOT BUILD_DIR STREQUAL SOURCE_DIR)
150         file(MAKE_DIRECTORY ${BUILD_DIR}/manpages)
151     endif()
153     # add the default translation to the list of languages
154     set(AWE_MAN_LANGS default ${AWE_MAN_LANGS})
156     foreach(lang ${AWE_MAN_LANGS})
158         foreach(txtfile ${AWE_MAN_SRCS})
159             # figure the base name of the file (ie "awesome.1")
160             GET_FILENAME_COMPONENT(tmpname ${txtfile} NAME)
161             string(REGEX REPLACE ".txt\$" "" basename ${tmpname})
163             # figure the relative path of the file
164             GET_FILENAME_COMPONENT(tmppath ${txtfile} PATH)
165             string(REPLACE ${SOURCE_DIR}/ "" relpath ${tmppath})
167             # figure the manpage section to install to from filename
168             string(REGEX REPLACE "^.*\\.([0-9])$" "\\1" section ${basename})
170             # construct the language specific versions of the basename and path
171             if (lang STREQUAL default)
172                 set(basename2 ${basename})
173                 set(relpath2 ${relpath}/man${section})
174             else()
175                 set(basename2 ${basename}.${lang})
176                 set(relpath2 ${relpath}/${lang}/man${section})
177             endif()
179             # create the build directory (if it does not exist)
180             file(MAKE_DIRECTORY ${BUILD_DIR}/${relpath2})
182             # set the final filenames
183             set(txtfile ${SOURCE_DIR}/${relpath}/${basename2}.txt)
184             set(xmlfile ${BUILD_DIR}/${relpath2}/${basename}.xml)
185             set(gzfile  ${BUILD_DIR}/${relpath2}/${basename}.gz)
186             set(manfile ${BUILD_DIR}/${relpath2}/${basename})
188             add_custom_command(
189                 COMMAND ${ASCIIDOC_EXECUTABLE} -d manpage -b docbook -o ${xmlfile} - < ${txtfile}
190                 WORKING_DIRECTORY ${BUILD_DIR}/${relpath2}
191                 OUTPUT  ${xmlfile}
192                 DEPENDS ${txtfile}
193                 VERBATIM)
194             add_custom_command(
195                 COMMAND ${XMLTO_EXECUTABLE} man ${xmlfile}
196                 OUTPUT  ${manfile}
197                 WORKING_DIRECTORY ${BUILD_DIR}/${relpath2}
198                 DEPENDS ${xmlfile})
200             if(COMPRESS_MANPAGES)
201                 add_custom_command(
202                     COMMAND ${GZIP_EXECUTABLE} < ${manfile} > ${gzfile}
203                     OUTPUT  ${gzfile}
204                     WORKING_DIRECTORY ${BUILD_DIR}/${relpath2}
205                     DEPENDS ${manfile}
206                     VERBATIM)
208                 set(MAN_FILES ${MAN_FILES} ${gzfile})
209             else()
210                 set(MAN_FILES ${MAN_FILES} ${manfile})
211             endif()
212         endforeach()
214     endforeach()
216     add_custom_target(man ALL DEPENDS ${MAN_FILES})
217 endif()
218 # }}}
220 # {{{ Doxygen
221 if(DOXYGEN_EXECUTABLE)
222     add_custom_target(doc
223         COMMAND ${DOXYGEN_EXECUTABLE} awesome.doxygen
224         WORKING_DIRECTORY ${BUILD_DIR})
225 endif()
226 # }}}
228 # {{{ Lua API Documentation
229 if(GENERATE_LUADOC)
231     if(NOT BUILD_DIR STREQUAL SOURCE_DIR)
232         file(MAKE_DIRECTORY ${BUILD_DIR}/lib)
233     endif()
235     set(luadoc_c_srcs "")
237     # Generate documentation of lib//0lua
238     file(GLOB_RECURSE lua_lib_files ${BUILD_DIR}/lib/*.lua
239         ${SOURCE_DIR}/luadoc/*.lua)
240     foreach(filename ${lua_lib_files})
241         file(RELATIVE_PATH filename ${BUILD_DIR} ${filename})
242         set(luadoc_srcs ${luadoc_srcs} ${filename})
243     endforeach()
245     add_custom_target(luadoc ALL
246         COMMAND ${LUADOC_EXECUTABLE} ${luadoc_srcs} -d ${BUILD_DIR}/luadoc --nofiles
247         WORKING_DIRECTORY ${BUILD_DIR}
248         DEPENDS ${AWE_LUA_FILES})
249 endif()
250 # }}}
252 # {{{ Theme icons
253 file(GLOB icon_sources RELATIVE ${SOURCE_DIR} ${SOURCE_DIR}/themes/*/titlebar/*.png)
255 foreach(icon ${icon_sources})
256     # Copy all icons to the build dir to simplify the following code.
257     # Source paths are interpreted relative to ${SOURCE_DIR}, target paths
258     # relative to ${BUILD_DIR}.
259     get_filename_component(icon_path ${icon} PATH)
260     get_filename_component(icon_name ${icon} NAME)
261     file(COPY ${icon} DESTINATION ${icon_path})
262     set(ALL_ICONS ${ALL_ICONS} "${icon_path}/${icon_name}")
263 endforeach()
265 macro(a_icon_convert match replacement input)
266     string(REPLACE ${match} ${replacement} output ${input})
268     if(NOT ${input} STREQUAL ${output})
269         set(ALL_ICONS ${ALL_ICONS} ${output})
271         add_custom_command(
272             COMMAND ${CONVERT_EXECUTABLE} ${input} ${ARGN} ${output}
273             OUTPUT  ${output}
274             DEPENDS ${input}
275             VERBATIM)
276     endif()
277 endmacro()
279 foreach(icon ${ALL_ICONS})
280     # Make unfocused icons translucent
281     a_icon_convert("_focus" "_normal" ${icon}
282         -gamma 0.6 -channel A -evaluate Multiply 0.4)
283 endforeach()
285 foreach(icon ${ALL_ICONS})
286     # Make inactive icons grayscale
287     a_icon_convert("_active" "_inactive" ${icon}
288         -colorspace Gray)
289 endforeach()
291 add_custom_target(generated_icons ALL DEPENDS ${ALL_ICONS})
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} RUNTIME DESTINATION bin)
304 install(FILES "utils/awesome-client" 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     PATTERN "*.in" EXCLUDE)
307 install(FILES ${AWE_CONF_FILE_DEFAULT} DESTINATION ${AWESOME_SYSCONFDIR}
308         RENAME ${AWE_CONF_FILE})
309 if(GENERATE_MANPAGES)
310     if(COMPRESS_MANPAGES)
311         set(regex "\\.(xml|txt|[0-9])$")
312     else()
313         set(regex "\\.(xml|txt|gz)$")
314     endif()
315     install(DIRECTORY ${BUILD_DIR}/${relpath}/ DESTINATION ${AWESOME_MAN_PATH}
316             REGEX ${regex} EXCLUDE )
317 endif()
318 install(DIRECTORY ${AWE_ICON_DIR} DESTINATION ${AWESOME_DATA_PATH})
319 install(DIRECTORY ${BUILD_DIR}/themes DESTINATION ${AWESOME_DATA_PATH}
320     PATTERN "*.in" EXCLUDE)
321 install(DIRECTORY ${SOURCE_DIR}/themes DESTINATION ${AWESOME_DATA_PATH}
322     PATTERN "*.in" EXCLUDE)
323 install(FILES ${AWE_DOC_FILES} DESTINATION ${AWESOME_DOC_PATH})
324 install(FILES "awesome.desktop" DESTINATION ${AWESOME_XSESSION_PATH})
325 if(GENERATE_LUADOC)
326     install(DIRECTORY ${BUILD_DIR}/luadoc DESTINATION ${AWESOME_DOC_PATH})
327 endif()
328 # }}}
330 # vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80