1 set(PROJECT_AWE_NAME awesome)
3 # If ${SOURCE_DIR} is a git repository VERSION is set to
4 # `git describe` later.
9 project(${PROJECT_AWE_NAME} C)
11 set(CMAKE_BUILD_TYPE RELEASE)
13 option(WITH_DBUS "build with D-BUS" ON)
14 option(GENERATE_MANPAGES "generate manpages" ON)
15 option(COMPRESS_MANPAGES "compress manpages" ON)
16 option(GENERATE_LUADOC "generate luadoc" ON)
19 add_definitions(-std=gnu99 -ggdb3 -fno-strict-aliasing -Wall -Wextra
20 -Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings
21 -Wsign-compare -Wunused -Wno-unused-parameter -Wuninitialized -Winit-self
22 -Wpointer-arith -Wredundant-decls -Wformat-nonliteral
23 -Wno-format-zero-length -Wmissing-format-attribute -Wmissing-prototypes
28 include(TestBigEndian)
29 TEST_BIG_ENDIAN(AWESOME_IS_BIG_ENDIAN)
32 # {{{ Find external utilities
33 macro(a_find_program var prg req)
35 find_program(${var} ${prg})
37 message(STATUS "${prg} not found.")
39 message(FATAL_ERROR "${prg} is required to build awesome")
42 message(STATUS "${prg} -> ${${var}}")
46 a_find_program(CAT_EXECUTABLE cat TRUE)
47 a_find_program(LN_EXECUTABLE ln TRUE)
48 a_find_program(GREP_EXECUTABLE grep TRUE)
49 a_find_program(GIT_EXECUTABLE git FALSE)
50 a_find_program(HOSTNAME_EXECUTABLE hostname FALSE)
51 a_find_program(GPERF_EXECUTABLE gperf TRUE)
52 # programs needed for man pages
53 a_find_program(ASCIIDOC_EXECUTABLE asciidoc FALSE)
54 a_find_program(XMLTO_EXECUTABLE xmlto FALSE)
55 a_find_program(GZIP_EXECUTABLE gzip FALSE)
57 a_find_program(LUA_EXECUTABLE lua FALSE)
58 a_find_program(LUADOC_EXECUTABLE luadoc FALSE)
60 a_find_program(CONVERT_EXECUTABLE convert TRUE)
64 include(FindPkgConfig)
66 include(FindLua51) #Due to a cmake bug, you will see Lua50 on screen
69 # {{{ Check if documentation can be build
71 if(NOT ASCIIDOC_EXECUTABLE OR NOT XMLTO_EXECUTABLE OR (COMPRESS_MANPAGES AND NOT GZIP_EXECUTABLE))
72 if(NOT ASCIIDOC_EXECUTABLE)
73 SET(missing "asciidoc")
75 if(NOT XMLTO_EXECUTABLE)
76 SET(missing ${missing} " xmlto")
78 if(COMPRESS_MANPAGES AND NOT GZIP_EXECUTABLE)
79 SET(missing ${missing} " gzip")
82 message(STATUS "Not generating manpages. Missing: " ${missing})
83 set(GENERATE_MANPAGES OFF)
88 if(NOT LUADOC_EXECUTABLE)
89 message(STATUS "Not generating luadoc. Missing: luadoc")
90 set(GENERATE_LUADOC OFF)
96 if(EXISTS ${SOURCE_DIR}/.git/HEAD AND GIT_EXECUTABLE)
99 COMMAND ${GIT_EXECUTABLE} describe
100 WORKING_DIRECTORY ${SOURCE_DIR}
101 OUTPUT_VARIABLE VERSION
102 OUTPUT_STRIP_TRAILING_WHITESPACE)
103 # file the git-version-stamp.sh script will look into
104 set(VERSION_STAMP_FILE ${BUILD_DIR}/.version_stamp)
105 file(WRITE ${VERSION_STAMP_FILE} ${VERSION})
106 # create a version_stamp target later
107 set(BUILD_FROM_GIT TRUE)
108 elseif( EXISTS ${SOURCE_DIR}/.version_stamp )
109 # get version from version stamp
110 file(READ ${SOURCE_DIR}/.version_stamp VERSION)
116 COMMAND ${HOSTNAME_EXECUTABLE}
117 WORKING_DIRECTORY ${SOURCE_DIR}
118 OUTPUT_VARIABLE BUILDHOSTNAME
119 OUTPUT_STRIP_TRAILING_WHITESPACE)
122 # {{{ Required libraries
125 # AWESOME_REQUIRED_LDFLAGS
126 # AWESOME_REQUIRED_INCLUDE_DIRS
128 # Use pkgconfig to get most of the libraries
129 pkg_check_modules(AWESOME_COMMON_REQUIRED REQUIRED
132 pkg_check_modules(AWESOME_REQUIRED REQUIRED
148 libstartup-notification-1.0>=0.10
151 libxdg-basedir>=1.0.0)
153 if(NOT AWESOME_REQUIRED_FOUND OR NOT AWESOME_COMMON_REQUIRED_FOUND)
157 macro(a_find_library variable library)
158 find_library(${variable} ${library})
160 message(FATAL_ERROR ${library} " library not found.")
165 a_find_library(LIB_EV ev)
167 # Check for backtrace_symbols()
168 include(CheckFunctionExists)
169 check_function_exists(backtrace_symbols HAS_EXECINFO)
171 find_library(LIB_EXECINFO execinfo)
174 set(AWESOME_REQUIRED_LDFLAGS
175 ${AWESOME_REQUIRED_LDFLAGS}
180 message(STATUS "checking for execinfo -- found")
182 message(STATUS "checking for execinfo -- not found")
185 # __builtin_clz is available since gcc 3.4
186 try_compile(HAS___BUILTIN_CLZ
188 ${CMAKE_SOURCE_DIR}/build-tests/__builtin_clz.c)
189 if(HAS___BUILTIN_CLZ)
190 message(STATUS "checking for __builtin_clz -- yes")
192 message(STATUS "checking for __builtin_clz -- no")
196 if(NOT LUA51_FOUND AND NOT LUA50_FOUND) # This is a workaround to a cmake bug
197 message(FATAL_ERROR "lua library not found")
200 set(AWESOME_REQUIRED_LDFLAGS
201 ${AWESOME_COMMON_REQUIRED_LDFLAGS}
202 ${AWESOME_REQUIRED_LDFLAGS}
206 set(AWESOME_REQUIRED_INCLUDE_DIRS
207 ${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}
208 ${AWESOME_REQUIRED_INCLUDE_DIRS}
212 # {{{ Optional libraries
215 # AWESOME_OPTIONAL_LDFLAGS
216 # AWESOME_OPTIONAL_INCLUDE_DIRS
219 pkg_check_modules(DBUS dbus-1)
221 set(AWESOME_OPTIONAL_LDFLAGS ${AWESOME_OPTIONAL_LDFLAGS} ${DBUS_LDFLAGS})
222 set(AWESOME_OPTIONAL_INCLUDE_DIRS ${AWESOME_OPTIONAL_INCLUDE_DIRS} ${DBUS_INCLUDE_DIRS})
225 message(STATUS "DBUS not found. Disabled.")
230 # {{{ Install path and configuration variables
232 set(PREFIX ${PREFIX} CACHE PATH "install prefix")
233 set(CMAKE_INSTALL_PREFIX ${PREFIX})
235 set(PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "install prefix")
238 #If a sysconfdir is specified, use it instead
239 #of the default configuration dir.
240 if(DEFINED SYSCONFDIR)
241 set(SYSCONFDIR ${SYSCONFDIR} CACHE PATH "config directory")
243 set(SYSCONFDIR ${PREFIX}/etc CACHE PATH "config directory")
246 #If an XDG Config Dir is specificed, use it instead
247 #of the default XDG configuration dir.
248 if(DEFINED XDG_CONFIG_DIR)
249 set(XDG_CONFIG_DIR ${XDG_CONFIG_DIR} CACHE PATH "xdg config directory")
251 set(XDG_CONFIG_DIR ${SYSCONFDIR}/xdg CACHE PATH "xdg config directory")
254 # setting AWESOME_DOC_PATH
255 if(DEFINED AWESOME_DOC_PATH)
256 set(AWESOME_DOC_PATH ${AWESOME_DOC_PATH} CACHE PATH "awesome docs directory")
258 set(AWESOME_DOC_PATH ${PREFIX}/share/doc/${PROJECT_AWE_NAME} CACHE PATH "awesome docs directory")
261 # setting AWESOME_XSESSION_PATH
262 if(DEFINED AWESOME_XSESSION_PATH)
263 set(AWESOME_XSESSION_PATH ${AWESOME_XSESSION_PATH} CACHE PATH "awesome xsessions directory")
265 set(AWESOME_XSESSION_PATH ${PREFIX}/share/xsessions CACHE PATH "awesome xsessions directory")
269 if(DEFINED AWESOME_MAN_PATH)
270 set(AWESOME_MAN_PATH ${AWESOME_MAN_PATH} CACHE PATH "awesome manpage directory")
272 set(AWESOME_MAN_PATH ${PREFIX}/share/man CACHE PATH "awesome manpage directory")
275 # Hide to avoid confusion
276 mark_as_advanced(CMAKE_INSTALL_PREFIX)
278 set(AWESOME_VERSION ${VERSION})
279 set(AWESOME_COMPILE_MACHINE ${CMAKE_SYSTEM_PROCESSOR})
280 set(AWESOME_COMPILE_HOSTNAME ${BUILDHOSTNAME})
281 set(AWESOME_COMPILE_BY $ENV{USER})
282 set(AWESOME_RELEASE ${CODENAME})
283 set(AWESOME_SYSCONFDIR ${XDG_CONFIG_DIR}/${PROJECT_AWE_NAME})
284 set(AWESOME_DATA_PATH ${PREFIX}/share/${PROJECT_AWE_NAME})
285 set(AWESOME_LUA_LIB_PATH ${AWESOME_DATA_PATH}/lib)
286 set(AWESOME_ICON_PATH ${AWESOME_DATA_PATH}/icons)
287 set(AWESOME_THEMES_PATH ${AWESOME_DATA_PATH}/themes)
290 # {{{ Configure files
291 file(GLOB_RECURSE awesome_lua_configure_files RELATIVE ${SOURCE_DIR} ${SOURCE_DIR}/lib/*.lua.in ${SOURCE_DIR}/themes/*/*.lua.in)
292 set(AWESOME_CONFIGURE_FILES
293 ${awesome_lua_configure_files}
296 awesome-version-internal.h.in
299 macro(a_configure_file file)
300 string(REGEX REPLACE ".in\$" "" outfile ${file})
301 message(STATUS "Configuring ${outfile}")
302 configure_file(${SOURCE_DIR}/${file}
303 ${BUILD_DIR}/${outfile}
308 foreach(file ${AWESOME_CONFIGURE_FILES})
309 a_configure_file(${file})
313 # vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80