-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
87 lines (69 loc) · 2.52 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
##
# StatsD Client
#
# Copyright (c) 2012-2014 Axel Etcheverry
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
##
cmake_minimum_required(VERSION 2.8.7)
project(StatsD CXX)
# Set some nicer output dirs.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
# get git tag
execute_process(COMMAND git describe --always --tag OUTPUT_VARIABLE tag_version OUTPUT_STRIP_TRAILING_WHITESPACE)
string(SUBSTRING ${tag_version} 1 -1 tag_version)
set(STATSD_VERSION ${tag_version})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/version.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/version.hpp @ONLY)
# enable valgrind
set(CMAKE_MEMORYCHECK_COMMAND valgrind)
set(CMAKE_MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 -v --track-origins=yes --leak-check=full --show-reachable=yes --trace-children=yes --child-silent-after-fork=yes -q")
find_file(HAVE_VALGRIND "valgrind")
add_definitions(
-std=c++11
-Wall
-pedantic
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(statsd SHARED src/statsd.cpp include/statsd.hpp include/version.hpp)
add_library(statsd_static STATIC src/statsd.cpp include/statsd.hpp include/version.hpp)
add_executable(
statsd-test
test/statsd.cpp
)
IF (WIN32)
target_link_libraries(statsd ws2_32)
target_link_libraries(statsd-test statsd_static ws2_32)
ELSE()
target_link_libraries(statsd-test statsd pthread)
ENDIF()
enable_testing()
function(add_memcheck_test name binary)
set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}")
separate_arguments(memcheck_command)
add_test(${name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${binary})
if(HAVE_VALGRIND)
add_test(memcheck_${name} ${memcheck_command} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${binary})
endif()
endfunction(add_memcheck_test)
add_memcheck_test(StatsD statsd-test)
install(FILES include/statsd.hpp DESTINATION include)
install(TARGETS statsd_static statsd
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
# Configure pkg-config file
set(ADDITIONAL_LIBS "")
if (WIN32)
set(ADDITIONAL_LIBS "-lws2_32")
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/statsd-cpp.pc.in
${CMAKE_CURRENT_BINARY_DIR}/statsd-cpp.pc
@ONLY
)
# Install pkg-config file
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/statsd-cpp.pc
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)