mirror of
https://github.com/polybar/polybar.git
synced 2024-10-27 05:23:39 -04:00
444120e664
Fixes #1978 * Move tail and non-tail handler to method Defining them in the constructor is ugly. * script: Iterate over defined actions instead of fixed list * Separate running logic and lock m_output * Include POLYBAR_FLAGS in linker flags * Stop using m_prev in script_runner * Join module threads in stop function Joining in the destructor may lead to UB because the subclass is already deconstructed but the threads may still require it to be around (e.g. for calling any functions on the instance) * Cleanup script module * Update changelog * Remove AfterReturn class * Remove m_stopping from script module * Fix polybar not reading the entire line from child process. For every `readline` call we created a new fd_streambuf. This means once `readline` returns, the streambuf is destructed and and pending data in its temporary buffer discarded and we never actually read it. * Remove unused includes
111 lines
4.2 KiB
CMake
111 lines
4.2 KiB
CMake
option(ENABLE_CCACHE "Enable ccache support" ON)
|
|
if(ENABLE_CCACHE)
|
|
find_program(BIN_CCACHE ccache)
|
|
mark_as_advanced(BIN_CCACHE)
|
|
|
|
if(NOT BIN_CCACHE)
|
|
message_colored(STATUS "Couldn't locate ccache, disabling ccache..." "33")
|
|
else()
|
|
# Enable only if the binary is found
|
|
message_colored(STATUS "Using compiler cache ${BIN_CCACHE}" "32")
|
|
set(CMAKE_CXX_COMPILER_LAUNCHER ${BIN_CCACHE} CACHE STRING "")
|
|
endif()
|
|
endif()
|
|
|
|
option(CXXLIB_CLANG "Link against libc++" OFF)
|
|
option(CXXLIB_GCC "Link against stdlibc++" OFF)
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
|
|
set(POLYBAR_FLAGS "" CACHE STRING "C++ compiler flags used for compiling polybar")
|
|
|
|
list(APPEND cxx_base -Wall -Wextra -Wpedantic)
|
|
list(APPEND cxx_debug -DDEBUG -g2)
|
|
list(APPEND cxx_minsizerel "")
|
|
list(APPEND cxx_sanitize -O0 -g -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls)
|
|
list(APPEND cxx_coverage --coverage)
|
|
|
|
list(APPEND cxx_linker_base "")
|
|
list(APPEND cxx_linker_minsizerel "")
|
|
|
|
# Compiler flags
|
|
include(CheckCXXCompilerFlag)
|
|
check_cxx_compiler_flag("-Wsuggest-override" HAS_SUGGEST_OVERRIDE)
|
|
if (HAS_SUGGEST_OVERRIDE)
|
|
list(APPEND cxx_base -Wsuggest-override)
|
|
endif()
|
|
unset(HAS_SUGGEST_OVERRIDE)
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
|
# Need dprintf() for FreeBSD 11.1 and older
|
|
# libinotify uses c99 extension, so suppress this error
|
|
list(APPEND cxx_base -D_WITH_DPRINTF -Wno-c99-extensions)
|
|
# Ensures that libraries from dependencies in LOCALBASE are used
|
|
list(APPEND cxx_linker_base -L/usr/local/lib)
|
|
endif()
|
|
|
|
# Check compiler
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
|
list(APPEND cxx_base -Wno-error=parentheses-equality -Wno-zero-length-array)
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.4.0")
|
|
message_colored(FATAL_ERROR "Compiler not supported (Requires clang-3.4+ or gcc-5.1+)" 31)
|
|
else()
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}" 32)
|
|
endif()
|
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
|
list(APPEND cxx_minsizerel -fdata-sections -ffunction-sections -flto)
|
|
list(APPEND cxx_linker_minsizerel -Wl,--gc-sections)
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1.0")
|
|
message_colored(FATAL_ERROR "Compiler not supported (Requires clang-3.4+ or gcc-5.1+)" 31)
|
|
else()
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}" 32)
|
|
endif()
|
|
else()
|
|
message_colored(WARNING "Using unsupported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION} !" 31)
|
|
endif()
|
|
|
|
# Set compiler and linker flags for preferred C++ library
|
|
if(CXXLIB_CLANG)
|
|
message_colored(STATUS "Linking against libc++" 32)
|
|
list(APPEND cxx_base -stdlib=libc++)
|
|
list(APPEND cxx_linker_base -lc++ -lc++abi)
|
|
elseif(CXXLIB_GCC)
|
|
message_colored(STATUS "Linking against libstdc++" 32)
|
|
list(APPEND cxx_linker_base -lstdc++)
|
|
endif()
|
|
|
|
# Custom build type 'Coverage', inherits the debug flags
|
|
list(APPEND cxx_coverage ${cxx_debug} ${cxx_coverage})
|
|
SET(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_COVERAGE}")
|
|
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CMAKE_EXE_LINKER_FLAGS_COVERAGE}")
|
|
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${CMAKE_SHARED_LINKER_FLAGS_COVERAGE}")
|
|
|
|
list(APPEND cxx_flags ${cxx_base})
|
|
list(APPEND cxx_linker_flags ${cxx_linker_base})
|
|
|
|
if (CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
|
|
list(APPEND cxx_flags ${cxx_debug})
|
|
elseif (CMAKE_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL")
|
|
list(APPEND cxx_flags ${cxx_minsizerel})
|
|
list(APPEND cxx_linker_flags ${cxx_linker_minsizerel})
|
|
elseif (CMAKE_BUILD_TYPE_UPPER STREQUAL "SANITIZE")
|
|
list(APPEND cxx_flags ${cxx_sanitize})
|
|
elseif (CMAKE_BUILD_TYPE_UPPER STREQUAL "COVERAGE")
|
|
list(APPEND cxx_flags ${cxx_coverage})
|
|
endif()
|
|
|
|
string(REPLACE " " ";" polybar_flags_list "${POLYBAR_FLAGS}")
|
|
list(APPEND cxx_flags ${polybar_flags_list})
|
|
|
|
list(APPEND cxx_linker_flags ${cxx_flags})
|
|
|
|
string(REPLACE ";" " " cxx_flags_str "${cxx_flags}")
|
|
string(REPLACE ";" " " cxx_linker_flags_str "${cxx_linker_flags}")
|
|
|
|
# TODO use target_link_options once min cmake version is >= 3.13
|
|
set(CMAKE_EXE_LINKER_FLAGS "${cxx_linker_flags_str}")
|