annotated CMakeFile

此文档中提到的cmake file针对的是awesome-3.1-rc2中的CMakeLists.txtawesomeConfig.cmake,后者是一个cmake模块,awesome的源代码结构是in-place build

 

awesomeConfig.cmake

//设置变量

set(PROJECT_AWE_NAME awesome)

set(PROJECT_AWECLIENT_NAME awesome-client)

 

# If ${SOURCE_DIR} is a git repository VERSION is set to

# `git describe` later.

set(VERSION devel)

 

set(CODENAME "When She Believes")

 

//设置工程名,并说明本工程由C语言编写

project(${PROJECT_AWE_NAME} C)

 

//编译的版本是RELEASECMAKE_BUILD_TYPEcmake定义的变量

set(CMAKE_BUILD_TYPE RELEASE)

 

// 在后面调用FindCurses 前需将CURSES_NEED_NCURSES设为true

set(CURSES_NEED_NCURSES true)

 

//设定编译选项

option(WITH_DBUS "build with D-BUS" ON)

option(GENERATE_MANPAGES "generate manpages" ON)

option(GENERATE_LUADOC "generate luadoc" ON)

 

//设定linker寻找lib的目录

link_directories(/usr/local/lib)

 

//设定preprocess defination

# {{{ CFLAGS

add_definitions(-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 -Wredundant-decls -Wformat-nonliteral

    -Wno-format-zero-length -Wmissing-format-attribute -Wmissing-prototypes

    -Wstrict-prototypes)

# }}}

 

 

//定义一个宏,寻找程序prg,如果找到就设定var,否则为NotFoundreq表明程序是否为required

# {{{ Find external utilities

macro(a_find_program var prg req)

    set(required ${req})

    find_program(${var} ${prg})

    if(NOT ${var})

        message(STATUS "${prg} not found.")

        if(required)

            message(FATAL_ERROR "${prg} is required to build awesome")

        endif()

else()

       //${var}的值为CAT_EXECUTABLE,而${ CAT_EXECUTABLE }的值为/bin/cat?

        message(STATUS "${prg} -> ${${var}}")

    endif()

endmacro()

 

a_find_program(CAT_EXECUTABLE cat TRUE)

a_find_program(LN_EXECUTABLE ln TRUE)

a_find_program(GREP_EXECUTABLE grep TRUE)

a_find_program(GIT_EXECUTABLE git FALSE)

a_find_program(HOSTNAME_EXECUTABLE hostname FALSE)

a_find_program(GPERF_EXECUTABLE gperf TRUE)

# programs needed for man pages

a_find_program(ASCIIDOC_EXECUTABLE asciidoc FALSE)

a_find_program(XMLTO_EXECUTABLE xmlto FALSE)

a_find_program(GZIP_EXECUTABLE gzip FALSE)

# lua documentation

a_find_program(LUA_EXECUTABLE lua FALSE)

a_find_program(LUADOC_EXECUTABLE luadoc FALSE)

 

//cmake定义的模块

# doxygen

include(FindDoxygen)

# pkg-config

include(FindPkgConfig)

# ncurses

include(FindCurses)

# lua 5.1

include(FindLua51) #Due to a cmake bug, you will see Lua50 on screen

# }}}

 

# {{{ Check if documentation can be build

if(GENERATE_MANPAGES)//option中定义的变量

    if(NOT ASCIIDOC_EXECUTABLE OR NOT XMLTO_EXECUTABLE OR NOT GZIP_EXECUTABLE)

        if(NOT ASCIIDOC_EXECUTABLE)

            SET(missing "asciidoc")

        endif()

        if(NOT XMLTO_EXECUTABLE)

            SET(missing ${missing} " xmlto")

        endif()

        if(NOT GZIP_EXECUTABLE)

            SET(missing ${missing} " gzip")

        endif()

 

        message(STATUS "Not generating manpages. Missing: " ${missing})

        set(GENERATE_MANPAGES OFF)

    endif()

endif()

 

if(GENERATE_LUADOC)

    if(NOT LUADOC_EXECUTABLE)

        message(STATUS "Not generating luadoc. Missing: luadoc")

        set(GENERATE_LUADOC OFF)

    endif()

endif()

# }}}

 

# {{{ Version stamp

if(EXISTS ${SOURCE_DIR}/.git/HEAD AND GIT_EXECUTABLE)

# get current version

//执行外部程序

    execute_process(

        COMMAND ${GIT_EXECUTABLE} describe

        WORKING_DIRECTORY ${SOURCE_DIR}

        OUTPUT_VARIABLE VERSION

        OUTPUT_STRIP_TRAILING_WHITESPACE)

    # file the git-version-stamp.sh script will look into

set(VERSION_STAMP_FILE ${BUILD_DIR}/.version_stamp)

//写文件

    file(WRITE ${VERSION_STAMP_FILE} ${VERSION})

    # create a version_stamp target later

    set(BUILD_FROM_GIT TRUE)

elseif( EXISTS ${SOURCE_DIR}/.version_stamp )

    # get version from version stamp

    file(READ ${SOURCE_DIR}/.version_stamp VERSION)

endif()

# }}}

 

# {{{ Get hostname

execute_process(

    COMMAND ${HOSTNAME_EXECUTABLE}

    WORKING_DIRECTORY ${SOURCE_DIR}

    OUTPUT_VARIABLE BUILDHOSTNAME

    OUTPUT_STRIP_TRAILING_WHITESPACE)

# }}}

 

# {{{ Required libraries

#

# this sets up:

# AWESOME_REQUIRED_LIBRARIES

# AWESOME_REQUIRED_INCLUDE_DIRS

# AWESOMECLIENT_LIBRARIES

 

# Use pkgconfig to get most of the libraries

//由模块FindPkgConfig定义的方法,并派生出下面的AWESOME_COMMON_REQUIRED_FOUNDAWESOME_COMMON_REQUIRED_LIBRARIESAWESOME_COMMON_REQUIRED_INCLUDE_DIRS

pkg_check_modules(AWESOME_COMMON_REQUIRED REQUIRED

    xcb>=1.1)

 

//由模块FindPkgConfig定义的方法,并派生出下面的AWESOME_REQUIRED_FOUNDAWESOME _REQUIRED_LIBRARIESAWESOME _REQUIRED_INCLUDE_DIRS

pkg_check_modules(AWESOME_REQUIRED REQUIRED

    glib-2.0

    cairo

    pango

    pangocairo

    x11-xcb

    xcb-randr

    xcb-xinerama

    xcb-event>=0.3.0

    xcb-aux>=0.3.0

    xcb-atom>=0.3.0

    xcb-keysyms>=0.3.0

    xcb-icccm>=0.3.0

    cairo-xcb

    xproto>=7.0.11

    imlib2)

 

if(NOT AWESOME_REQUIRED_FOUND OR NOT AWESOME_COMMON_REQUIRED_FOUND)

    message(FATAL_ERROR)

endif()

 

//找库的宏,找到就设定variable

macro(a_find_library variable library)

    find_library(${variable} ${library})

    if(NOT ${variable})

        message(FATAL_ERROR ${library} " library not found.")

    endif()

endmacro()

 

# Check for readline, ncurse and libev

a_find_library(LIB_READLINE readline)

a_find_library(LIB_EV ev)

 

# Error check

set( LUA_FOUND LUA51_FOUND OR LUA50_FOUND )# This is a workaround to a cmake bug

if(NOT LUA_FOUND)

    message(FATAL_ERROR "lua library not found")

endif()

 

set(AWESOME_REQUIRED_LIBRARIES

    ${AWESOME_COMMON_REQUIRED_LIBRARIES}

    ${AWESOME_REQUIRED_LIBRARIES}

    ${LIB_EV}

    ${LUA_LIBRARIES})

 

set(AWESOME_REQUIRED_INCLUDE_DIRS

    ${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}

    ${AWESOME_REQUIRED_INCLUDE_DIRS}

    ${LUA_INCLUDE_DIR})

 

set(AWESOMECLIENT_LIBRARIES

    ${AWESOME_COMMON_REQUIRED_LIBRARIES}

    ${LIB_READLINE}

    ${LIB_XCB}

    ${CURSES_LIBRARIES})

 

set(AWESOMECLIENT_REQUIRED_INCLUDE_DIRS

    ${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS})

# }}}

 

# {{{ Optional libraries

#

# this sets up:

# AWESOME_OPTIONAL_LIBRARIES

# AWESOME_OPTIONAL_INCLUDE_DIRS

 

if(WITH_DBUS)

    pkg_check_modules(DBUS dbus-1)

    if(DBUS_FOUND)

        set(AWESOME_OPTIONAL_LIBRARIES ${AWESOME_OPTIONAL_LIBRARIES} ${DBUS_LIBRARIES})

        set(AWESOME_OPTIONAL_INCLUDE_DIRS ${AWESOME_OPTIONAL_INCLUDE_DIRS} ${DBUS_INCLUDE_DIRS})

    else()

        set(WITH_DBUS OFF)

        message(STATUS "DBUS not found. Disabled.")

    endif()

endif()

# }}}

 

//编译配置选项

# {{{ Install path and configuration variables

if(DEFINED PREFIX)

    set(PREFIX ${PREFIX} CACHE PATH "install prefix")

    set(CMAKE_INSTALL_PREFIX ${PREFIX})

else()

    set(PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "install prefix")

endif()

 

#If a sysconfdir is specified, use it instead

#of the default configuration dir.

if(DEFINED SYSCONFDIR)

    set(SYSCONFDIR ${SYSCONFDIR} CACHE PATH "config directory")

else()

    set(SYSCONFDIR /etc CACHE PATH "config directory")

endif()

 

#If an XDG Config Dir is specificed, use it instead

#of the default XDG configuration dir.

if(DEFINED XDG_CONFIG_DIR)

    set(XDG_CONFIG_DIR ${XDG_CONFIG_SYS} CACHE PATH "xdg config directory")

else()

    set(XDG_CONFIG_DIR ${SYSCONFDIR}/xdg CACHE PATH "xdg config directory")

endif()

 

# setting AWESOME_DOC_PATH

if(DEFINED AWESOME_DOC_PATH)

    set(AWESOME_DOC_PATH ${AWESOME_DOC_PATH} CACHE PATH "awesome docs directory")

else()

    set(AWESOME_DOC_PATH ${PREFIX}/share/doc/${PROJECT_AWE_NAME} CACHE PATH "awesome docs directory")

endif()

 

# setting AWESOME_XSESSION_PATH

if(DEFINED AWESOME_XSESSION_PATH)

    set(AWESOME_XSESSION_PATH ${AWESOME_XSESSION_PATH} CACHE PATH "awesome xsessions directory")

else()

    set(AWESOME_XSESSION_PATH ${PREFIX}/share/xsessions CACHE PATH "awesome xsessions directory")

endif()

 

# set man path

if(DEFINED AWESOME_MAN_PATH)

   set(AWESOME_MAN_PATH ${AWESOME_MAN_PATH} CACHE PATH "awesome manpage directory")

else()

   set(AWESOME_MAN_PATH ${PREFIX}/share/man CACHE PATH "awesome manpage directory")

endif()

 

# Hide to avoid confusion

mark_as_advanced(CMAKE_INSTALL_PREFIX)

 

set(AWESOME_VERSION          ${VERSION})

set(AWESOME_COMPILE_MACHINE  ${CMAKE_SYSTEM_PROCESSOR})

set(AWESOME_COMPILE_HOSTNAME ${BUILDHOSTNAME})

set(AWESOME_COMPILE_BY       $ENV{USER})

set(AWESOME_RELEASE          ${CODENAME})

set(AWESOME_SYSCONFDIR       ${XDG_CONFIG_DIR}/${PROJECT_AWE_NAME})

set(AWESOME_DATA_PATH        ${PREFIX}/share/${PROJECT_AWE_NAME})

set(AWESOME_LUA_LIB_PATH     ${AWESOME_DATA_PATH}/lib)

set(AWESOME_ICON_PATH        ${AWESOME_DATA_PATH}/icons)

set(AWESOME_THEMES_PATH      ${AWESOME_DATA_PATH}/themes)

# }}}

 

# {{{ Configure files

file(GLOB_RECURSE awesome_lua_configure_files RELATIVE ${SOURCE_DIR} ${SOURCE_DIR}/lib/*.lua.in)

set(AWESOME_CONFIGURE_FILES

    ${awesome_lua_configure_files}

    config.h.in

    awesomerc.lua.in

    themes/default/theme.in

    themes/sky/theme.in

    awesome-version-internal.h.in

    awesome.doxygen.in)

 

macro(a_configure_file file)

    string(REGEX REPLACE ".in/$" "" outfile ${file})

    message(STATUS "Configuring ${outfile}")

    configure_file(${SOURCE_DIR}/${file}

                   ${BUILD_DIR}/${outfile}

                   ESCAPE_QUOTE

                   @ONLY)

endmacro()

 

foreach(file ${AWESOME_CONFIGURE_FILES})

    a_configure_file(${file})

endforeach()

#}}}

 

 

CMakeLists.txt

cmake_minimum_required(VERSION 2.6.0)

set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS  TRUE)

 

if(COMMAND cmake_policy)//如果存在命令cmake_policy

    cmake_policy(VERSION 2.6)//使用CMake2.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()

 

//包含并执行awesomeConfig.cmake

include(awesomeConfig.cmake)

 

//将下列目录加入到Include目录中

include_directories(

    ${SOURCE_DIR}

    ${BUILD_DIR}

    ${BUILD_DIR}/common

    ${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}

    ${AWESOME_REQUIRED_INCLUDE_DIRS}

    ${AWESOME_OPTIONAL_INCLUDE_DIRS})

 

//设置AWE_LUA_FILES*.lua文件列表

file(GLOB_RECURSE AWE_LUA_FILES ${BUILD_DIR}/lib/*.lua)

 

//设置变量

set(AWE_CONF_FILE_DEFAULT ${BUILD_DIR}/awesomerc.lua)

set(AWE_CONF_FILE rc.lua)

 

set(AWE_ICON_DIR ${SOURCE_DIR}/icons)

set(AWE_THEMES_DIR ${SOURCE_DIR}/themes)

 

set(AWE_DOC_FILES

    ${SOURCE_DIR}/AUTHORS

    ${SOURCE_DIR}/BUGS

    ${SOURCE_DIR}/README

    ${SOURCE_DIR}/LICENSE)

 

set(AWE_SRCS

    ${SOURCE_DIR}/awesome.c

    ${SOURCE_DIR}/client.c

    ${SOURCE_DIR}/cnode.c

    ${SOURCE_DIR}/dbus.c

    ${SOURCE_DIR}/event.c

    ${SOURCE_DIR}/property.c

    ${SOURCE_DIR}/ewmh.c

    ${SOURCE_DIR}/keybinding.c

    ${SOURCE_DIR}/keygrabber.c

    ${SOURCE_DIR}/layout.c

    ${SOURCE_DIR}/luaa.c

    ${SOURCE_DIR}/hooks.c

    ${SOURCE_DIR}/mouse.c

    ${SOURCE_DIR}/screen.c

    ${SOURCE_DIR}/stack.c

    ${SOURCE_DIR}/statusbar.c

    ${SOURCE_DIR}/wibox.c

    ${SOURCE_DIR}/systray.c

    ${SOURCE_DIR}/tag.c

    ${SOURCE_DIR}/titlebar.c

    ${SOURCE_DIR}/widget.c

    ${SOURCE_DIR}/window.c

    ${SOURCE_DIR}/image.c

    ${SOURCE_DIR}/draw.c

    ${SOURCE_DIR}/swindow.c

    ${SOURCE_DIR}/common/buffer.c

    ${SOURCE_DIR}/common/atoms.c

    ${SOURCE_DIR}/common/markup.c

    ${SOURCE_DIR}/common/socket.c

    ${SOURCE_DIR}/common/util.c

    ${SOURCE_DIR}/common/version.c

    ${SOURCE_DIR}/common/xembed.c

    ${SOURCE_DIR}/common/xutil.c

    ${SOURCE_DIR}/layouts/fibonacci.c

    ${SOURCE_DIR}/layouts/floating.c

    ${SOURCE_DIR}/layouts/magnifier.c

    ${SOURCE_DIR}/layouts/fair.c

    ${SOURCE_DIR}/layouts/max.c

    ${SOURCE_DIR}/layouts/tile.c

    ${SOURCE_DIR}/widgets/graph.c

    ${SOURCE_DIR}/widgets/progressbar.c

    ${SOURCE_DIR}/widgets/textbox.c

    ${SOURCE_DIR}/widgets/systray.c

    ${SOURCE_DIR}/widgets/imagebox.c)

 

set(AWE_CLIENT_SRCS

    ${SOURCE_DIR}/awesome-client.c

    ${SOURCE_DIR}/common/socket.c

    ${SOURCE_DIR}/common/util.c

    ${SOURCE_DIR}/common/version.c)

 

set(AWE_MAN_SRCS

    ${SOURCE_DIR}/awesome.1.txt

    ${SOURCE_DIR}/awesome-client.1.txt

    ${SOURCE_DIR}/awesomerc.5.txt)

 

//用后面的源文件编译一个可执行文件${PROJECT_AWE_NAME}

add_executable(${PROJECT_AWE_NAME}

    ${AWE_SRCS}

    ${BUILD_DIR}/common/tokenize.c)

 

add_executable(${PROJECT_AWECLIENT_NAME}

    ${AWE_CLIENT_SRCS}

    ${BUILD_DIR}/common/tokenize.c)

 

//设置${PROJECT_AWE_NAME}LINK_FLAGS属性

set_target_properties(${PROJECT_AWE_NAME}

    PROPERTIES

    LINK_FLAGS -export-dynamic)

 

//添加link时的库文件

target_link_libraries(${PROJECT_AWE_NAME}

    ${AWESOME_COMMON_REQUIRED_LIBRARIES}

    ${AWESOME_REQUIRED_LIBRARIES}

    ${AWESOME_OPTIONAL_LIBRARIES})

 

target_link_libraries(${PROJECT_AWECLIENT_NAME}

    ${AWESOME_COMMON_REQUIRED_LIBRARIES}

    ${AWESOMECLIENT_LIBRARIES})

 

# {{{ Generated sources

file(GLOB LAYOUTGEN_DEPS ${SOURCE_DIR}/layouts/*.h)

 

//自定义命令,实际就是layoutgen.sh,并说明一些脚本运行的环境

add_custom_command(

    COMMAND ${SOURCE_DIR}/build-utils/layoutgen.sh

    ARGS    > ${BUILD_DIR}/layoutgen.h

    OUTPUT  ${BUILD_DIR}/layoutgen.h

    WORKING_DIRECTORY ${SOURCE_DIR}

    DEPENDS ${LAYOUTGEN_DEPS}

    COMMENT "Generating layoutgen.h"

    VERBATIM)

 

add_custom_command(

    COMMAND ${SOURCE_DIR}/build-utils/widgetgen.sh

    ARGS    > ${BUILD_DIR}/widgetgen.h

    OUTPUT  ${BUILD_DIR}/widgetgen.h

    WORKING_DIRECTORY ${SOURCE_DIR}

    DEPENDS ${SOURCE_DIR}/widget.h

    COMMENT "Generating widgetgen.h"

    VERBATIM)

 

# 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)

 

# gperf

add_custom_command(

    COMMAND ${SOURCE_DIR}/build-utils/gperf.sh

    ARGS    ${SOURCE_DIR}/common/tokenize.gperf

            ${BUILD_DIR}/common/tokenize.h

    OUTPUT  ${BUILD_DIR}/common/tokenize.h

    DEPENDS ${SOURCE_DIR}/common/tokenize.gperf

            ${SOURCE_DIR}/build-utils/gperf.sh

    COMMENT "Generating common/tokenize.h")

 

add_custom_command(

    COMMAND ${SOURCE_DIR}/build-utils/gperf.sh

    ARGS    ${SOURCE_DIR}/common/tokenize.gperf

            ${BUILD_DIR}/common/tokenize.c

    OUTPUT  ${BUILD_DIR}/common/tokenize.c

    DEPENDS ${SOURCE_DIR}/common/tokenize.gperf

            ${SOURCE_DIR}/build-utils/gperf.sh

    COMMENT "Generating common/tokenize.c")

 

add_custom_target(generated_sources

    DEPENDS ${BUILD_DIR}/widgetgen.h

            ${BUILD_DIR}/layoutgen.h

            ${BUILD_DIR}/common/atoms-intern.h

            ${BUILD_DIR}/common/atoms-extern.h

            ${BUILD_DIR}/common/tokenize.c

            ${BUILD_DIR}/common/tokenize.h)

 

# Default theme directory

file(MAKE_DIRECTORY ${BUILD_DIR}/themes/default)

file(MAKE_DIRECTORY ${BUILD_DIR}/themes/sky)

add_dependencies(${PROJECT_AWE_NAME} generated_sources)

add_dependencies(${PROJECT_AWECLIENT_NAME} generated_sources)

# }}}

 

# {{{ Version stamp

if(BUILD_FROM_GIT)

       //自定义的target,这里的target类似于makefile中的target

    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)

    add_dependencies(${PROJECT_AWECLIENT_NAME} version_stamp)

endif()

# }}}

 

# {{{ Manpages

if(GENERATE_MANPAGES)

    foreach(txtfile ${AWE_MAN_SRCS})

        string(REGEX REPLACE ".txt/$" ".xml" xmlfile ${txtfile})

        string(REPLACE ${SOURCE_DIR}

                       ${BUILD_DIR} xmlfile ${xmlfile})

        string(REGEX REPLACE ".xml/$" ".gz" gzfile ${xmlfile})

        string(REGEX REPLACE ".gz/$" "" manfile ${gzfile})

 

        add_custom_command(

            COMMAND ${CAT_EXECUTABLE} ${txtfile}

                    | ${ASCIIDOC_EXECUTABLE} -d manpage -b docbook -o ${xmlfile} -

            WORKING_DIRECTORY ${BUILD_DIR}

            OUTPUT  ${xmlfile}

            DEPENDS ${txtfile}

            VERBATIM)

        add_custom_command(

            COMMAND ${XMLTO_EXECUTABLE} man ${xmlfile}

            OUTPUT  ${manfile}

            DEPENDS ${xmlfile})

        add_custom_command(

            COMMAND ${CAT_EXECUTABLE} ${manfile}

                    | ${GZIP_EXECUTABLE}

                    > ${gzfile}

            OUTPUT  ${gzfile}

            DEPENDS ${manfile}

            VERBATIM)

 

        set(MAN_FILES ${MAN_FILES} ${gzfile})

 

        # figure out in what section to install to from filename

        string(REGEX REPLACE "^.*//.([0-9])//.gz/$" "//1" section ${gzfile})

        set(AWE_MAN${section}_FILES ${AWE_MAN${section}_FILES} ${gzfile})

    endforeach()

 

    add_custom_target(man ALL DEPENDS ${MAN_FILES})

endif()

# }}}

 

# {{{ Doxygen

if(DOXYGEN_EXECUTABLE)

    add_custom_target(doc

        COMMAND ${DOXYGEN_EXECUTABLE} awesome.doxygen

        WORKING_DIRECTORY ${BUILD_DIR})

endif()

# }}}

 

# {{{ Lua API Documentation

if(GENERATE_LUADOC)

 

    set(capi_lua ${BUILD_DIR}/lib/capi.lua)

 

    if(NOT BUILD_DIR STREQUAL SOURCE_DIR)

        file(MAKE_DIRECTORY ${BUILD_DIR}/lib)

    endif()

 

    # {{{ setup a command for ${capi_lua}

    macro(a_file_match infile regex result_var)

        file(STRINGS ${infile} match REGEX ${regex} LIMIT_COUNT 1)

        if(match)

            set(${result_var} TRUE)

        else()

            set(${result_var} FALSE)

        endif()

    endmacro()

 

    set(luadoc_c_srcs "")

 

    # find .c files exporting lua functions

    foreach(cfile ${AWE_SRCS})

        a_file_match(${cfile} "const struct luaL_reg" result)

        if(result)

            set(luadoc_c_srcs ${luadoc_c_srcs} ${cfile})

        else()

            a_file_match(${cfile} "luaA_.*_index" result)

            if(result)

                set(luadoc_c_srcs ${luadoc_c_srcs} ${cfile})

        endif()

        endif()

    endforeach()

 

    # create fake lua source file to process by luadoc

    add_custom_command(

        COMMAND ${CAT_EXECUTABLE} ${luadoc_c_srcs}

                | ${LUA_EXECUTABLE} ${SOURCE_DIR}/build-utils/fake-lua-src.lua

                > ${capi_lua}

        OUTPUT  ${capi_lua}

        DEPENDS ${luadoc_c_srcs}

        COMMENT "Generating fake lua source."

        VERBATIM)

    # }}}

 

    # Generate documentation of lib//0lua

    file(GLOB_RECURSE lua_lib_files ${BUILD_DIR}/lib/*.lua)

    foreach(filename ${lua_lib_files})

        file(RELATIVE_PATH filename ${BUILD_DIR}/lib ${filename})

        set(luadoc_srcs ${luadoc_srcs} ${filename})

    endforeach()

 

    add_custom_target(luadoc ALL

        COMMAND ${LUADOC_EXECUTABLE} ${luadoc_srcs} -d ${BUILD_DIR}/luadoc

        WORKING_DIRECTORY ${BUILD_DIR}/lib

        DEPENDS ${AWE_LUA_FILES} ${capi_lua})

endif()

# }}}

 

# {{{ 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} ${PROJECT_AWECLIENT_NAME} RUNTIME DESTINATION bin)

install(FILES "utils/awsetbg" 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})

install(FILES ${AWE_CONF_FILE_DEFAULT} DESTINATION ${AWESOME_SYSCONFDIR}

        RENAME ${AWE_CONF_FILE})

if(GENERATE_MANPAGES)

    install(FILES ${AWE_MAN1_FILES} DESTINATION ${AWESOME_MAN_PATH}/man1)

    install(FILES ${AWE_MAN5_FILES} DESTINATION ${AWESOME_MAN_PATH}/man5)

endif()

install(DIRECTORY ${AWE_ICON_DIR} DESTINATION ${AWESOME_DATA_PATH})

install(DIRECTORY ${BUILD_DIR}/themes DESTINATION ${AWESOME_DATA_PATH})

install(DIRECTORY ${SOURCE_DIR}/themes DESTINATION ${AWESOME_DATA_PATH}

    PATTERN "*.in" EXCLUDE)

install(FILES ${AWE_DOC_FILES} DESTINATION ${AWESOME_DOC_PATH})

install(FILES "awesome.desktop" DESTINATION ${AWESOME_XSESSION_PATH})

if(GENERATE_LUADOC)

    install(DIRECTORY ${BUILD_DIR}/luadoc DESTINATION ${AWESOME_DOC_PATH})

endif()

# }}}

 

# vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

 

阅读更多
上一篇从spserver看HS-HA模式
下一篇Hadoop最佳实践
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭