forked from SimonKagstrom/kcov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
236 lines (200 loc) · 7.43 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
cmake_minimum_required (VERSION 2.6)
project (kcov)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
find_package (Threads)
find_package (Bfd)
include(TargetArch)
target_architecture(CMAKE_TARGET_ARCHITECTURES)
message(STATUS "Target architectures: ${CMAKE_TARGET_ARCHITECTURES}")
pkg_check_modules(LIBZ REQUIRED zlib)
pkg_check_modules(LIBCURL REQUIRED libcurl)
# ====================================
# project name and version
# ====================================
project (kcov)
set (KCOV kcov)
# See http://eatmyrandom.blogspot.se/2010/06/automate-version-numbering-using-git.html
if( EXISTS "${CMAKE_SOURCE_DIR}/.git" )
execute_process(COMMAND git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/../.git describe --abbrev=4 HEAD
OUTPUT_VARIABLE POD_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
execute_process(COMMAND head -n 1 ${CMAKE_CURRENT_SOURCE_DIR}/../ChangeLog
COMMAND cut -d \( -f 2
COMMAND cut -d \) -f 1
OUTPUT_VARIABLE POD_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
add_custom_command(
OUTPUT version.c
COMMAND ${CMAKE_COMMAND} -E echo "const char *kcov_version = \\\"${POD_VERSION}\\\"\;"
> version.c
)
set (SOLIB kcov_sowrapper)
set (${SOLIB}_SRCS
solib-parser/phdr_data.c
solib-parser/lib.c
)
set (ADDRESS_VERIFIER_SRCS
parsers/dummy-address-verifier.cc
)
set (HAS_LIBBFD "0")
if("${CMAKE_TARGET_ARCHITECTURES}" STREQUAL "i386" OR "${CMAKE_TARGET_ARCHITECTURES}" STREQUAL "x86_64")
if(LIBBFD_FOUND)
set (HAS_LIBBFD "1")
set (ADDRESS_VERIFIER_SRCS
parsers/bfd-address-verifier.cc
)
set (ADDRESS_VERIFIER_LIBRARIES
${LIBBFD_OPCODES_LIBRARY}
${LIBBFD_BFD_LIBRARY}
${LIBBFD_IBERTY_LIBRARY}
)
endif()
endif()
set (coveralls_SRCS writers/coveralls-writer.cc)
if ("${KCOV_STATIC_BUILD}" STREQUAL "1")
message(STATUS "Building a static binary (no coveralls support)")
set (LIBCURL_LIBRARIES "")
# Coveralls doesn't work in a static setting
set (coveralls_SRCS writers/dummy-coveralls-writer.cc)
set (CMAKE_EXE_LINKER_FLAGS "-static")
endif()
set (LINUX_SRCS
dummy-solib-handler.cc
)
set (SOLIB_generated )
# Linux-specific sources
if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
find_package (LibElf REQUIRED)
find_package (Elfutils REQUIRED)
set (LINUX_SRCS
engines/clang-coverage-engine.cc
engines/ptrace.cc
engines/kernel-engine.cc
parsers/elf-parser.cc
parsers/dwarf.cc
solib-handler.cc
solib-parser/phdr_data.c
)
set (SOLIB_generated library.cc)
add_library (${SOLIB} SHARED ${${SOLIB}_SRCS})
set_target_properties(${SOLIB} PROPERTIES SUFFIX ".so")
target_link_libraries(${SOLIB} dl)
endif ()
set (${KCOV}_SRCS
capabilities.cc
collector.cc
configuration.cc
engine-factory.cc
engines/bash-engine.cc
engines/gcov-engine.cc
engines/python-engine.cc
filter.cc
gcov.cc
main.cc
merge-file-parser.cc
output-handler.cc
${ADDRESS_VERIFIER_SRCS}
parser-manager.cc
reporter.cc
utils.cc
writers/cobertura-writer.cc
${coveralls_SRCS}
writers/html-writer.cc
writers/writer-base.cc
${LINUX_SRCS}
)
set (KCOV_LIBRARY_PREFIX "/tmp")
set (CMAKE_CXX_FLAGS "-std=c++0x -g -Wall -D_GLIBCXX_USE_NANOSLEEP -DKCOV_LIBRARY_PREFIX=${KCOV_LIBRARY_PREFIX} -DKCOV_HAS_LIBBFD=${HAS_LIBBFD}")
include_directories(
include/
${LIBELF_INCLUDE_DIRS}
${LIBDW_INCLUDE_DIRS}
${LIBZ_INCLUDE_DIRS}
${LIBCURL_INCLUDE_DIRS}
)
link_directories (/home/ska/local/lib)
add_library (bash_execve_redirector SHARED engines/bash-execve-redirector.c)
set_target_properties(bash_execve_redirector PROPERTIES SUFFIX ".so")
target_link_libraries(bash_execve_redirector dl)
add_custom_command(
OUTPUT library.cc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py lib${SOLIB}.so __library > library.cc
DEPENDS ${SOLIB} ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py
)
add_custom_command(
OUTPUT bash-redirector-library.cc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py libbash_execve_redirector.so bash_redirector_library > bash-redirector-library.cc
DEPENDS bash_execve_redirector ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py
)
add_custom_command(
OUTPUT python-helper.cc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py ${CMAKE_CURRENT_SOURCE_DIR}/engines/python-helper.py python_helper > python-helper.cc
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/engines/python-helper.py ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py
)
add_custom_command(
OUTPUT bash-helper.cc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py
${CMAKE_CURRENT_SOURCE_DIR}/engines/bash-helper.sh bash_helper
${CMAKE_CURRENT_SOURCE_DIR}/engines/bash-helper-debug-trap.sh bash_helper_debug_trap
> bash-helper.cc
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/engines/bash-helper.sh
${CMAKE_CURRENT_SOURCE_DIR}/engines/bash-helper-debug-trap.sh
${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py
)
add_custom_command(
OUTPUT html-data-files.cc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py
${CMAKE_CURRENT_SOURCE_DIR}/../data/bcov.css css_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/amber.png icon_amber
${CMAKE_CURRENT_SOURCE_DIR}/../data/glass.png icon_glass
${CMAKE_CURRENT_SOURCE_DIR}/../data/source-file.html source_file_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/index.html index_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/handlebars.js handlebars_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/kcov.js kcov_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/jquery.min.js jquery_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/jquery.tablesorter.min.js tablesorter_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/jquery.tablesorter.widgets.min.js tablesorter_widgets_text
${CMAKE_CURRENT_SOURCE_DIR}/../data/tablesorter-theme.css tablesorter_theme_text
> html-data-files.cc
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/../data/bcov.css
${CMAKE_CURRENT_SOURCE_DIR}/../data/amber.png
${CMAKE_CURRENT_SOURCE_DIR}/../data/glass.png
${CMAKE_CURRENT_SOURCE_DIR}/../data/source-file.html
${CMAKE_CURRENT_SOURCE_DIR}/../data/index.html
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/handlebars.js
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/kcov.js
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/jquery.min.js
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/jquery.tablesorter.min.js
${CMAKE_CURRENT_SOURCE_DIR}/../data/js/jquery.tablesorter.widgets.min.js
${CMAKE_CURRENT_SOURCE_DIR}/../data/tablesorter-theme.css
${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py
)
# Reference: http://www.cmake.org/Wiki/CMake_RPATH_handling
if(SPECIFY_RPATH)
set (CMAKE_SKIP_BUILD_RPATH FALSE)
set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
endif(SPECIFY_RPATH)
add_executable (${KCOV} ${${KCOV}_SRCS} ${SOLIB_generated} bash-redirector-library.cc python-helper.cc bash-helper.cc html-data-files.cc version.c)
target_link_libraries(${KCOV}
${LIBDW_LIBRARIES}
${LIBELF_LIBRARIES}
stdc++
${LIBCURL_LIBRARIES}
m
${ADDRESS_VERIFIER_LIBRARIES}
${LIBZ_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
dl
)
install (TARGETS ${PROJECT_NAME} ${INSTALL_TARGETS_PATH})