Skip to content

Commit

Permalink
Some tests updates, use googletest as ExternalProject
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmuja committed Oct 27, 2022
1 parent 00efff9 commit f9caaf6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 71 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.8.12)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
Expand All @@ -11,6 +11,7 @@ include(${PROJECT_SOURCE_DIR}/cmake/flann_utils.cmake)
set(FLANN_VERSION 1.9.2)
DISSECT_VERSION()
GET_OS_INFO()
ENABLE_TESTING()


# detect if using the Clang compiler
Expand Down Expand Up @@ -115,10 +116,10 @@ endif()


if (BUILD_TESTS)
find_package(GTest)
if (NOT GTEST_FOUND)
message(WARNING "gtest library not found, some tests will not be run")
endif()
# find_package(GTest)
# if (NOT GTEST_FOUND)
# message(WARNING "gtest library not found, some tests will not be run")
# endif()
endif()


Expand Down
89 changes: 54 additions & 35 deletions cmake/flann_utils.cmake
Expand Up @@ -41,44 +41,66 @@ macro(find_hdf5)
endmacro(find_hdf5)


macro(flann_add_gtest exe)
# Enable ExternalProject CMake module
include(ExternalProject)

# Add gtest
ExternalProject_Add(
googletest
PREFIX ${CMAKE_BINARY_DIR}/googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
URL_MD5 2648d4138129812611cf6b6b4b497a3b
TIMEOUT 10
# Force separate output paths for debug and release builds to allow easy
# identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# Disable install step
INSTALL_COMMAND ""
# Disable update step
UPDATE_COMMAND ""
# Wrap download, configure and build steps in a script to log output
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON)
set_target_properties(googletest PROPERTIES EXCLUDE_FROM_ALL TRUE)

ExternalProject_Get_Property(googletest source_dir)
set(googletest_INCLUDE_DIRS ${source_dir}/googletest/include)
ExternalProject_Get_Property(googletest binary_dir)
set(googletest_LIBRARIES ${binary_dir}/lib/libgtest.a)
include_directories(${googletest_INCLUDE_DIRS})


macro(flann_add_gtest exe src)
# add build target
add_executable(${exe} EXCLUDE_FROM_ALL ${ARGN})
target_link_libraries(${exe} ${GTEST_LIBRARIES})
add_executable(${exe} EXCLUDE_FROM_ALL ${src})
target_link_libraries(${exe} ${googletest_LIBRARIES} ${ARGN})
# add dependency to 'tests' target
add_dependencies(${exe} googletest)
add_dependencies(flann_gtests ${exe})

# add target for running test
string(REPLACE "/" "_" _testname ${exe})
add_custom_target(test_${_testname}
COMMAND ${exe}
ARGS --gtest_print_time
DEPENDS ${exe}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
VERBATIM
COMMENT "Running gtest test(s) ${exe}")
# add dependency to 'test' target
add_dependencies(flann_gtest test_${_testname})
add_test(
NAME test_${_testname}
COMMAND ${exe} --gtest_print_time
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
)
endmacro(flann_add_gtest)

macro(flann_add_cuda_gtest exe)
macro(flann_add_cuda_gtest exe src)
# add build target
cuda_add_executable(${exe} EXCLUDE_FROM_ALL ${ARGN})
target_link_libraries(${exe} ${GTEST_LIBRARIES})
# add dependency to 'tests' target
add_dependencies(tests ${exe})
cuda_add_executable(${exe} EXCLUDE_FROM_ALL ${src})
target_link_libraries(${exe} ${googletest_LIBRARIES} ${ARGN})
add_dependencies(${exe} googletest)

# add target for running test
string(REPLACE "/" "_" _testname ${exe})
add_custom_target(test_${_testname}
COMMAND ${exe}
ARGS --gtest_print_time
DEPENDS ${exe}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
VERBATIM
COMMENT "Running gtest test(s) ${exe}")
# add dependency to 'test' target
add_dependencies(test test_${_testname})
add_test(
NAME test_${_testname}
COMMAND ${exe} --gtest_print_time
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
)
endmacro(flann_add_cuda_gtest)

macro(flann_add_pyunit file)
Expand All @@ -91,13 +113,10 @@ macro(flann_add_pyunit file)

# add target for running test
string(REPLACE "/" "_" _testname ${file})
add_custom_target(pyunit_${_testname}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin/run_test.py ${_file_name}
DEPENDS ${_file_name}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
VERBATIM
COMMENT "Running pyunit test(s) ${file}" )
add_test(
NAME pyunit_${_testname}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin/run_test.py ${_file_name}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
)
# add dependency to 'test' target
add_dependencies(pyunit_${_testname} flann)
add_dependencies(test pyunit_${_testname})
endmacro(flann_add_pyunit)
endmacro(flann_add_pyunit)
42 changes: 11 additions & 31 deletions test/CMakeLists.txt
@@ -1,58 +1,38 @@

add_custom_target(tests)
add_custom_target(flann_gtests)
add_custom_target(test)
add_custom_target(flann_gtest)

add_dependencies(tests flann_gtests)
add_dependencies(test flann_gtest)
add_dependencies(test tests)

set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH})

if (GTEST_FOUND AND HDF5_FOUND)
if (HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIR})

set(TEST_LIBRARIES "${HDF5_LIBRARIES}")
if (HDF5_IS_PARALLEL)
set(TEST_LIBRARIES "${TEST_LIBRARIES};${MPI_LIBRARIES}")
endif()

flann_add_gtest(flann_linear_test flann_linear_test.cpp)
target_link_libraries(flann_linear_test flann_cpp ${TEST_LIBRARIES})

flann_add_gtest(flann_kdtree_test flann_kdtree_test.cpp)
target_link_libraries(flann_kdtree_test flann_cpp ${TEST_LIBRARIES})

flann_add_gtest(flann_kmeans_test flann_kmeans_test.cpp)
target_link_libraries(flann_kmeans_test flann_cpp ${TEST_LIBRARIES})

flann_add_gtest(flann_kdtree_single_test flann_kdtree_single_test.cpp)
target_link_libraries(flann_kdtree_single_test flann_cpp ${TEST_LIBRARIES})

flann_add_gtest(flann_hierarchical_test flann_hierarchical_test.cpp)
target_link_libraries(flann_hierarchical_test flann_cpp ${TEST_LIBRARIES})

flann_add_gtest(flann_lsh_test flann_lsh_test.cpp)
target_link_libraries(flann_lsh_test flann_cpp ${TEST_LIBRARIES})

flann_add_gtest(flann_autotuned_test flann_autotuned_test.cpp)
target_link_libraries(flann_autotuned_test flann_cpp ${TEST_LIBRARIES})

flann_add_gtest(flann_linear_test flann_linear_test.cpp flann_cpp ${TEST_LIBRARIES})
flann_add_gtest(flann_kdtree_test flann_kdtree_test.cpp flann_cpp ${TEST_LIBRARIES})
flann_add_gtest(flann_kmeans_test flann_kmeans_test.cpp flann_cpp ${TEST_LIBRARIES})
flann_add_gtest(flann_kdtree_single_test flann_kdtree_single_test.cpp flann_cpp ${TEST_LIBRARIES})
flann_add_gtest(flann_hierarchical_test flann_hierarchical_test.cpp flann_cpp ${TEST_LIBRARIES})
flann_add_gtest(flann_lsh_test flann_lsh_test.cpp flann_cpp ${TEST_LIBRARIES})
flann_add_gtest(flann_autotuned_test flann_autotuned_test.cpp flann_cpp ${TEST_LIBRARIES})
if (OPENMP_FOUND)
flann_add_gtest(flann_multithreaded_test flann_multithreaded_test.cpp)
target_link_libraries(flann_multithreaded_test flann_cpp ${TEST_LIBRARIES})
flann_add_gtest(flann_multithreaded_test flann_multithreaded_test.cpp flann_cpp ${TEST_LIBRARIES})
endif()

endif()

if (GTEST_FOUND AND HDF5_FOUND AND BUILD_CUDA_LIB)
if (HDF5_FOUND AND BUILD_CUDA_LIB)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xcompiler;-fPIC;-Xcudafe \"--diag_suppress=partial_override\" ;-gencode=arch=compute_52,code=\"sm_52,compute_52\";-gencode=arch=compute_61,code=\"sm_61,compute_61\"" )
if (NVCC_COMPILER_BINDIR)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};--compiler-bindir=${NVCC_COMPILER_BINDIR}")
endif()
flann_add_cuda_gtest(flann_cuda_test flann_cuda_test.cu)
target_link_libraries(flann_cuda_test flann_cpp ${HDF5_LIBRARIES} flann_cuda)
flann_add_cuda_gtest(flann_cuda_test flann_cuda_test.cu flann_cpp ${HDF5_LIBRARIES} flann_cuda)
endif()


Expand Down

1 comment on commit f9caaf6

@StefanBruens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditionally running ExternalProject_Add is quite hostile to anyone building Flann in an isolated environment.

This should either be switchable with an OPTION, or depend on the result of find_package(gtest).

Please sign in to comment.