diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d7cf3dda..ec512ea35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ configure_file(${CMAKE_MODULE_PATH}/build.h.in ${CMAKE_BINARY_DIR}/build.h) set(conky_sources ${CMAKE_BINARY_DIR}/config.h ${CMAKE_BINARY_DIR}/build.h) # Finally, add some code +add_subdirectory(lua) add_subdirectory(data) add_subdirectory(doc) @@ -67,8 +68,6 @@ endif() add_subdirectory(src) -add_subdirectory(lua) - if(BUILD_TESTS) add_subdirectory(tests) enable_testing() diff --git a/lua/CMakeLists.txt b/lua/CMakeLists.txt index 6dbaa1bca..19b02a5a1 100644 --- a/lua/CMakeLists.txt +++ b/lua/CMakeLists.txt @@ -72,7 +72,7 @@ if(BUILD_LUA_IMLIB2) add_library(conky-imlib2 MODULE ${luaimlib2_src}) set_target_properties(conky-imlib2 PROPERTIES OUTPUT_NAME "imlib2") - target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static ) + target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static) set(lua_libs ${lua_libs} conky-imlib2) print_target_properties(conky-imlib2) @@ -83,16 +83,14 @@ if(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2) ${CMAKE_CURRENT_SOURCE_DIR}) wrap_tolua(luacairo_imlib2_helper_src cairo_imlib2_helper.pkg) - set(imlib_helper_libs ${luacairo_libs} ${luaimlib2_libs} toluapp_lib_static) - # if(BUILD_I18N) - # set(imlib_helper_libs ${imlib_helper_libs} -lintl) - # endif() - add_library(conky-cairo_imlib2_helper MODULE ${luacairo_imlib2_helper_src}) set_target_properties(conky-cairo_imlib2_helper PROPERTIES OUTPUT_NAME "cairo_imlib2_helper") - target_link_libraries(conky-cairo_imlib2_helper ${imlib_helper_libs}) + target_link_libraries(conky-cairo_imlib2_helper + ${luacairo_libs} + ${luaimlib2_libs} + toluapp_lib_static) set(lua_libs ${lua_libs} conky-cairo_imlib2_helper) endif(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2) diff --git a/lua/libcairo_imlib2_helper.h b/lua/libcairo_imlib2_helper.h index 45bffd775..d1571cc29 100644 --- a/lua/libcairo_imlib2_helper.h +++ b/lua/libcairo_imlib2_helper.h @@ -36,8 +36,11 @@ #define gettext #endif -#define NORM_ERR(Format, ...) \ - fprintf(stderr, gettext(Format), ##__VA_ARGS__); +// TODO: inject reference to conky logger +// Lua allows modifying .so loading, so for each loaded library check if it has +// some hardcoded set_logger function symbol, and call it to set per-library +// reference to the global logger. +#define NORM_ERR(Format, ...) fprintf(stderr, gettext(Format), ##__VA_ARGS__); void cairo_place_image(const char *file, cairo_t *cr, int x, int y, int width, int height, double alpha) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d36f4dbc2..cd1b68f0a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,6 +64,7 @@ execute_process( set(conky_sources ${conky_sources} + logging.cc c++wrap.cc c++wrap.hh colour-settings.cc diff --git a/src/darwin.mm b/src/darwin.mm index 448816ca2..52611decc 100644 --- a/src/darwin.mm +++ b/src/darwin.mm @@ -87,11 +87,8 @@ #include #endif -/* debugging defines */ -#undef NDEBUG - /* (E)nhanced printf */ -#ifndef NDEBUG +#if true // ifdef NDEBUG #include void eprintf(const char *fmt, ...) { va_list args; diff --git a/src/logger.hh b/src/logger.hh index 25e570798..75c54cbac 100644 --- a/src/logger.hh +++ b/src/logger.hh @@ -43,6 +43,7 @@ #include #include #include +#include #include #include diff --git a/src/logging.cc b/src/logging.cc new file mode 100644 index 000000000..56a6aeb34 --- /dev/null +++ b/src/logging.cc @@ -0,0 +1,3 @@ +#include "logging.h" + +conky::log::logger DEFAULT_LOGGER("conky"); diff --git a/src/logging.h b/src/logging.h index 6ae76c841..d90c4d2a2 100644 --- a/src/logging.h +++ b/src/logging.h @@ -32,6 +32,8 @@ #include "logger.hh" +#include + class fork_throw : public std::runtime_error { public: fork_throw() : std::runtime_error("Fork happened") {} @@ -92,9 +94,9 @@ namespace _priv_error_print { template inline std::string alloc_printf(const char *format, Args &&...args) { auto size = std::snprintf(nullptr, 0, format, args...); - std::string output(size + 1, '\0'); - std::sprintf(&output[0], format, args...); - return output; + char output[size + 1]; + std::snprintf(output, sizeof(output), format, args...); + return std::string(&output[0]); } inline std::string alloc_printf(const char *format) { return std::string(format); @@ -103,6 +105,10 @@ inline std::string alloc_printf(const char *format) { class error : public std::runtime_error { public: + /// @brief Construct a new error object. + /// + /// @param Msg Already localized error message. + error(const std::string &msg) : std::runtime_error(msg) {} error(const char *msg) : std::runtime_error(_(msg)) {} template error(const char *format, Args &&...args) diff --git a/src/main.cc b/src/main.cc index 16bda45cf..0e584e713 100644 --- a/src/main.cc +++ b/src/main.cc @@ -281,8 +281,6 @@ inline void reset_optind() { #endif } -conky::log::logger DEFAULT_LOGGER("conky"); - int main(int argc, char **argv) { std::set_terminate(&handle_terminate);