From 74a04ded808fe8ecf5444e9e6dcae9532a4e9733 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Thu, 3 Nov 2016 13:06:33 +0100 Subject: [PATCH] fix(build): Add missing files --- .gitignore | 1 + cmake/build/core.cmake | 58 +++++++++++++++++++++++++++++++++++++++ cmake/build/options.cmake | 58 +++++++++++++++++++++++++++++++++++++++ cmake/build/summary.cmake | 45 ++++++++++++++++++++++++++++++ cmake/build/targets.cmake | 39 ++++++++++++++++++++++++++ 5 files changed, 201 insertions(+) create mode 100644 cmake/build/core.cmake create mode 100644 cmake/build/options.cmake create mode 100644 cmake/build/summary.cmake create mode 100644 cmake/build/targets.cmake diff --git a/.gitignore b/.gitignore index bc90ec12..f01fad86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build*/ +!cmake/build/ tags *.bak *.pyc diff --git a/cmake/build/core.cmake b/cmake/build/core.cmake new file mode 100644 index 00000000..23e012fe --- /dev/null +++ b/cmake/build/core.cmake @@ -0,0 +1,58 @@ +# +# Core setup +# + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Export compile commands used for custom targets +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Set default build type if not specified +if(NOT CMAKE_BUILD_TYPE) + message_colored(STATUS "No build type specified; using Release" 33) + set(CMAKE_BUILD_TYPE "Release") +endif() + +# Generic compiler flags +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") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic-errors") + +# Release specific compiler flags +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") + +# 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() + +if(ENABLE_CCACHE) + require_binary(ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${BINPATH_ccache}) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${BINPATH_ccache}) +endif() diff --git a/cmake/build/options.cmake b/cmake/build/options.cmake new file mode 100644 index 00000000..685ad137 --- /dev/null +++ b/cmake/build/options.cmake @@ -0,0 +1,58 @@ +# +# Build options +# + +option(CXXLIB_CLANG "Link against libc++" OFF) +option(CXXLIB_GCC "Link against stdlibc++" OFF) + +option(BUILD_TESTS "Build testsuite" OFF) +option(DEBUG_LOGGER "Enable extra debug logging" OFF) +option(VERBOSE_TRACELOG "Enable verbose trace logs" OFF) + +option(ENABLE_CCACHE "Enable ccache support" OFF) +option(ENABLE_ALSA "Enable alsa support" ON) +option(ENABLE_I3 "Enable i3 support" ON) +option(ENABLE_MPD "Enable mpd support" ON) +option(ENABLE_NETWORK "Enable network support" ON) + +option(ENABLE_RANDR_EXT "Enable RandR X extension" ON) +option(ENABLE_RENDER_EXT "Enable Render X extension" OFF) +option(ENABLE_DAMAGE_EXT "Enable Damage X extension" OFF) + +set(SETTING_ALSA_SOUNDCARD "default" + CACHE STRING "Name of the ALSA soundcard driver") +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") + +find_package(ALSA QUIET) +if(NOT ALSA_FOUND) + set(ENABLE_ALSA OFF) +endif() +find_package(Libiw QUIET) +if(NOT LIBIW_FOUND) + set(ENABLE_NETWORK OFF) +endif() +find_package(LibMPDClient QUIET) +if(NOT LIBMPDCLIENT_FOUND) + set(ENABLE_MPD OFF) +endif() +find_program(I3_BINARY i3) +if(NOT I3_BINARY) + set(ENABLE_I3 OFF) +endif() diff --git a/cmake/build/summary.cmake b/cmake/build/summary.cmake new file mode 100644 index 00000000..3708ccca --- /dev/null +++ b/cmake/build/summary.cmake @@ -0,0 +1,45 @@ +# +# Output build summary +# + +message(STATUS "---------------------------") +message(STATUS " Build type: ${CMAKE_BUILD_TYPE}") +message(STATUS " Compiler C: ${CMAKE_C_COMPILER}") +message(STATUS " Compiler C++: ${CMAKE_CXX_COMPILER}") +message(STATUS " Compiler flags: ${CMAKE_CXX_FLAGS}") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + message(STATUS " + debug flags:: ${CMAKE_CXX_FLAGS_DEBUG}") + if(NOT DEFINED ${DEBUG_LOGGER}) + set(DEBUG_LOGGER ON) + endif() + if(NOT DEFINED ${ENABLE_CCACHE}) + set(ENABLE_CCACHE ON) + endif() +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() + +if(CXXLIB_CLANG) + message(STATUS " Linking C++ library: libc++") +elseif(CXXLIB_GCC) + message(STATUS " Linking C++ library: libstdc++") +else() + message(STATUS " Linking C++ library: system default") +endif() + +message(STATUS "---------------------------") +message(STATUS " Build testsuite ${BUILD_TESTS}") +message(STATUS " Enable debug logger ${DEBUG_LOGGER}") +message(STATUS " Enable extra tracing ${VERBOSE_TRACELOG}") +message(STATUS " Enable ccache support ${ENABLE_CCACHE}") +message(STATUS "---------------------------") +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}") +message(STATUS "---------------------------") diff --git a/cmake/build/targets.cmake b/cmake/build/targets.cmake new file mode 100644 index 00000000..bf108b62 --- /dev/null +++ b/cmake/build/targets.cmake @@ -0,0 +1,39 @@ +# +# Custom targets +# + +# Target: uninstall {{{ + +configure_file( + ${PROJECT_SOURCE_DIR}/cmake/templates/uninstall.cmake.in + ${PROJECT_BINARY_DIR}/uninstall.cmake + IMMEDIATE @ONLY) + +add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} + -P ${PROJECT_BINARY_DIR}/cuninstall.cmake) + +# }}} +# 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") + +# }}} +# 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() + +# }}}