forked from dacorvo/gtest-cmake-example
-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
132 lines (109 loc) · 3.84 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
126
127
128
129
130
131
132
cmake_minimum_required(VERSION 2.8)
# Options. Turn on with 'cmake -Dmyvarname=ON'.
option(test "Build all tests." ON) # Makes boolean 'test' available.
# Make PROJECT_SOURCE_DIR, PROJECT_BINARY_DIR, and PROJECT_NAME available.
set(PROJECT_NAME MyProject)
project(${PROJECT_NAME})
set(CMAKE_CXX_FLAGS "-g -Wall")
set(CMAKE_C_FLAGS "-g -Wall")
# force static runtime libraries for msvc builds
if(MSVC)
set(variables
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
)
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
endif()
# If you want your own include/ directory, set this, and then you can do
# include_directories(${COMMON_INCLUDES}) in other CMakeLists.txt files.
# set(COMMON_INCLUDES ${PROJECT_SOURCE_DIR}/include)
################################
# Normal Libraries & Executables
################################
add_library(libbar
libbar/bar.cpp
libbar/bar.h
)
add_library(libfoo
libfoo/foo.cpp
libfoo/foo.h
)
add_executable( main_noTest
main/main.cpp
)
# Key idea: SEPARATE OUT your main() function into its own file so it can be its
# own executable. Separating out main() means you can add this library to be
# used elsewhere.
include_directories(
libfoo/
libbar/
)
target_link_libraries( main_noTest
libbar
libfoo
)
################################
# Testing
################################
if (test)
if (APPLE)
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
add_definitions(-D__GLIBCXX__)
endif (APPLE)
# This adds another subdirectory, which has 'project(gtest)'.
#add_subdirectory(lib/gtest-1.6.0)
add_subdirectory(gtest/googletest)
#add_subdirectory(test)
enable_testing()
# Include the gtest library. gtest_SOURCE_DIR is available due to
# 'project(gtest)' above.
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
SET( GTEST_LIBRARIES gtest gtest_main gmock gmock_main )
SET( CMAKE_BUILD_TYPE Debug )
include( cmake/CodeCoverage.cmake )
SET(CMAKE_CXX_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
add_subdirectory( test )
###############
## Unit Tests
###############
#add_executable(runUnitTests test_project1.cpp)
## Standard linking to gtest stuff.
#target_link_libraries(runUnitTests gtest gtest_main)
## Extra linking for the project.
#target_link_libraries(runUnitTests project1_lib)
## This is so you can do 'make test' to see all your tests run, instead of
## manually running the executable runUnitTests to see those specific tests.
#add_test(NAME that-test-I-made COMMAND runUnitTests)
## You can also omit NAME and COMMAND. The second argument could be some other
## test executable.
#add_test(that-other-test-I-made runUnitTests)
endif()
#enable_testing()
#OPTION( ENABLE_COVERAGE "Use gcov" ON )
#IF(ENABLE_COVERAGE)
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
#ENDIF()
#INCLUDE(CodeCoverage.cmake)
#SET(CMAKE_CXX_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
#SET(CMAKE_C_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
#
#SETUP_TARGET_FOR_COVERAGE(
# my_coverage_target # Name for custom target.
# testfoo # Name of the test driver executable that runs the tests.
# # NOTE! This should always have a ZERO as exit code
# # otherwise the coverage generation will not complete.
# coverage # Name of output directory.
# )
#add_subdirectory(main)
#add_subdirectory(test)
#add_subdirectory(libfoo)
#add_subdirectory(libbar)