blob: 1c5ad29fd90b92abeffeaa31bfc4428dec2454c8 [file] [log] [blame]
Roni Riskaf165e572019-08-14 10:53:40 +03001#
2# Copyright (c) 2019 AT&T Intellectual Property.
3# Copyright (c) 2018-2019 Nokia.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18cmake_minimum_required (VERSION 3.5)
19
20file(
21 DOWNLOAD https://raw.githubusercontent.com/hunter-packages/gate/master/cmake/HunterGate.cmake
22 ${CMAKE_BINARY_DIR}/HunterGate.cmake)
23
24include("${CMAKE_BINARY_DIR}/HunterGate.cmake")
25
26HunterGate(
27 URL "https://github.com/ruslo/hunter/archive/v0.23.5.tar.gz"
28 SHA1 "2c5c6fc1cf609d0856695d60f147594daf4e6b3e"
29)
30
31project(tracelibcpp LANGUAGES CXX C)
32set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/cxx1.cmake)
33
34set (tracelibcpp_VERSION_MAJOR "0")
35set (tracelibcpp_VERSION_MINOR "0")
36set (tracelibcpp_VERSION_MICRO "1")
37set (tracelibcpp_VERSION_STRING
38 "${tracelibcpp_VERSION_MAJOR}.${tracelibcpp_VERSION_MINOR}.${tracelibcpp_VERSION_MICRO}")
39
40# Add jaeger
41hunter_add_package(jaegertracing)
42find_package(jaegertracing CONFIG REQUIRED)
43
44# Unit testing support of off by default
45# Enable it with cmake -DWITH_TESTING=ON <srcdir>
46option(WITH_TESTING "Include using testing support" OFF)
47
48include_directories ("${PROJECT_SOURCE_DIR}/include/tracelibcpp")
49
50add_library(tracelibcpp SHARED
51 src/tracelib.cpp
52)
53
54option(WITH_VERSION "Support for library versioning" ON)
55
56if (WITH_VERSION)
57 set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING}
58 SOVERSION ${tracelibcpp_VERSION_MAJOR})
59endif (WITH_VERSION)
60
61# Library versions are on by default
62# i.e. so versions
63option(WITH_VERSION "Support for library versioning" ON)
64
65if (WITH_VERSION)
66set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING}
67 SOVERSION ${tracelibcpp_VERSION_MAJOR})
68endif (WITH_VERSION)
69
70target_link_libraries(tracelibcpp PUBLIC jaegertracing::jaegertracing-static)
71
72include(GNUInstallDirs)
73if (NOT DEFINED LIB_INSTALL_DIR)
74 set(LIB_INSTALL_DIR lib)
75endif()
76
77install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/tracelibcpp
78 DESTINATION include
79 COMPONENT DEVEL)
80
81install(TARGETS tracelibcpp
82 COMPONENT DIST
83 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
84 NAMELINK_SKIP
85 )
86
87install(TARGETS tracelibcpp
88 COMPONENT DEVEL
89 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
90 NAMELINK_ONLY
91 )
92
93# Add google test
94if (WITH_TESTING)
95 hunter_add_package(GTest)
96 find_package(GTest CONFIG REQUIRED)
97 add_executable(testrunner
98 tst/testcreate.cpp
99 )
100 target_link_libraries(testrunner GTest::main) # GTest::gtest will be linked automatically
101 target_link_libraries(testrunner GTest::gtest)
102 target_link_libraries(testrunner tracelibcpp)
103 add_test(UnitTest testrunner)
104 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS testrunner)
105 ENABLE_TESTING()
106endif (WITH_TESTING)