Skip to content

Commit 361b51e

Browse files
DEV: cmake for gtest (#517)
* DEV: cmake for gtest
1 parent 59f0ce9 commit 361b51e

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

dpnp/backend/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ option(DPNP_STATIC_LIB_ENABLE "Enable build DPNP static library" FALSE)
5252
option(DPNP_DEBUG_ENABLE "Enable output for DPNP_DEBUG statements" FALSE)
5353
option(DPNP_INSTALL_STRUCTURED "if FALSE, install package files into same directory" TRUE)
5454
option(DPNP_SYCL_QUEUE_MGR_ENABLE "Use external manager for SYCL queue" FALSE)
55+
option(DPNP_BACKEND_TESTS "Enable DPNP tests" FALSE)
5556

5657
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
5758
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
5859
message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
5960
message(STATUS "DPNP_ONEAPI_ROOT: ${DPNP_ONEAPI_ROOT}")
6061
message(STATUS "DPNP_STATIC_LIB_ENABLE: ${DPNP_STATIC_LIB_ENABLE}")
6162
message(STATUS "DPNP_DEBUG_ENABLE: ${DPNP_DEBUG_ENABLE}")
63+
message(STATUS "DPNP_BACKEND_TESTS: ${DPNP_BACKEND_TESTS}")
6264
message(STATUS "DPNP_INSTALL_STRUCTURED: ${DPNP_INSTALL_STRUCTURED}")
6365
message(STATUS "DPNP_SYCL_QUEUE_MGR_ENABLE: ${DPNP_SYCL_QUEUE_MGR_ENABLE}")
6466
message(STATUS " |- DPNP_QUEUEMGR_INCLUDE_DIR: ${DPNP_QUEUEMGR_INCLUDE_DIR}")
@@ -186,6 +188,13 @@ endif()
186188
target_include_directories(dpnp_backend_c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
187189
target_include_directories(dpnp_backend_c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
188190

191+
# -----------------------------------------------------------------------------------------------
192+
# Testing logic...
193+
# -----------------------------------------------------------------------------------------------
194+
if(DPNP_BACKEND_TESTS)
195+
add_subdirectory(tests)
196+
endif()
197+
189198
# -----------------------------------------------------------------------------------------------
190199
# Dependencies logic...
191200
# -----------------------------------------------------------------------------------------------

dpnp/backend/tests/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
find_package(GTest REQUIRED)
2+
3+
find_package(Threads REQUIRED)
4+
5+
if(GTEST_FOUND)
6+
message(STATUS "Found GTest: (include: ${GTEST_INCLUDE_DIRS}, library: ${GTEST_LIBRARIES})")
7+
else()
8+
message(FATAL_ERROR "Cannot find Google Test Framework!")
9+
endif()
10+
11+
if(NOT Threads_FOUND)
12+
message(FATAL_ERROR "Cannot find Threads library!")
13+
endif()
14+
15+
# Emulate autotools like make check target to build tests
16+
# set(CMAKE_CTEST_COMMAND ctest --progress --output-on-failure -j 4)
17+
18+
enable_testing()
19+
20+
include_directories(${GTEST_INCLUDE_DIR})
21+
link_directories(${GTEST_LIB_DIR})
22+
23+
add_executable(dpnpc_tests test_random.cpp)
24+
target_link_libraries(dpnpc_tests GTest::GTest GTest::Main pthread dpnp_backend_c)

scripts/install_system_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ python --version
2626
python3 --version
2727

2828
echo ========================= install extra packages ==========================
29-
sudo apt-get install cmake valgrind
29+
sudo apt-get install cmake valgrind libgtest-dev
3030

3131
#echo ========================= install/delete libstdc++-dev ===================
3232
#sudo apt remove -y gcc-7 g++-7 gcc-8 g++-8 gcc-10 g++-10

utils/command_build_cmake_clib.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ def run(self):
9595
config = "Debug" if self.debug else "Release"
9696

9797
cmake_generator = str()
98+
enable_tests = "OFF"
99+
98100
if IS_WIN:
99101
cmake_generator = "-GNinja"
102+
if IS_LIN:
103+
enable_tests = "ON"
100104

101105
cmake_args = [
102106
cmake_generator,
@@ -109,7 +113,8 @@ def run(self):
109113
"-DDPNP_SYCL_QUEUE_MGR_ENABLE:BOOL=" + _dpctrl_exists,
110114
"-DDPNP_QUEUEMGR_INCLUDE_DIR=" + _dpctrl_include_dir,
111115
"-DDPNP_QUEUEMGR_LIB_DIR=" + _dpctrl_library_dir,
112-
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
116+
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
117+
"-DDPNP_BACKEND_TESTS:BOOL=" + enable_tests
113118
]
114119

115120
self.spawn(["cmake"] + cmake_args + [backend_directory])

0 commit comments

Comments
 (0)