Google Benchmark как зависимость cmake - PullRequest
2 голосов
/ 11 ноября 2019

Я пытаюсь скомпилировать бенчмарк Google с зависимостью от библиотеки Libtorch (Pytorch). Я установил Google Benchmark с make install, поэтому, насколько я понимаю, я могу использовать find_package (), чтобы добавить обе зависимости. Наконец, я добавляю несколько флагов компилятора.

Вот мой CMakeLists.txt:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(learned_b VERSION 1.0)
add_executable(PROJECT_NAME learned_benchmark.cpp)

find_package(Torch REQUIRED)
find_package(benchmark REQUIRED)
target_link_libraries(PROJECT_NAME "${TORCH_LIBRARIES}")
target_include_directories(PROJECT_NAME PUBLIC "${benchmark_INCLUDE_DIRS}")
target_link_libraries(PROJECT_NAME "${benchmark_LIBRARIES}")

SET(GCC_LINK_FLAGS    "-isystem /Users/yhr/Programs/benchmark/include -lbenchmark -pthread")
SET(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS}")
set_property(TARGET PROJECT_NAME PROPERTY CXX_STANDARD 11)

Следует отметить, что с GCC_LINK_FLAGS и без него я всегда получаю фатальную ошибку: 'benchmark /Файл benchmark.h 'не найден. Мой код компилировался и работал, когда он зависел только от Pytorch. Можно ли использовать find_package с тестом Google? Если нет, то как я могу сделать это правильно?

РЕДАКТИРОВАТЬ 1:

вот команды, которые я выполнил.

$ cd build
$ cmake -DCMAKE_PREFIX_PATH='/Users/yhr/Programs/libtorch;/Users/yhr/Programs/benchmark' ..
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter
 $ cd ..
 $ make VERBOSE=1
/usr/local/Cellar/cmake/3.15.4/bin/cmake -S/Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter -B/Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.15.4/bin/cmake -E cmake_progress_start /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter/CMakeFiles /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/PROJECT_NAME.dir/build.make CMakeFiles/PROJECT_NAME.dir/depend
cd /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter && /usr/local/Cellar/cmake/3.15.4/bin/cmake -E cmake_depends "Unix Makefiles" /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter/CMakeFiles/PROJECT_NAME.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/PROJECT_NAME.dir/build.make CMakeFiles/PROJECT_NAME.dir/build
[ 50%] Building CXX object CMakeFiles/PROJECT_NAME.dir/learned_benchmark.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -DAT_PARALLEL_OPENMP=1 -D_THP_CORE -I/Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter -isystem /Users/yhr/programs/libtorch/include -isystem /Users/yhr/programs/libtorch/include/torch/csrc/api/include  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.14   -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-write-strings -Wno-unknown-pragmas -Wno-missing-braces -std=gnu++11 -o CMakeFiles/PROJECT_NAME.dir/learned_benchmark.cpp.o -c /Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter/learned_benchmark.cpp
/Users/yhr/Programs/learnedbloomfilters/OpenBloomFilter/learned_benchmark.cpp:4:10: fatal error: 'benchmark/benchmark.h' file not found
#include <benchmark/benchmark.h>
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/PROJECT_NAME.dir/learned_benchmark.cpp.o] Error 1
make[1]: *** [CMakeFiles/PROJECT_NAME.dir/all] Error 2
make: *** [all] Error 2
...