Remove redundant FindGTest.cmake. (#3533)

During removal of FindGTest.cmake, also

* Fix gtest include dirs.
* Remove some blanks and use PWD for gtest dir.
This commit is contained in:
trivialfis 2018-08-07 06:08:08 +08:00 committed by Rory Mitchell
parent 69454d9487
commit 55caad6e49
4 changed files with 15 additions and 93 deletions

View File

@ -8,9 +8,9 @@ set_default_configuration_release()
msvc_use_static_runtime() msvc_use_static_runtime()
# Options # Options
option(USE_CUDA "Build with GPU acceleration") option(USE_CUDA "Build with GPU acceleration")
option(USE_AVX "Build with AVX instructions. May not produce identical results due to approximate math." OFF) option(USE_AVX "Build with AVX instructions. May not produce identical results due to approximate math." OFF)
option(USE_NCCL "Build using NCCL for multi-GPU. Also requires USE_CUDA") option(USE_NCCL "Build using NCCL for multi-GPU. Also requires USE_CUDA")
option(JVM_BINDINGS "Build JVM bindings" OFF) option(JVM_BINDINGS "Build JVM bindings" OFF)
option(GOOGLE_TEST "Build google tests" OFF) option(GOOGLE_TEST "Build google tests" OFF)
option(R_LIB "Build shared library for R package" OFF) option(R_LIB "Build shared library for R package" OFF)
@ -89,7 +89,7 @@ include_directories (
${PROJECT_SOURCE_DIR}/rabit/include ${PROJECT_SOURCE_DIR}/rabit/include
) )
file(GLOB_RECURSE SOURCES file(GLOB_RECURSE SOURCES
src/*.cc src/*.cc
src/*.h src/*.h
include/*.h include/*.h
@ -127,7 +127,7 @@ if(USE_CUDA)
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
add_definitions(-DXGBOOST_USE_CUDA) add_definitions(-DXGBOOST_USE_CUDA)
include_directories(cub) include_directories(cub)
if(USE_NCCL) if(USE_NCCL)
@ -146,12 +146,12 @@ if(USE_CUDA)
endif() endif()
cuda_add_library(gpuxgboost ${CUDA_SOURCES} STATIC) cuda_add_library(gpuxgboost ${CUDA_SOURCES} STATIC)
if(USE_NCCL) if(USE_NCCL)
link_directories(${NCCL_LIBRARY}) link_directories(${NCCL_LIBRARY})
target_link_libraries(gpuxgboost ${NCCL_LIB_NAME}) target_link_libraries(gpuxgboost ${NCCL_LIB_NAME})
endif() endif()
list(APPEND LINK_LIBRARIES gpuxgboost) list(APPEND LINK_LIBRARIES gpuxgboost)
endif() endif()
@ -232,12 +232,12 @@ endif()
# Test # Test
if(GOOGLE_TEST) if(GOOGLE_TEST)
find_package(GTest REQUIRED)
enable_testing() enable_testing()
find_package(GTest REQUIRED)
file(GLOB_RECURSE TEST_SOURCES "tests/cpp/*.cc") file(GLOB_RECURSE TEST_SOURCES "tests/cpp/*.cc")
auto_source_group("${TEST_SOURCES}") auto_source_group("${TEST_SOURCES}")
include_directories(${GTEST_INCLUDE_DIR}) include_directories(${GTEST_INCLUDE_DIRS})
if(USE_CUDA) if(USE_CUDA)
file(GLOB_RECURSE CUDA_TEST_SOURCES "tests/cpp/*.cu") file(GLOB_RECURSE CUDA_TEST_SOURCES "tests/cpp/*.cu")

View File

@ -1,79 +0,0 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Tries to find GTest headers and libraries.
#
# Usage of this module as follows:
#
# find_package(GTest)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# GTest_HOME - When set, this path is inspected instead of standard library
# locations as the root of the GTest installation.
# The environment variable GTEST_HOME overrides this veriable.
#
# This module defines
# GTEST_INCLUDE_DIR, directory containing headers
# GTEST_LIBS, directory containing gtest libraries
# GTEST_STATIC_LIB, path to libgtest.a
# GTEST_SHARED_LIB, path to libgtest's shared library
# GTEST_FOUND, whether gtest has been found
find_path(GTEST_INCLUDE_DIR NAMES gtest/gtest.h gtest.h PATHS ${CMAKE_SOURCE_DIR}/gtest/include NO_DEFAULT_PATH)
find_library(GTEST_LIBRARIES NAMES gtest PATHS ${CMAKE_SOURCE_DIR}/gtest/lib NO_DEFAULT_PATH)
if (GTEST_INCLUDE_DIR )
message(STATUS "Found the GTest includes: ${GTEST_INCLUDE_DIR}")
endif ()
if (GTEST_INCLUDE_DIR AND GTEST_LIBRARIES)
set(GTEST_FOUND TRUE)
get_filename_component( GTEST_LIBS ${GTEST_LIBRARIES} PATH )
set(GTEST_LIB_NAME gtest)
set(GTEST_STATIC_LIB ${GTEST_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${GTEST_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_MAIN_STATIC_LIB ${GTEST_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${GTEST_LIB_NAME}_main${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_SHARED_LIB ${GTEST_LIBS}/${CMAKE_SHARED_LIBRARY_PREFIX}${GTEST_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
else ()
set(GTEST_FOUND FALSE)
endif ()
if (GTEST_FOUND)
if (NOT GTest_FIND_QUIETLY)
message(STATUS "Found the GTest library: ${GTEST_LIBRARIES}")
endif ()
else ()
if (NOT GTest_FIND_QUIETLY)
set(GTEST_ERR_MSG "Could not find the GTest library. Looked in ")
if ( _gtest_roots )
set(GTEST_ERR_MSG "${GTEST_ERR_MSG} in ${_gtest_roots}.")
else ()
set(GTEST_ERR_MSG "${GTEST_ERR_MSG} system search paths.")
endif ()
if (GTest_FIND_REQUIRED)
message(FATAL_ERROR "${GTEST_ERR_MSG}")
else (GTest_FIND_REQUIRED)
message(STATUS "${GTEST_ERR_MSG}")
endif (GTest_FIND_REQUIRED)
endif ()
endif ()
mark_as_advanced(
GTEST_INCLUDE_DIR
GTEST_LIBS
GTEST_LIBRARIES
GTEST_STATIC_LIB
GTEST_SHARED_LIB
)

View File

@ -6,7 +6,7 @@ rm -rf gtest
wget -nc https://github.com/google/googletest/archive/release-1.7.0.zip wget -nc https://github.com/google/googletest/archive/release-1.7.0.zip
unzip -n release-1.7.0.zip unzip -n release-1.7.0.zip
mv googletest-release-1.7.0 gtest && cd gtest mv googletest-release-1.7.0 gtest && cd gtest
cmake . && make cmake . && make
mkdir lib && mv libgtest.a lib mkdir lib && mv libgtest.a lib
cd .. cd ..
rm -rf release-1.7.0.zip* rm -rf release-1.7.0.zip*
@ -14,7 +14,7 @@ rm -rf release-1.7.0.zip*
rm -rf build rm -rf build
mkdir build mkdir build
cd build cd build
cmake .. "$@" -DGOOGLE_TEST=ON -DGTEST_ROOT=../gtest cmake .. "$@" -DGOOGLE_TEST=ON -DGTEST_ROOT=$PWD/../gtest
make clean make clean
make -j make -j
cd .. cd ..

View File

@ -125,16 +125,17 @@ if [ ${TASK} == "cmake_test" ]; then
rm -rf release-1.7.0.zip rm -rf release-1.7.0.zip
# Build/test without AVX # Build/test without AVX
rm -rf build
mkdir build && cd build mkdir build && cd build
cmake .. -DGOOGLE_TEST=ON -DGTEST_ROOT=../gtest/ cmake .. -DGOOGLE_TEST=ON -DGTEST_ROOT=$PWD/../gtest/
make make
cd .. cd ..
./testxgboost ./testxgboost
rm -rf build rm -rf build
# Build/test with AVX # Build/test with AVX
mkdir build && cd build mkdir build && cd build
cmake .. -DGOOGLE_TEST=ON -DUSE_AVX=ON -DGTEST_ROOT=../gtest/ cmake .. -DGOOGLE_TEST=ON -DUSE_AVX=ON -DGTEST_ROOT=$PWD/../gtest/
make make
cd .. cd ..
./testxgboost ./testxgboost