Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame^] | 1 | # |
| 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 | |
| 18 | cmake_minimum_required (VERSION 3.5) |
| 19 | |
| 20 | file( |
| 21 | DOWNLOAD https://raw.githubusercontent.com/hunter-packages/gate/master/cmake/HunterGate.cmake |
| 22 | ${CMAKE_BINARY_DIR}/HunterGate.cmake) |
| 23 | |
| 24 | include("${CMAKE_BINARY_DIR}/HunterGate.cmake") |
| 25 | |
| 26 | HunterGate( |
| 27 | URL "https://github.com/ruslo/hunter/archive/v0.23.5.tar.gz" |
| 28 | SHA1 "2c5c6fc1cf609d0856695d60f147594daf4e6b3e" |
| 29 | ) |
| 30 | |
| 31 | project(tracelibcpp LANGUAGES CXX C) |
| 32 | set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/cxx1.cmake) |
| 33 | |
| 34 | set (tracelibcpp_VERSION_MAJOR "0") |
| 35 | set (tracelibcpp_VERSION_MINOR "0") |
| 36 | set (tracelibcpp_VERSION_MICRO "1") |
| 37 | set (tracelibcpp_VERSION_STRING |
| 38 | "${tracelibcpp_VERSION_MAJOR}.${tracelibcpp_VERSION_MINOR}.${tracelibcpp_VERSION_MICRO}") |
| 39 | |
| 40 | # Add jaeger |
| 41 | hunter_add_package(jaegertracing) |
| 42 | find_package(jaegertracing CONFIG REQUIRED) |
| 43 | |
| 44 | # Unit testing support of off by default |
| 45 | # Enable it with cmake -DWITH_TESTING=ON <srcdir> |
| 46 | option(WITH_TESTING "Include using testing support" OFF) |
| 47 | |
| 48 | include_directories ("${PROJECT_SOURCE_DIR}/include/tracelibcpp") |
| 49 | |
| 50 | add_library(tracelibcpp SHARED |
| 51 | src/tracelib.cpp |
| 52 | ) |
| 53 | |
| 54 | option(WITH_VERSION "Support for library versioning" ON) |
| 55 | |
| 56 | if (WITH_VERSION) |
| 57 | set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING} |
| 58 | SOVERSION ${tracelibcpp_VERSION_MAJOR}) |
| 59 | endif (WITH_VERSION) |
| 60 | |
| 61 | # Library versions are on by default |
| 62 | # i.e. so versions |
| 63 | option(WITH_VERSION "Support for library versioning" ON) |
| 64 | |
| 65 | if (WITH_VERSION) |
| 66 | set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING} |
| 67 | SOVERSION ${tracelibcpp_VERSION_MAJOR}) |
| 68 | endif (WITH_VERSION) |
| 69 | |
| 70 | target_link_libraries(tracelibcpp PUBLIC jaegertracing::jaegertracing-static) |
| 71 | |
| 72 | include(GNUInstallDirs) |
| 73 | if (NOT DEFINED LIB_INSTALL_DIR) |
| 74 | set(LIB_INSTALL_DIR lib) |
| 75 | endif() |
| 76 | |
| 77 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/tracelibcpp |
| 78 | DESTINATION include |
| 79 | COMPONENT DEVEL) |
| 80 | |
| 81 | install(TARGETS tracelibcpp |
| 82 | COMPONENT DIST |
| 83 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} |
| 84 | NAMELINK_SKIP |
| 85 | ) |
| 86 | |
| 87 | install(TARGETS tracelibcpp |
| 88 | COMPONENT DEVEL |
| 89 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} |
| 90 | NAMELINK_ONLY |
| 91 | ) |
| 92 | |
| 93 | # Add google test |
| 94 | if (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() |
| 106 | endif (WITH_TESTING) |