-
Notifications
You must be signed in to change notification settings - Fork 104
/
CMakeLists.txt
executable file
·106 lines (88 loc) · 3.73 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
EchoWithColor(COLOR GREEN "-- Configure Test Projects")
find_package(GTest)
set (PROJECT_LIBCOPP_TEST_LIB_LINK "")
# =========== find gtest ===========
if (GTEST_FOUND)
EchoWithColor(COLOR GREEN "-- GTest Found: ${GTEST_LIBRARIES}")
add_compiler_define(COPP_MACRO_TEST_ENABLE_GTEST=1)
set (PROJECT_LIBCOPP_TEST_LIB_LINK ${GTEST_LIBRARIES})
include_directories(${GTEST_INCLUDE_DIRS})
# =========== enable find boost.test ===========
elseif(LIBCOPP_TEST_ENABLE_BOOST_UNIT_TEST)
find_package(Boost COMPONENTS unit_test_framework)
set(Boost_AUTO_LIBS "${Boost_LIBRARIES}")
if(Boost_FOUND)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS unit_test_framework)
if(NOT Boost_FOUND)
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost COMPONENTS unit_test_framework)
elseif(NOT "${Boost_LIBRARIES}" EQUAL "${Boost_AUTO_LIBS}")
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost COMPONENTS unit_test_framework)
endif()
add_compiler_define(COPP_MACRO_TEST_ENABLE_BOOST_TEST=1)
set (PROJECT_LIBCOPP_TEST_LIB_LINK ${Boost_LIBRARIES})
include_directories(${Boost_INCLUDE_DIRS})
EchoWithColor(COLOR GREEN "-- Boost.test Found: ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}")
if (NOT Boost_USE_STATIC_LIBS)
EchoWithColor(COLOR GREEN "-- Boost.test using dynamic library define BOOST_TEST_DYN_LINK")
add_compiler_define(BOOST_TEST_DYN_LINK)
endif()
else()
EchoWithColor(COLOR RED "-- Enable boost unit test but boost.test not found.")
endif()
endif()
include("${CMAKE_CURRENT_LIST_DIR}/test.custom-macro.cmake")
include_directories(${PROJECT_TEST_INC_DIR})
file(GLOB_RECURSE COPP_TEST_SRC_LIST
${PROJECT_TEST_SRC_DIR}/*.h
${PROJECT_TEST_SRC_DIR}/*.hpp
${PROJECT_TEST_SRC_DIR}/*.c
${PROJECT_TEST_SRC_DIR}/*.cpp
${PROJECT_TEST_SRC_DIR}/*.cc
${PROJECT_TEST_SRC_DIR}/*.cxx
)
source_group_by_dir(COPP_TEST_SRC_LIST)
# ================ multi thread ================
if ( NOT MSVC )
add_definitions(-D_POSIX_MT_)
set (PROJECT_LIBCOPP_TEST_LIB_LINK ${PROJECT_LIBCOPP_TEST_LIB_LINK} pthread)
endif()
# ============ test - coroutine test frame ============
set(CMAKE_BUILD_RPATH "$ORIGIN/../lib" "$ORIGIN/../lib64")
if (NOT (WIN32 AND (BUILD_SHARED_LIBS OR LIBCOPP_USE_DYNAMIC_LIBRARY)))
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/test")
endif ()
add_executable(libcopp_unit_test ${COPP_TEST_SRC_LIST})
set_target_properties(libcopp_unit_test PROPERTIES
INSTALL_RPATH_USE_LINK_PATH YES
BUILD_WITH_INSTALL_RPATH NO
BUILD_RPATH_USE_ORIGIN YES
)
target_link_libraries(libcopp_unit_test
${PROJECT_LIBCOTASK_LIB_LINK}
${PROJECT_LIBCOPP_LIB_LINK}
${PROJECT_LIBCOPP_TEST_LIB_LINK}
${PROJECT_LIBCOPP_SYSLIB_LINK_NAMES}
${COMPILER_OPTION_EXTERN_CXX_LIBS}
)
if (MSVC AND MSVC_VERSION LESS 1910)
target_compile_options(libcopp_unit_test
PRIVATE /wd4503
)
endif ()
add_custom_target(run_test_libcopp_unit_test
libcopp_unit_test
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
add_dependencies(run_test run_test_libcopp_unit_test)
add_dependencies(run_test_libcopp_unit_test libcopp_unit_test)
if (_VALGRIND_EXECUTABLE)
add_custom_target(run_memcheck_libcopp_unit_test
${_VALGRIND_EXECUTABLE} "--max-threads=4096" "--tool=memcheck" "--log-file=libcopp_unit_test.memcheck.log" --leak-check=full --show-leak-kinds=all --malloc-fill=ef --free-fill=e5 $<TARGET_FILE:libcopp_unit_test>
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
add_dependencies(memcheck run_memcheck_libcopp_unit_test)
add_dependencies(run_memcheck_libcopp_unit_test libcopp_unit_test)
endif()