2016-05-19 14:41:06 +00:00
|
|
|
#
|
|
|
|
# Build configuration
|
|
|
|
#
|
2016-08-31 16:55:36 +00:00
|
|
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
2016-06-15 03:32:35 +00:00
|
|
|
project(lemonbuddy CXX)
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-10-25 18:14:44 +00:00
|
|
|
option(CXXLIB_CLANG "Link against libc++" OFF)
|
|
|
|
option(CXXLIB_GCC "Link against stdlibc++" OFF)
|
|
|
|
|
2016-10-24 23:46:26 +00:00
|
|
|
# Include local cmake modules
|
2016-06-15 03:32:35 +00:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/modules)
|
|
|
|
|
2016-10-25 18:14:44 +00:00
|
|
|
# Export compile commands used for custom targets
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
2016-10-24 23:46:26 +00:00
|
|
|
# Load cmake utility functions
|
|
|
|
include(cmake/utils.cmake)
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-10-24 23:46:26 +00:00
|
|
|
# Set default build type if not specified
|
2016-05-20 02:27:24 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
2016-10-24 23:46:26 +00:00
|
|
|
message_colored(STATUS "No build type specified; using Release" 33)
|
2016-05-20 02:27:24 +00:00
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
endif()
|
|
|
|
|
2016-10-24 23:46:26 +00:00
|
|
|
# Generic compiler flags
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
|
|
|
|
|
|
|
# Debug specific compiler flags
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g2")
|
2016-10-25 18:14:44 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic-errors")
|
2016-05-24 12:24:45 +00:00
|
|
|
|
2016-10-24 23:46:26 +00:00
|
|
|
# Release specific compiler flags
|
2016-10-25 18:14:44 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
2016-06-23 04:36:03 +00:00
|
|
|
|
2016-10-25 18:14:44 +00:00
|
|
|
# Compiler specific flags
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang)
|
|
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32)
|
|
|
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL GNU)
|
|
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32)
|
|
|
|
else()
|
|
|
|
message_colored(WARNING "Using unsupported compiler ${CMAKE_CXX_COMPILER_ID} !" 31)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set compiler and linker flags for preferred C++ library
|
|
|
|
if(CXXLIB_CLANG)
|
|
|
|
message_colored(STATUS "Linking against libc++" 32)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi")
|
|
|
|
elseif(CXXLIB_GCC)
|
|
|
|
message_colored(STATUS "Linking against libstdc++" 32)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
|
|
|
|
else()
|
|
|
|
message_colored(STATUS "No preferred c++lib specified... linking against system default" 33)
|
|
|
|
endif()
|
2016-10-24 23:46:26 +00:00
|
|
|
|
|
|
|
# Project settings {{{
|
|
|
|
|
|
|
|
# Set default option values based on current environment
|
2016-08-31 16:55:36 +00:00
|
|
|
find_package(ALSA QUIET)
|
|
|
|
find_package(Libiw QUIET)
|
|
|
|
find_package(LibMPDClient QUIET)
|
2016-06-15 03:32:35 +00:00
|
|
|
find_program(I3_BINARY i3)
|
2016-08-31 16:55:36 +00:00
|
|
|
if(I3_BINARY)
|
|
|
|
set(I3_FOUND ON)
|
2016-06-23 04:36:03 +00:00
|
|
|
endif()
|
|
|
|
|
2016-10-24 23:46:26 +00:00
|
|
|
option(BUILD_TESTS "Build testsuite" OFF)
|
|
|
|
option(ENABLE_CCACHE "Enable ccache support" OFF)
|
2016-08-31 16:55:36 +00:00
|
|
|
option(ENABLE_ALSA "Enable alsa support" ${ALSA_FOUND})
|
|
|
|
option(ENABLE_I3 "Enable i3 support" ${I3_FOUND})
|
|
|
|
option(ENABLE_MPD "Enable mpd support" ${LIBMPDCLIENT_FOUND})
|
|
|
|
option(ENABLE_NETWORK "Enable network support" ${LIBIW_FOUND})
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
if(ENABLE_ALSA)
|
|
|
|
set(SETTING_ALSA_SOUNDCARD "default"
|
|
|
|
CACHE STRING "Name of the ALSA soundcard driver")
|
|
|
|
endif()
|
|
|
|
set(SETTING_CONNECTION_TEST_IP "8.8.8.8"
|
|
|
|
CACHE STRING "Address to ping when testing network connection")
|
|
|
|
set(SETTING_PATH_BACKLIGHT_VAL "/sys/class/backlight/%card%/brightness"
|
|
|
|
CACHE STRING "Path to file containing the current backlight value")
|
|
|
|
set(SETTING_PATH_BACKLIGHT_MAX "/sys/class/backlight/%card%/max_brightness"
|
|
|
|
CACHE STRING "Path to file containing the maximum backlight value")
|
|
|
|
set(SETTING_PATH_BATTERY_CAPACITY "/sys/class/power_supply/%battery%/capacity"
|
|
|
|
CACHE STRING "Path to file containing the current battery capacity")
|
|
|
|
set(SETTING_PATH_ADAPTER_STATUS "/sys/class/power_supply/%adapter%/online"
|
|
|
|
CACHE STRING "Path to file containing the current adapter status")
|
|
|
|
set(SETTING_BSPWM_SOCKET_PATH "/tmp/bspwm_0_0-socket"
|
|
|
|
CACHE STRING "Path to bspwm socket")
|
|
|
|
set(SETTING_BSPWM_STATUS_PREFIX "W"
|
|
|
|
CACHE STRING "Prefix prepended to the bspwm status line")
|
|
|
|
set(SETTING_PATH_CPU_INFO "/proc/stat"
|
|
|
|
CACHE STRING "Path to file containing cpu info")
|
|
|
|
set(SETTING_PATH_MEMORY_INFO "/proc/meminfo"
|
|
|
|
CACHE STRING "Path to file containing memory info")
|
|
|
|
|
|
|
|
if(ENABLE_CCACHE)
|
2016-10-24 23:46:26 +00:00
|
|
|
require_binary(ccache)
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${BINPATH_ccache})
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${BINPATH_ccache})
|
2016-05-24 02:06:29 +00:00
|
|
|
endif()
|
2016-05-20 09:20:58 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
# }}}
|
2016-10-24 23:46:26 +00:00
|
|
|
# Add subdirectories {{{
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
add_subdirectory(${PROJECT_SOURCE_DIR}/man)
|
|
|
|
add_subdirectory(${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/bin)
|
|
|
|
add_subdirectory(${PROJECT_SOURCE_DIR}/examples ${PROJECT_BINARY_DIR}/examples)
|
2016-10-24 23:46:26 +00:00
|
|
|
|
2016-10-12 05:17:03 +00:00
|
|
|
if(BUILD_TESTS)
|
2016-10-24 23:46:26 +00:00
|
|
|
add_subdirectory(${PROJECT_SOURCE_DIR}/tests ${PROJECT_BINARY_DIR}/tests)
|
|
|
|
else()
|
2016-10-12 05:17:03 +00:00
|
|
|
add_subdirectory(${PROJECT_SOURCE_DIR}/tests ${PROJECT_BINARY_DIR}/tests EXCLUDE_FROM_ALL)
|
|
|
|
endif()
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
# }}}
|
|
|
|
# Build summary {{{
|
2016-06-28 12:50:21 +00:00
|
|
|
|
2016-05-24 02:06:29 +00:00
|
|
|
message(STATUS "---------------------------")
|
2016-06-21 02:27:14 +00:00
|
|
|
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
|
2016-06-21 05:48:24 +00:00
|
|
|
message(STATUS " Compiler C: ${CMAKE_C_COMPILER}")
|
|
|
|
message(STATUS " Compiler C++: ${CMAKE_CXX_COMPILER}")
|
2016-06-15 03:32:35 +00:00
|
|
|
message(STATUS " Compiler flags: ${CMAKE_CXX_FLAGS}")
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
message(STATUS " + debug flags:: ${CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
message(STATUS " + release flags:: ${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
|
|
|
|
message(STATUS " + minsizerel flags:: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
|
|
|
message(STATUS " + relwithdebinfo flags:: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
|
|
|
endif()
|
2016-10-25 18:14:44 +00:00
|
|
|
if(CXXLIB_CLANG)
|
2016-10-25 20:59:02 +00:00
|
|
|
message(STATUS " Linking C++ library: libc++")
|
2016-10-25 18:14:44 +00:00
|
|
|
elseif(CXXLIB_GCC)
|
2016-10-25 20:59:02 +00:00
|
|
|
message(STATUS " Linking C++ library: libstdc++")
|
2016-10-25 18:14:44 +00:00
|
|
|
else()
|
2016-10-25 20:59:02 +00:00
|
|
|
message(STATUS " Linking C++ library: system default")
|
2016-10-25 18:14:44 +00:00
|
|
|
endif()
|
2016-06-21 05:48:24 +00:00
|
|
|
message(STATUS "---------------------------")
|
2016-10-12 05:17:03 +00:00
|
|
|
message(STATUS " Build testsuite ${BUILD_TESTS}")
|
2016-05-24 02:06:29 +00:00
|
|
|
message(STATUS " Enable ccache support ${ENABLE_CCACHE}")
|
|
|
|
message(STATUS " Enable alsa support ${ENABLE_ALSA}")
|
|
|
|
message(STATUS " Enable i3 support ${ENABLE_I3}")
|
|
|
|
message(STATUS " Enable mpd support ${ENABLE_MPD}")
|
|
|
|
message(STATUS " Enable network support ${ENABLE_NETWORK}")
|
2016-06-15 03:32:35 +00:00
|
|
|
if(DISABLE_MODULES)
|
|
|
|
message(STATUS " Disable modules ON")
|
|
|
|
endif()
|
|
|
|
if(DISABLE_TRAY)
|
|
|
|
message(STATUS " Disable systray ON")
|
|
|
|
endif()
|
|
|
|
if(DISABLE_DRAW)
|
|
|
|
message(STATUS " Disable drawing ON")
|
|
|
|
endif()
|
2016-05-24 02:06:29 +00:00
|
|
|
message(STATUS "---------------------------")
|
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
# }}}
|
2016-10-24 23:46:26 +00:00
|
|
|
|
|
|
|
# Custom target: uninstall {{{
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
configure_file(
|
2016-06-15 03:32:35 +00:00
|
|
|
${PROJECT_SOURCE_DIR}/cmake/uninstall.cmake.in
|
|
|
|
${PROJECT_BINARY_DIR}/cmake/uninstall.cmake
|
2016-05-19 14:41:06 +00:00
|
|
|
IMMEDIATE @ONLY)
|
|
|
|
|
|
|
|
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND}
|
2016-06-15 03:32:35 +00:00
|
|
|
-P ${PROJECT_BINARY_DIR}/cmake/uninstall.cmake)
|
|
|
|
|
|
|
|
# }}}
|
2016-10-24 23:46:26 +00:00
|
|
|
# Custom target: clang-format {{{
|
|
|
|
|
|
|
|
find_program(CLANG_FORMAT "clang-format")
|
|
|
|
|
|
|
|
if(CLANG_FORMAT)
|
|
|
|
file(GLOB_RECURSE HEADERS ${PROJECT_SOURCE_DIR}/include/*.hpp)
|
|
|
|
file(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
|
|
|
|
|
|
|
|
add_custom_target(clang-format COMMAND ${CLANG_FORMAT}
|
|
|
|
-i -style=file ${HEADERS} ${SOURCES})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(CLANG_TIDY "clang-tidy")
|
|
|
|
|
|
|
|
# }}}
|
|
|
|
# Custom target: clang-tidy {{{
|
|
|
|
|
|
|
|
if(CLANG_TIDY)
|
|
|
|
add_custom_target(clang-tidy COMMAND ${CLANG_TIDY}
|
|
|
|
-p ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src/main.cpp)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# }}}
|