forked from motonacciu/mpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
125 lines (101 loc) · 3.65 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
project(mmpi CXX)
# States that CMake required version must be >= 2.6
cmake_minimum_required(VERSION 2.6)
# enable ctest support for testing
enable_testing()
# get code root directory (based on current file name path)
get_filename_component( mmpi_dir ${CMAKE_CURRENT_LIST_FILE} PATH )
set ( mmpi_include_dir ${mmpi_dir}/include )
# enable tests for this project
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# enable MPI
find_package(MPI REQUIRED)
set(CMAKE_REQUIRED_DEFINITIONS ${MPI_COMPILE_FLAGS})
set(CMAKE_REQUIRED_INCLUDES ${MPI_INCLUDE_PATH})
set(CMAKE_REQUIRED_LIBRARIES ${MPI_LIBRARIES})
# enable C++0x support within gcc (if supported)
if (CMAKE_COMPILER_IS_GNUCXX)
# add general flags
add_definitions( -fshow-column )
add_definitions( -Wall )
# add flags for debug mode
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
# set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O3")
# ENABLE PROFILING
# add_definitions( -pg )
# SET(CMAKE_EXE_LINKER_FLAGS -pg)
# check for -std=c++0x
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag( -std=c++11 CXX11_Support )
if(CXX11_Support)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message( "WARNING: --std=c++11 not supported by your compiler!" )
endif()
endif()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
# avoid multiple import
if (NOT MEMORY_CHECK_SETUP)
option(CONDUCT_MEMORY_CHECKS "Checks all test cases for memory leaks using valgrind if enabled." OFF)
# add -all-valgrind target
add_custom_target(valgrind)
# define macro for adding tests
macro ( add_unit_test case_name )
# take value from environment variable
set(USE_VALGRIND ${CONDUCT_MEMORY_CHECKS})
# check whether there was a 2nd argument
if(${ARGC} GREATER 1)
# use last argument as a valgrind flag
set(USE_VALGRIND ${ARG2})
endif(${ARGC} GREATER 1)
# add test case
if(USE_VALGRIND)
# no valgrind support in MSVC
if(NOT MSVC)
# add valgrind as a test
add_test(NAME valgrind_${case_name}
COMMAND valgrind
--leak-check=full
--show-reachable=no
--track-fds=yes
--error-exitcode=1
#--log-file=${CMAKE_CURRENT_BINARY_DIR}/valgrind.log.${case_name}
${CMAKE_CURRENT_BINARY_DIR}/ut_${case_name}
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
endif(NOT MSVC)
else(USE_VALGRIND)
# add normal test
add_test(ut_${case_name} ut_${case_name})
# + valgrind as a custom target (only of not explicitly prohibited)
if ((NOT MSVC) AND ((NOT (${ARGC} GREATER 1)) OR (${ARG2})))
add_custom_target(valgrind_${case_name}
COMMAND valgrind
--leak-check=full
--show-reachable=no
--track-fds=yes
--error-exitcode=1
#--log-file=${CMAKE_CURRENT_BINARY_DIR}/valgrind.log.${case_name}
${CMAKE_CURRENT_BINARY_DIR}/ut_${case_name}
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
add_dependencies(valgrind valgrind_${case_name})
endif ((NOT MSVC) AND ((NOT (${ARGC} GREATER 1)) OR (${ARG2})))
endif(USE_VALGRIND)
endmacro(add_unit_test)
endif (NOT MEMORY_CHECK_SETUP)
# mark as defined
set(MEMORY_CHECK_SETUP OFF CACHE INTERNAL "Flag to avoid multiple setup" PARENT_SCOPE)
file(GLOB test_cases test/*.cc)
foreach ( case_file ${test_cases})
get_filename_component( case_name ${case_file} NAME_WE )
add_executable(ut_${case_name} ${case_file})
include_directories(ut_${case_name} ${mmpi_include_dir})
include_directories(ut_${case_name} ${MPI_INCLUDE_PATH})
target_link_libraries(ut_${case_name} ${GTEST_BOTH_LIBRARIES})
target_link_libraries(ut_${case_name} ${MPI_LIBRARIES})
add_unit_test(${case_name})
endforeach(case_file)