fix(cmake): Make specific c++lib linking optional

- Do not enforce linking against libc++
- Fix various linter warnings
This commit is contained in:
Michael Carlberg 2016-10-25 20:14:44 +02:00
parent 27df2398f0
commit eac65cdabb
11 changed files with 55 additions and 42 deletions

View File

@ -4,47 +4,60 @@
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(lemonbuddy CXX)
option(CXXLIB_CLANG "Link against libc++" OFF)
option(CXXLIB_GCC "Link against stdlibc++" OFF)
# Include local 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
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
if(NOT CMAKE_BUILD_TYPE)
message_colored(STATUS "No build type specified; using Release" 33)
set(CMAKE_BUILD_TYPE "Release")
endif()
# Export compile commands used for custom targets
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Generic compiler flags
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} -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} -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} -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} -O2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
# Generic linker flags
# 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()
# Project settings {{{
@ -123,6 +136,13 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "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 ccache support ${ENABLE_CCACHE}")

View File

@ -460,4 +460,4 @@ class builder {
int m_fontindex = 1;
};
LEMONBUDDY_NS_END;
LEMONBUDDY_NS_END

View File

@ -33,11 +33,7 @@ namespace command_line {
*/
explicit option(
string flag, string flag_long, string desc, string token = "", const choices c = {})
: flag(flag)
, flag_long(flag_long)
, desc(desc)
, token(token)
, values(c) {}
: flag(flag), flag_long(flag_long), desc(desc), token(token), values(c) {}
};
// }}}
@ -101,7 +97,7 @@ namespace command_line {
}
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;

View File

@ -563,7 +563,6 @@ namespace {
di::injector<T> configure_controller(inotify_watch_t& confwatch) {
// clang-format off
return di::make_injector(
di::bind<controller>().to<controller>(),
di::bind<>().to(confwatch),
configure_connection(),
configure_logger(),

View File

@ -128,14 +128,14 @@ class logger {
template <typename T>
decltype(auto) convert(T&& arg) const {
return forward<T>(arg);
};
}
/**
* Convert string to const char*
*/
const char* convert(string arg) const {
return arg.c_str();
};
}
/**
* Write the log message to the output channel
@ -150,10 +150,14 @@ class logger {
auto suffix = m_suffixes.find(level)->second;
// silence the compiler
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
#endif
dprintf(m_fd, (prefix + format + suffix + "\n").c_str(), convert(values)...);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
private:

View File

@ -56,7 +56,7 @@ struct bar_settings {
};
snprintf(buffer, sizeof(buffer), "%dx%d+%d+%d", width, height, x, y);
return string{*buffer};
};
}
};
struct tray_settings {
@ -105,7 +105,6 @@ struct action_block {
#endif
};
struct wmsettings_bspwm {
};
struct wmsettings_bspwm {};
LEMONBUDDY_NS_END

View File

@ -7,21 +7,16 @@
LEMONBUDDY_NS
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
union rgba {
struct {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
} _;
uint32_t v;
};
#pragma clang diagnostic pop
static map<string, class color> g_colorstore;
class color {
@ -29,9 +24,9 @@ class color {
explicit color(string hex) : m_hex(string_util::upper(hex)) {
m_rgba.v = static_cast<uint32_t>(strtoul(&hex[1], nullptr, 16));
// premultiply alpha
m_rgba.r = m_rgba.r * 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._.r = m_rgba._.r * m_rgba._.a / 255;
m_rgba._.g = m_rgba._.g * m_rgba._.a / 255;
m_rgba._.b = m_rgba._.b * m_rgba._.a / 255;
}
explicit color(uint32_t v) {

View File

@ -25,7 +25,7 @@ namespace draw_util {
* Code: http://wmdia.sourceforge.net/
*/
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 = {
5, // count
0, // ext

View File

@ -120,7 +120,7 @@ namespace inotify_util {
inline auto make_watch(string path) {
di::injector<inotify_watch_t> injector = di::make_injector(di::bind<>().to(path));
return injector.create<inotify_watch_t>();
};
}
}
LEMONBUDDY_NS_END

View File

@ -35,7 +35,7 @@ namespace scope_util {
template <typename Fn = function<void()>, typename... Args>
decltype(auto) make_exit_handler(Fn&& fn, Args&&... args) {
return make_unique<on_exit<Args...>>(forward<Fn>(fn), forward<Args>(args)...);
};
}
}
LEMONBUDDY_NS_END