In all honesty I couldn’t get CMake to find the GoogleTest libraries even though I did the local install, and installed in Ubuntu, or using Google’s own instructions. Hopefully someone has better instructions, it’s been on the roadmap to document this.
What I did is install gtest locally on Ubuntu: sudo apt install libgtest-dev
. You can also follow this guide.
Then remove the GTest requirement in CMakeLists.txt
because it can’t seem to find gtest regardless:
# Test
if(GOOGLE_TEST)
enable_testing()
# Disable this because I couldn't get it to find the libraries
# find_package(GTest REQUIRED)
auto_source_group("${TEST_SOURCES}")
include_directories(${GTEST_INCLUDE_DIRS})
if(USE_CUDA)
file(GLOB_RECURSE CUDA_TEST_SOURCES "tests/cpp/*.cu")
cuda_compile(CUDA_TEST_OBJS ${CUDA_TEST_SOURCES})
else()
set(CUDA_TEST_OBJS "")
endif()
add_executable(testxgboost ${TEST_SOURCES} ${CUDA_TEST_OBJS} $<TARGET_OBJECTS:objxgboost>)
set_output_directory(testxgboost ${PROJECT_SOURCE_DIR})
# Add gtest manually, the variable is no longer available
target_link_libraries(testxgboost gtest ${LINK_LIBRARIES})
add_test(TestXGBoost testxgboost)
endif()
Then you can run make testxgboost
in your cmake build directory and run the tests using ../testxgboost
. That is, after you’ve installed Gtest and made the changes to CMakeLists.txt:
mkdir build
cd build
cmake -DGOOGLE_TEST=ON ..
make -j4 testxgboost
../testxgboost