Skip to content

Commit

Permalink
[BUILD] Fixing CMake to build GTest on Windows (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachittle authored May 26, 2023
1 parent 5e290c9 commit 3707bc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,12 @@ function(install_windows_deps)
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/setup-buildtools.cmd)
set(CMAKE_TOOLCHAIN_FILE
${CMAKE_CURRENT_SOURCE_DIR}/tools/vcpkg/scripts/buildsystems/vcpkg.cmake
PARENT_SCOPE)
CACHE FILEPATH "")
message(
"Make sure that vcpkg.cmake is set as the CMAKE_TOOLCHAIN_FILE at the START of the cmake build process!
Can be command-line arg (cmake -DCMAKE_TOOLCHAIN_FILE=...) or set in your editor of choice."
)

endfunction()

function(set_target_version target_name)
Expand Down Expand Up @@ -548,9 +553,10 @@ if(BUILD_TESTING)
${CMAKE_BINARY_DIR}/lib/libgmock.a)
elseif(WIN32)
# Make sure we are always bootsrapped with vcpkg on Windows
find_package(GTest REQUIRED)
find_package(GTest)
if(NOT (GTEST_FOUND OR GTest_FOUND))
install_windows_deps()
include(${CMAKE_TOOLCHAIN_FILE})
find_package(GTest REQUIRED)
endif()
else()
Expand Down
4 changes: 2 additions & 2 deletions test_common/src/http/client/nosend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(${BUILD_TESTING})
endif()

target_link_libraries(
opentelemetry_http_client_nosend ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIB}
opentelemetry_ext opentelemetry_test_common)
opentelemetry_http_client_nosend ${GTEST_BOTH_LIBRARIES} opentelemetry_ext
opentelemetry_test_common)

endif()
4 changes: 1 addition & 3 deletions tools/setup-buildtools.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if defined VCPKG_ROOT (
set "PATH=%VCPKG_ROOT%;%PATH%"
) else (
set "PATH=%~dp0vcpkg;%PATH%"
set "VCPKG_ROOT=%~dp0vcpkg"
)
pushd %~dp0

Expand Down Expand Up @@ -53,9 +54,6 @@ where /Q vcpkg.exe
if %ERRORLEVEL% == 1 (
REM Build our own vcpkg from source
REM Prefer building in VCPKG_ROOT
if not defined VCPKG_ROOT (
set "VCPKG_ROOT=%~dp0\vcpkg"
)
pushd "!VCPKG_ROOT!"
call bootstrap-vcpkg.bat
popd
Expand Down

0 comments on commit 3707bc0

Please sign in to comment.