Skip to content

Commit

Permalink
Force CMake targets to use c++ std 14 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
techbech authored Oct 6, 2023
1 parent 603f7f7 commit 40e10fe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
19 changes: 11 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ include_guard(GLOBAL)

find_package(Python COMPONENTS Interpreter)

set(CMAKE_CXX_STANDARD 14)

# Use waf to resolve dependencies
if (NOT DEFINED STEINWURF_RESOLVE)
message(STATUS "Resolving dependencies...")
Expand All @@ -23,14 +21,17 @@ endif ()

# Abseil
file(GLOB_RECURSE sw_protobuf_abseil_sources ${STEINWURF_RESOLVE}/protobuf-source/third_party/abseil-cpp/absl/**/*.cc)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_test_.*\.cc)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_test\.cc)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/test_.*\.cc)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*testing.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_benchmark.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*benchmark.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*mock.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*test_.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_test.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*mock_.*)
list(FILTER sw_protobuf_abseil_sources EXCLUDE REGEX .*absl\/.*\/.*_mock_.*)

message(STATUS "Abseil sources: ${sw_protobuf_abseil_sources}")

add_library(sw_protobuf_abseil STATIC ${sw_protobuf_abseil_sources})
target_compile_features(sw_protobuf_abseil PUBLIC cxx_std_14)
target_include_directories(sw_protobuf_abseil PUBLIC ${STEINWURF_RESOLVE}/protobuf-source/third_party/abseil-cpp)

if (APPLE)
Expand All @@ -44,18 +45,20 @@ file(GLOB_RECURSE sw_protobuf_utf8_range_sources
list(FILTER sw_protobuf_utf8_range_sources EXCLUDE REGEX .*test\.cc)

add_library(sw_protobuf_utf8_range STATIC ${sw_protobuf_utf8_range_sources})
target_compile_features(sw_protobuf_utf8_range PUBLIC cxx_std_14)
target_link_libraries(sw_protobuf_utf8_range PRIVATE sw_protobuf_abseil)
target_include_directories(sw_protobuf_utf8_range PUBLIC ${STEINWURF_RESOLVE}/protobuf-source/third_party/utf8_range)

if (DEFINED MSVC)
target_compile_options(sw_protobuf_abseil PRIVATE /DNOMINMAX)
target_compile_options(sw_protobuf_abseil PRIVATE "/DNOMINMAX")
endif ()

file(GLOB_RECURSE sw_protobuf_sources ${STEINWURF_RESOLVE}/protobuf-source/src/google/**/*.cc)
list(FILTER sw_protobuf_sources EXCLUDE REGEX .*src/google/protobuf\/compiler\/.*)
list(FILTER sw_protobuf_sources EXCLUDE REGEX .*src/google/protobuf\/.*test.*)

add_library(sw_protobuf STATIC ${sw_protobuf_sources})
target_compile_features(sw_protobuf PUBLIC cxx_std_14)
target_link_libraries(sw_protobuf PUBLIC sw_protobuf_abseil sw_protobuf_utf8_range)
target_include_directories(sw_protobuf PUBLIC ${STEINWURF_RESOLVE}/protobuf-source/src)

Expand Down
2 changes: 1 addition & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ every change, see the Git log.

Latest
------
* tbd
* Patch: Force CMake targets to use c++ std 14.

2.0.3
-----
Expand Down
30 changes: 26 additions & 4 deletions test/cpp/test_synopsis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@

TEST(test_synopsis, api)
{
auto t = protobuf::Metrics();
t.set_protocol_version(1);
auto m = protobuf::Metrics();
m.set_protocol_version(1);

auto metric = m.add_metric();
auto info = metric->mutable_info();
info->set_kind(protobuf::Kind::COUNTER);
info->set_name("metric0");
info->set_description("An unsigned integer metric");
info->set_unit("bytes");

info->set_type(protobuf::Type::UINT64);
metric->set_uint64_value(42);
info->set_type(protobuf::Type::INT64);
metric->set_int64_value(-42);
info->set_type(protobuf::Type::FLOAT64);
metric->set_float64_value(123.f);
info->set_type(protobuf::Type::BOOL);
metric->set_bool_value(true);

std::string json;
auto msg = google::protobuf::util::MessageToJsonString(t, &json);
EXPECT_TRUE(msg.ok());
auto status = google::protobuf::util::MessageToJsonString(m, &json);
EXPECT_TRUE(status.ok());

google::protobuf::util::JsonParseOptions options;
auto m2 = protobuf::Metrics();
options.ignore_unknown_fields = false;
status = google::protobuf::util::JsonStringToMessage(json, &m2, options);
EXPECT_TRUE(status.ok());
}

0 comments on commit 40e10fe

Please sign in to comment.