kranewl

A wlroots-based dynamic Wayland compositor, written in C++, configurable with Lua
git clone git://git.deurzen.net/kranewl
Log | Files | Refs | LICENSE

CMakeLists.txt (6107B)


      1 cmake_minimum_required(VERSION 3.10.0)
      2 
      3 project(kranewl
      4     VERSION 0.0.1
      5     DESCRIPTION "A wlroots-based dynamic Wayland compositor, written in C++, configured with Lua"
      6     HOMEPAGE_URL "%%https://github.com/deurzen/kranewl%%"
      7     LANGUAGES CXX
      8 )
      9 
     10 set(CMAKE_CXX_STANDARD 20)
     11 set(CMAKE_CXX_STANDARD_REQUIRED ON)
     12 set(CMAKE_CXX_EXTENSIONS OFF)
     13 
     14 add_compile_options(
     15     $<$<CONFIG:DEBUG>:-w>
     16     $<$<CONFIG:DEBUG>:-DXWAYLAND>
     17     $<$<CONFIG:DEBUG>:-O0>
     18     $<$<CONFIG:DEBUG>:-g>
     19     $<$<CONFIG:RELEASE>:-w>
     20     $<$<CONFIG:RELEASE>:-DXWAYLAND>
     21     $<$<CONFIG:RELEASE>:-DTRACING_DISABLED>
     22     $<$<CONFIG:RELEASE>:-O2>
     23 )
     24 
     25 add_compile_definitions(
     26     $<$<CONFIG:DEBUG>:DEBUG>
     27 )
     28 
     29 find_program(CCACHE ccache)
     30 if(CCACHE)
     31     set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
     32 endif(CCACHE)
     33 
     34 set(CMAKE_CXX_CPPCHECK cppcheck)
     35 find_program(CPPCHECK NAMES cppcheck)
     36 if (CPPCHECK)
     37     list(
     38         APPEND CPPCHECK
     39             "--enable=style,performance,warning,portability"
     40             "--enable=warning"
     41             "--force"
     42             "--inconclusive"
     43             "--inline-suppr"
     44             "--suppress=cppcheckError"
     45             "--suppress=internalAstError"
     46             "--suppress=passedByValue"
     47             "--suppress=syntaxError"
     48             "--suppress=unmatchedSuppression"
     49     )
     50 endif(CPPCHECK)
     51 
     52 execute_process(COMMAND git rev-parse --short HEAD
     53     OUTPUT_VARIABLE GIT_REVISION
     54     ERROR_QUIET
     55 )
     56 
     57 if ("${GIT_REVISION}" STREQUAL "")
     58     set(VERSION "")
     59 else()
     60     execute_process(
     61         COMMAND bash -c "git diff --quiet --exit-code || echo +"
     62         OUTPUT_VARIABLE GIT_DIRTY
     63     )
     64 
     65     execute_process(
     66         COMMAND git describe --exact-match --tags
     67         OUTPUT_VARIABLE GIT_TAG ERROR_QUIET
     68     )
     69 
     70     execute_process(
     71         COMMAND git rev-parse --abbrev-ref HEAD
     72         OUTPUT_VARIABLE GIT_BRANCH
     73     )
     74 
     75     string(STRIP "${GIT_REVISION}" GIT_REVISION)
     76     string(STRIP "${GIT_DIRTY}" GIT_DIRTY)
     77     string(STRIP "${GIT_TAG}" GIT_TAG)
     78     string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
     79 
     80     if (NOT "${GIT_TAG}" STREQUAL "")
     81         set(VERSION "${GIT_TAG}-${GIT_REVISION}${GIT_DIRTY}")
     82     else()
     83         set(VERSION "${GIT_BRANCH}/${GIT_REVISION}${GIT_DIRTY}")
     84     endif()
     85 endif()
     86 
     87 if(EXISTS ${CMAKE_SOURCE_DIR}/include/version.hh)
     88     file(READ ${CMAKE_SOURCE_DIR}/include/version.hh CURRENT_VERSION)
     89 else()
     90     set(CURRENT_VERSION "")
     91 endif()
     92 
     93 if (NOT "#define VERSION \"${VERSION}\"" STREQUAL "${CURRENT_VERSION}")
     94     file(WRITE
     95         ${CMAKE_SOURCE_DIR}/include/version.hh
     96         "#define VERSION \"${VERSION}\""
     97     )
     98 endif()
     99 
    100 file(GLOB_RECURSE KRANEWL_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} src/kranewl/*.cc)
    101 file(GLOB_RECURSE KRANEC_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} src/kranec/*.cc)
    102 
    103 find_package(PkgConfig)
    104 pkg_get_variable(WAYLAND_PROTOCOLS wayland-protocols pkgdatadir)
    105 
    106 add_custom_command(
    107     OUTPUT ${CMAKE_SOURCE_DIR}/include/protocols/xdg-shell-protocol.h
    108     COMMAND wayland-scanner server-header ${WAYLAND_PROTOCOLS}/stable/xdg-shell/xdg-shell.xml ${CMAKE_SOURCE_DIR}/include/protocols/xdg-shell-protocol.h
    109     COMMENT "Generating xdg-shell-protocol.h"
    110 )
    111 
    112 add_custom_command(
    113     OUTPUT ${CMAKE_SOURCE_DIR}/include/protocols/wlr-layer-shell-unstable-v1-protocol.h
    114     COMMAND wayland-scanner server-header ${CMAKE_SOURCE_DIR}/protocols/wlr-layer-shell-unstable-v1.xml ${CMAKE_SOURCE_DIR}/include/protocols/wlr-layer-shell-unstable-v1-protocol.h
    115     COMMENT "Generating layer-shell-protocol.h"
    116 )
    117 
    118 add_custom_command(
    119     OUTPUT ${CMAKE_SOURCE_DIR}/include/protocols/pointer-constraints-unstable-v1-protocol.h
    120     COMMAND wayland-scanner server-header ${WAYLAND_PROTOCOLS}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml ${CMAKE_SOURCE_DIR}/include/protocols/pointer-constraints-unstable-v1-protocol.h
    121     COMMENT "Generating pointer-constraints-unstable-v1.h"
    122 )
    123 
    124 add_custom_target(run ALL
    125     DEPENDS ${CMAKE_SOURCE_DIR}/include/protocols/xdg-shell-protocol.h
    126     DEPENDS ${CMAKE_SOURCE_DIR}/include/protocols/wlr-layer-shell-unstable-v1-protocol.h
    127     DEPENDS ${CMAKE_SOURCE_DIR}/include/protocols/pointer-constraints-unstable-v1-protocol.h
    128 )
    129 
    130 set_source_files_properties(tags PROPERTIES GENERATED true)
    131 add_custom_command (OUTPUT tags
    132     COMMAND git ls-files | ctags -R --exclude=.git --c++-kinds=+p --links=no --fields=+iaS --extras=+q -L-
    133     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    134     COMMENT "Generating project tags"
    135 )
    136 
    137 add_executable(kranewl
    138     ${KRANEWL_SOURCES}
    139     tags
    140 )
    141 
    142 add_executable(kranec
    143     ${KRANEC_SOURCES}
    144 )
    145 
    146 pkg_check_modules(spdlog REQUIRED IMPORTED_TARGET spdlog)
    147 pkg_check_modules(lua REQUIRED IMPORTED_TARGET lua5.4)
    148 pkg_check_modules(cairo REQUIRED IMPORTED_TARGET cairo)
    149 pkg_check_modules(pangocairo REQUIRED IMPORTED_TARGET pangocairo)
    150 pkg_check_modules(wayland_server REQUIRED IMPORTED_TARGET wayland-server)
    151 pkg_check_modules(wlroots REQUIRED IMPORTED_TARGET wlroots)
    152 pkg_check_modules(pixman_1 REQUIRED IMPORTED_TARGET pixman-1)
    153 pkg_check_modules(libinput REQUIRED IMPORTED_TARGET libinput)
    154 pkg_check_modules(xkbcommon REQUIRED IMPORTED_TARGET xkbcommon)
    155 pkg_check_modules(xcb REQUIRED IMPORTED_TARGET xcb)
    156 
    157 target_compile_features(kranewl PRIVATE cxx_std_20)
    158 target_compile_features(kranec PRIVATE cxx_std_20)
    159 target_compile_definitions(kranewl PRIVATE
    160     # required to use wlroots' unstable interfaces
    161     WLR_USE_UNSTABLE
    162 )
    163 
    164 target_link_libraries(kranewl
    165     PRIVATE
    166     PkgConfig::spdlog
    167     PkgConfig::lua
    168     PkgConfig::cairo
    169     PkgConfig::pangocairo
    170     PkgConfig::wayland_server
    171     PkgConfig::wlroots
    172     PkgConfig::pixman_1
    173     PkgConfig::libinput
    174     PkgConfig::xkbcommon
    175     PkgConfig::xcb
    176 )
    177 
    178 target_include_directories(kranewl PRIVATE
    179     ${CMAKE_SOURCE_DIR}/src/kranewl
    180     ${CMAKE_SOURCE_DIR}/include
    181     ${CMAKE_SOURCE_DIR}/include/protocols
    182 )
    183 
    184 target_include_directories(kranec PRIVATE
    185     ${CMAKE_SOURCE_DIR}/src/kranec
    186     ${CMAKE_SOURCE_DIR}/include
    187     ${CMAKE_SOURCE_DIR}/include/protocols
    188 )
    189 
    190 install(TARGETS kranewl)
    191 install(TARGETS kranec)
    192 
    193 include(CTest)
    194 
    195 add_test(NAME kranewl
    196     COMMAND
    197     kranewl
    198 )
    199 
    200 set_tests_properties(kranewl
    201     PROPERTIES
    202     ENVIRONMENT WL_BACKEND=x11
    203 )