Skip to content

Commit 9a75492

Browse files
committed
Use CMake to build libprotobuf and the C++ harness
This reuses some cmake logic from the protobuf dir, which isn't ideal, but at least CMake knows how to handle abseil. <whew!> Note: This now expects abseil and googletests to be already installed on the local system. A more ambitious setup here could potentially avoid that.
1 parent 6eefad2 commit 9a75492

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

Performance/runners/CMakeLists.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# cmake configuration file for building the C++ test harness
3+
#
4+
# This assumes you have a protobuf source checkout handy,
5+
# and have used `git submodule update` to obtain all the
6+
# related source repos.
7+
#
8+
# This script uses the protobuf sources to build libprotobuf and
9+
# statically links it into the test harness executable.
10+
# (This is probably not necessary; updates to this file to
11+
# use a better strategy would be appreciated.)
12+
#
13+
# Also assumes that you have abseil_cpp and googletest installed
14+
# locally via e.g.,
15+
# brew install googletest
16+
# brew install abseil
17+
#
18+
19+
cmake_minimum_required(VERSION 3.10...3.26)
20+
set(CMAKE_CXX_STANDARD 17)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
23+
24+
project(swiftprotobuf-perf C CXX)
25+
26+
# Update this with the appropriate path to the protobuf source
27+
# checkout, starting from the directory holding this file.
28+
# Default here assumes that `protobuf` is checked out beside
29+
# `swift-protobuf`
30+
set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../../../protobuf)
31+
set(protobuf_VERSION "999.999")
32+
33+
# Use protobuf cmake scripts to locate suitable abseil package:
34+
set(protobuf_ABSL_PROVIDER "package")
35+
include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake)
36+
37+
# Use protobuf cmake scripts for building libprotobuf
38+
include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake)
39+
40+
# Use utf8_range from protobuf checkout
41+
set(utf8_range_SOURCE_DIR ${protobuf_SOURCE_DIR}/third_party/utf8_range)
42+
add_subdirectory(${utf8_range_SOURCE_DIR} third_party/utf8_range)
43+
44+
include_directories(
45+
${protobuf_SOURCE_DIR}/src
46+
${utf8_range_SOURCE_DIR}
47+
)
48+
49+
add_executable(harness_cpp
50+
../main.cc
51+
../Harness.cc
52+
../_generated/Harness+Generated.cc
53+
../_generated/message.pb.cc
54+
)
55+
56+
target_include_directories(harness_cpp PRIVATE
57+
${CMAKE_SOURCE_DIR}
58+
${CMAKE_SOURCE_DIR}/..
59+
${ABSL_ROOT_DIR}
60+
${utf8_range_SOURCE_DIR}
61+
)
62+
63+
target_link_libraries(harness_cpp PRIVATE libprotobuf)

Performance/runners/cpp.sh

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,12 @@ function run_cpp_harness() {
2727
generate_cpp_harness
2828

2929
echo "Building C++ test harness..."
30-
time ( g++ --std=c++11 -O \
31-
-o "$harness" \
32-
-I "$script_dir" \
33-
-I "$GOOGLE_PROTOBUF_CHECKOUT/src" \
34-
-L "$GOOGLE_PROTOBUF_CHECKOUT/src/.libs" \
35-
-lprotobuf \
36-
"$gen_harness_path" \
37-
"$script_dir/Harness.cc" \
38-
"$script_dir/_generated/message.pb.cc" \
39-
"$script_dir/main.cc" \
40-
)
41-
echo
42-
43-
# Make sure the dylib is loadable from the harness if the user hasn't
44-
# actually installed them.
45-
cp "$GOOGLE_PROTOBUF_CHECKOUT"/src/.libs/libprotobuf.*.dylib \
46-
"$script_dir/_generated"
4730

31+
pushd $script_dir/runners
32+
cmake -B ../_generated -S .
33+
cmake --build ../_generated
34+
popd
35+
4836
run_harness_and_concatenate_results "C++" "$harness" "$partial_results"
4937
)
5038
}

0 commit comments

Comments
 (0)