@@ -15,44 +15,91 @@ option(WITH_OTLP "Whether to include the OpenTelemetry Protocol in the SDK" OFF)
1515option (WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK"
1616 OFF )
1717
18- option (WITH_TESTS "Whether to enable tests" ON )
18+ option (BUILD_TESTING "Whether to enable tests" ON )
1919option (WITH_EXAMPLES "Whether to build examples" ON )
2020
2121set (WITH_PROTOBUF OFF )
22- if (WITH_OTLP)
23- set (WITH_PROTOBUF ON )
24- endif ()
25-
26- if (WITH_TESTS)
27- include (CTest)
28- endif ()
2922
3023find_package (Threads)
3124
25+ function (install_windows_deps)
26+ # Bootstrap vcpkg from CMake and auto-install deps in case if we are missing
27+ # deps on Windows
28+ message ("Installing build tools and dependencies..." )
29+ execute_process (
30+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR} /tools/setup-buildtools.cmd)
31+ set (CMAKE_TOOLCHAIN_FILE
32+ ${CMAKE_CURRENT_SOURCE_DIR} /tools/vcpkg/scripts/buildsystems/vcpkg.cmake)
33+ endfunction ()
34+
3235if (MSVC )
3336 # Options for Visual C++ compiler: /Zc:__cplusplus - report an updated value
3437 # for recent C++ language standards. Without this option MSVC returns the
3538 # value of __cplusplus="199711L"
3639 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus" )
3740endif ()
3841
42+ if (WITH_OTLP)
43+ set (WITH_PROTOBUF ON )
44+ endif ()
45+
3946if (WITH_PROTOBUF)
4047 set (protobuf_MODULE_COMPATIBLE ON )
41- find_package (Protobuf CONFIG NAMES protobuf)
42- # Older versions of protobuf don't use cmake config files.
48+ find_package (Protobuf REQUIRED)
4349 if (NOT protobuf_FOUND)
50+ if (WIN32 )
51+ install_windows_deps()
52+ endif ()
4453 find_package (Protobuf REQUIRED)
54+ if (WIN32 )
55+ # Always use x64 protoc.exe
56+ if (NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE} " )
57+ set (Protobuf_PROTOC_EXECUTABLE
58+ ${CMAKE_CURRENT_SOURCE_DIR} /tools/vcpkg/packages/protobuf_x64-windows/tools/protobuf/protoc.exe
59+ )
60+ endif ()
61+ endif ()
62+ # Latest Protobuf uses mixed case instead of uppercase
63+ set (PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE} )
4564 endif ()
65+ message ("PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE} " )
4666endif ()
4767
4868if (WITH_OTLP)
49- include (third_party /opentelemetry-proto/Protobuf .cmake)
69+ include (cmake /opentelemetry-proto.cmake)
5070endif ()
5171
72+ list (APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR} " )
73+
5274if (BUILD_TESTING)
53- find_package (GTest REQUIRED)
54- find_package (benchmark REQUIRED)
75+ include (CTest)
76+ if (EXISTS ${CMAKE_BINARY_DIR} /lib/libgtest.a)
77+ # Prefer GTest from build tree. GTest is not always working with
78+ # CMAKE_PREFIX_PATH
79+ set (GTEST_INCLUDE_DIRS
80+ ${CMAKE_CURRENT_SOURCE_DIR} /third_party/googletest/googletest/include
81+ ${CMAKE_CURRENT_SOURCE_DIR} /third_party/googletest/googlemock/include )
82+ set (GTEST_BOTH_LIBRARIES
83+ ${CMAKE_BINARY_DIR} /lib/libgtest.a
84+ ${CMAKE_BINARY_DIR} /lib/libgtest_main.a
85+ ${CMAKE_BINARY_DIR} /lib/libgmock.a)
86+ elseif (WIN32 )
87+ # Make sure we are always bootsrapped with vcpkg on Windows
88+ find_package (GTest)
89+ if (NOT GTEST_FOUND)
90+ install_windows_deps()
91+ find_package (GTest REQUIRED)
92+ endif ()
93+ else ()
94+ # Prefer GTest installed by OS distro, brew or vcpkg package manager
95+ find_package (GTest REQUIRED)
96+ endif ()
5597 include_directories (SYSTEM ${GTEST_INCLUDE_DIRS} )
98+ message ("GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS} " )
99+ message ("GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES} " )
100+ enable_testing ()
101+ # Benchmark respects the CMAKE_PREFIX_PATH
102+ find_package (benchmark CONFIG REQUIRED)
56103endif ()
57104
58105include_directories (api/include )
0 commit comments