-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathCMakeLists.txt
64 lines (50 loc) · 1.95 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
project(Tests)
cmake_minimum_required(VERSION 2.8)
find_package(Glog REQUIRED)
include_directories(${GLOG_INCLUDE_DIRS})
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
# Function prepares name of a test executable
# @output_name - output variable's name
# @filename - test_*.cpp file path
function(test_name output_name filename)
get_filename_component(name ${filename} NAME_WE)
set(${output_name} ${name}${TEST_EXT} PARENT_SCOPE)
endfunction()
file(GLOB TEST_CPP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "test_*.cpp")
list(REMOVE_ITEM TEST_CPP_SOURCES test_main.cpp)
foreach(source ${TEST_CPP_SOURCES})
MESSAGE( STATUS ${source} )
endforeach()
add_library(test_main.o EXCLUDE_FROM_ALL OBJECT test_main.cpp)
# Build each test separately from *.cpp files
foreach(source ${TEST_CPP_SOURCES})
test_name(TEST_NAME ${source})
add_library(${TEST_NAME}.o EXCLUDE_FROM_ALL OBJECT ${source})
set(TEST_OBJ_LIB $<TARGET_OBJECTS:${TEST_NAME}.o>)
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_OBJ_LIB} $<TARGET_OBJECTS:test_main.o>)
target_link_libraries(${TEST_NAME} purine)
target_link_libraries(${TEST_NAME}
${GLOG_LIBRARIES}
${PROTOBUF_LIBRARIES}
${LIBUV_LIBRARIES}
)
# output dir
set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
# Targets and object libs
set(TEST_TARGETS ${TEST_TARGETS} ${TEST_NAME})
set(TEST_OBJ_LIBS ${TEST_OBJ_LIBS} ${TEST_OBJ_LIB})
endforeach()
# Build a compound test excluded from the ALL target
add_executable(test_all EXCLUDE_FROM_ALL ${TEST_OBJ_LIBS} $<TARGET_OBJECTS:test_main.o>)
target_link_libraries(test_all purine)
target_link_libraries(test_all
${CUDA_CUBLAS_LIBRARIES}
${CUDA_curand_LIBRARY}
${GLOG_LIBRARIES}
${PROTOBUF_LIBRARIES}
${LIBUV_LIBRARIES}
)
add_dependencies(test_all ${TEST_TARGETS})
# Test command
add_custom_target(run_test COMMAND test_all)