fix(cmake): Make specific c++lib linking optional
- Do not enforce linking against libc++ - Fix various linter warnings
This commit is contained in:
parent
27df2398f0
commit
eac65cdabb
@ -4,47 +4,60 @@
|
|||||||
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
||||||
project(lemonbuddy CXX)
|
project(lemonbuddy CXX)
|
||||||
|
|
||||||
|
option(CXXLIB_CLANG "Link against libc++" OFF)
|
||||||
|
option(CXXLIB_GCC "Link against stdlibc++" OFF)
|
||||||
|
|
||||||
# Include local cmake modules
|
# Include local cmake modules
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/modules)
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/modules)
|
||||||
|
|
||||||
|
# Export compile commands used for custom targets
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
# Load cmake utility functions
|
# Load cmake utility functions
|
||||||
include(cmake/utils.cmake)
|
include(cmake/utils.cmake)
|
||||||
|
|
||||||
# Warn if using an unsupported compiler
|
|
||||||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang)
|
|
||||||
message_colored(WARNING "Unsupported compiler!" 31)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Set default build type if not specified
|
# Set default build type if not specified
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
message_colored(STATUS "No build type specified; using Release" 33)
|
message_colored(STATUS "No build type specified; using Release" 33)
|
||||||
set(CMAKE_BUILD_TYPE "Release")
|
set(CMAKE_BUILD_TYPE "Release")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Export compile commands used for custom targets
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
|
|
||||||
# Generic compiler flags
|
# Generic compiler flags
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
|
||||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
||||||
|
|
||||||
# Debug specific compiler flags
|
# Debug specific compiler flags
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic-errors")
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror")
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
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} -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
|
# Release specific compiler flags
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||||
|
|
||||||
# Generic linker flags
|
# Compiler specific flags
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi")
|
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()
|
||||||
|
|
||||||
# Project settings {{{
|
# Project settings {{{
|
||||||
|
|
||||||
@ -123,6 +136,13 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
|
|||||||
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||||
message(STATUS " + relwithdebinfo flags:: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
message(STATUS " + relwithdebinfo flags:: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
||||||
endif()
|
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 "---------------------------")
|
||||||
message(STATUS " Build testsuite ${BUILD_TESTS}")
|
message(STATUS " Build testsuite ${BUILD_TESTS}")
|
||||||
message(STATUS " Enable ccache support ${ENABLE_CCACHE}")
|
message(STATUS " Enable ccache support ${ENABLE_CCACHE}")
|
||||||
|
@ -460,4 +460,4 @@ class builder {
|
|||||||
int m_fontindex = 1;
|
int m_fontindex = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
LEMONBUDDY_NS_END;
|
LEMONBUDDY_NS_END
|
||||||
|
@ -33,11 +33,7 @@ namespace command_line {
|
|||||||
*/
|
*/
|
||||||
explicit option(
|
explicit option(
|
||||||
string flag, string flag_long, string desc, string token = "", const choices c = {})
|
string flag, string flag_long, string desc, string token = "", const choices c = {})
|
||||||
: flag(flag)
|
: flag(flag), flag_long(flag_long), desc(desc), token(token), values(c) {}
|
||||||
, flag_long(flag_long)
|
|
||||||
, desc(desc)
|
|
||||||
, token(token)
|
|
||||||
, values(c) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
@ -101,7 +97,7 @@ namespace command_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto& opt : m_opts) {
|
for (auto& opt : m_opts) {
|
||||||
int pad = maxlen - opt.flag_long.length() - opt.token.length();
|
size_t pad = maxlen - opt.flag_long.length() - opt.token.length();
|
||||||
|
|
||||||
std::cout << " " << opt.flag << ", " << opt.flag_long;
|
std::cout << " " << opt.flag << ", " << opt.flag_long;
|
||||||
|
|
||||||
|
@ -563,7 +563,6 @@ namespace {
|
|||||||
di::injector<T> configure_controller(inotify_watch_t& confwatch) {
|
di::injector<T> configure_controller(inotify_watch_t& confwatch) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
return di::make_injector(
|
return di::make_injector(
|
||||||
di::bind<controller>().to<controller>(),
|
|
||||||
di::bind<>().to(confwatch),
|
di::bind<>().to(confwatch),
|
||||||
configure_connection(),
|
configure_connection(),
|
||||||
configure_logger(),
|
configure_logger(),
|
||||||
|
@ -128,14 +128,14 @@ class logger {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
decltype(auto) convert(T&& arg) const {
|
decltype(auto) convert(T&& arg) const {
|
||||||
return forward<T>(arg);
|
return forward<T>(arg);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert string to const char*
|
* Convert string to const char*
|
||||||
*/
|
*/
|
||||||
const char* convert(string arg) const {
|
const char* convert(string arg) const {
|
||||||
return arg.c_str();
|
return arg.c_str();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the log message to the output channel
|
* Write the log message to the output channel
|
||||||
@ -150,10 +150,14 @@ class logger {
|
|||||||
auto suffix = m_suffixes.find(level)->second;
|
auto suffix = m_suffixes.find(level)->second;
|
||||||
|
|
||||||
// silence the compiler
|
// silence the compiler
|
||||||
|
#if defined(__clang__)
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wformat-security"
|
#pragma clang diagnostic ignored "-Wformat-security"
|
||||||
|
#endif
|
||||||
dprintf(m_fd, (prefix + format + suffix + "\n").c_str(), convert(values)...);
|
dprintf(m_fd, (prefix + format + suffix + "\n").c_str(), convert(values)...);
|
||||||
|
#if defined(__clang__)
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -56,7 +56,7 @@ struct bar_settings {
|
|||||||
};
|
};
|
||||||
snprintf(buffer, sizeof(buffer), "%dx%d+%d+%d", width, height, x, y);
|
snprintf(buffer, sizeof(buffer), "%dx%d+%d+%d", width, height, x, y);
|
||||||
return string{*buffer};
|
return string{*buffer};
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tray_settings {
|
struct tray_settings {
|
||||||
@ -105,7 +105,6 @@ struct action_block {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wmsettings_bspwm {
|
struct wmsettings_bspwm {};
|
||||||
};
|
|
||||||
|
|
||||||
LEMONBUDDY_NS_END
|
LEMONBUDDY_NS_END
|
||||||
|
@ -7,21 +7,16 @@
|
|||||||
|
|
||||||
LEMONBUDDY_NS
|
LEMONBUDDY_NS
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
|
|
||||||
|
|
||||||
union rgba {
|
union rgba {
|
||||||
struct {
|
struct {
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
uint8_t g;
|
uint8_t g;
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
uint8_t a;
|
uint8_t a;
|
||||||
};
|
} _;
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
|
|
||||||
static map<string, class color> g_colorstore;
|
static map<string, class color> g_colorstore;
|
||||||
|
|
||||||
class color {
|
class color {
|
||||||
@ -29,9 +24,9 @@ class color {
|
|||||||
explicit color(string hex) : m_hex(string_util::upper(hex)) {
|
explicit color(string hex) : m_hex(string_util::upper(hex)) {
|
||||||
m_rgba.v = static_cast<uint32_t>(strtoul(&hex[1], nullptr, 16));
|
m_rgba.v = static_cast<uint32_t>(strtoul(&hex[1], nullptr, 16));
|
||||||
// premultiply alpha
|
// premultiply alpha
|
||||||
m_rgba.r = m_rgba.r * m_rgba.a / 255;
|
m_rgba._.r = m_rgba._.r * m_rgba._.a / 255;
|
||||||
m_rgba.g = m_rgba.g * m_rgba.a / 255;
|
m_rgba._.g = m_rgba._.g * m_rgba._.a / 255;
|
||||||
m_rgba.b = m_rgba.b * m_rgba.a / 255;
|
m_rgba._.b = m_rgba._.b * m_rgba._.a / 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit color(uint32_t v) {
|
explicit color(uint32_t v) {
|
||||||
|
@ -25,7 +25,7 @@ namespace draw_util {
|
|||||||
* Code: http://wmdia.sourceforge.net/
|
* Code: http://wmdia.sourceforge.net/
|
||||||
*/
|
*/
|
||||||
auto xcb_poly_text_16_patched(xcb_connection_t* conn, xcb_drawable_t d, xcb_gcontext_t gc,
|
auto xcb_poly_text_16_patched(xcb_connection_t* conn, xcb_drawable_t d, xcb_gcontext_t gc,
|
||||||
int16_t x, int16_t y, uint32_t len, uint16_t* str) {
|
int16_t x, int16_t y, uint8_t len, uint16_t* str) {
|
||||||
static const xcb_protocol_request_t xcb_req = {
|
static const xcb_protocol_request_t xcb_req = {
|
||||||
5, // count
|
5, // count
|
||||||
0, // ext
|
0, // ext
|
||||||
|
@ -120,7 +120,7 @@ namespace inotify_util {
|
|||||||
inline auto make_watch(string path) {
|
inline auto make_watch(string path) {
|
||||||
di::injector<inotify_watch_t> injector = di::make_injector(di::bind<>().to(path));
|
di::injector<inotify_watch_t> injector = di::make_injector(di::bind<>().to(path));
|
||||||
return injector.create<inotify_watch_t>();
|
return injector.create<inotify_watch_t>();
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LEMONBUDDY_NS_END
|
LEMONBUDDY_NS_END
|
||||||
|
@ -35,7 +35,7 @@ namespace scope_util {
|
|||||||
template <typename Fn = function<void()>, typename... Args>
|
template <typename Fn = function<void()>, typename... Args>
|
||||||
decltype(auto) make_exit_handler(Fn&& fn, Args&&... args) {
|
decltype(auto) make_exit_handler(Fn&& fn, Args&&... args) {
|
||||||
return make_unique<on_exit<Args...>>(forward<Fn>(fn), forward<Args>(args)...);
|
return make_unique<on_exit<Args...>>(forward<Fn>(fn), forward<Args>(args)...);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LEMONBUDDY_NS_END
|
LEMONBUDDY_NS_END
|
||||||
|
@ -59,7 +59,7 @@ namespace string_util {
|
|||||||
for (size_t i = 0; i < haystack.length(); i++) {
|
for (size_t i = 0; i < haystack.length(); i++) {
|
||||||
if (haystack.compare(i, needle.length(), needle) == 0) {
|
if (haystack.compare(i, needle.length(), needle) == 0) {
|
||||||
replaced += replacement;
|
replaced += replacement;
|
||||||
i += needle.length()-1;
|
i += needle.length() - 1;
|
||||||
} else {
|
} else {
|
||||||
replaced += haystack[i];
|
replaced += haystack[i];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user