Skip to content

Commit

Permalink
Add -stub suffix to colour-names.cc
Browse files Browse the repository at this point in the history
Made CMake copy the file renamed in case gperf isn't available. This
should prevent the compiler from finding stub before generated file.

Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Apr 24, 2024
1 parent f34b5dd commit 5133193
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if(APP_GPERF)
)
else(APP_GPERF)
message(WARNING "'gperf' program not found, using stub colour-names.cc; colors names will not be parsed")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/colour-names-stub.cc" "${CMAKE_BINARY_DIR}/colour-names.cc" COPYONLY)
endif(APP_GPERF)

set(conky_sources
Expand Down
5 changes: 3 additions & 2 deletions src/colour-names.cc → src/colour-names-stub.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* To generate colour-names.cc, you must have gperf installed during build.
* This is a dummy implementation for builds without gperf.
* Color name matching will always return null (i.e. no match).
Expand All @@ -17,5 +17,6 @@ class color_name_hash {
};

const struct rgb *color_name_hash::in_word_set(const char *str, size_t len) {
return 0;
DBGP("color parsing not supported");
return nullptr;
}
12 changes: 4 additions & 8 deletions src/colours.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#include "logging.h"

#include <optional>

Colour Colour::from_argb32(uint32_t argb) {
Colour out;
out.alpha = argb >> 24;
Expand Down Expand Up @@ -111,14 +113,8 @@ Colour parse_color(const std::string &color) {
std::optional<Colour> value_##name = name(color); \
if (value_##name.has_value()) { return value_##name.value(); }

std::optional<Colour> value_parse_color_name = parse_color_name(color);
if (value_parse_color_name.has_value()) {
return value_parse_color_name.value();
}
std::optional<Colour> value_parse_hex_color = parse_hex_color(color);
if (value_parse_hex_color.has_value()) {
return value_parse_hex_color.value();
}
TRY_PARSER(parse_color_name)
TRY_PARSER(parse_hex_color)

#undef TRY_PARSER

Expand Down

0 comments on commit 5133193

Please sign in to comment.