问题
I am trying to build google-benchmark and use it with my library using cmake. I have managed to build google-benchmark and run all its tests successfully using cmake. I am unfortunately unable to link it properly with my c++ code in windows using cmake or cl.
the problem I think is that google-benchmark builds the library inside the src folder, i.e it is build in src/Release/benchmark.lib now i cannot point to it in cmake if I use ${benchmark_LIBRARIES} it looks for the library in the Release folder outside src, as this is the usual place all the libraries are build. and it is difficult to find examples which work in windows.
here are two ways which I have tried, both can build the library and all the tests run but I cannot point to the library to target_link_library properly
include(ExternalProject)
ExternalProject_Add(googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG master
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build"
CONFIGURE_COMMAND ${CMAKE_COMMAND} -B ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build -S ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON
BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build --config Release
INSTALL_COMMAND ""
TEST_COMMAND ${CMAKE_CTEST_COMMAND} ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build --build-config Release
)
and
ExternalProject_Add(googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG master
PREFIX googlebenchmark
CMAKE_ARGS -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release
INSTALL_COMMAND ""
TEST_COMMAND ${CMAKE_CTEST_COMMAND} --build-config Release
)
how do i link it to my c++ file try.cpp after this
来源:https://stackoverflow.com/questions/55376111/how-to-build-and-link-google-benchmark-using-cmake-in-windows