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) |
Roni Riska | 95f44a5 | 2019-08-19 13:56:21 +0300 | [diff] [blame] | 33 | add_compile_options(-Wall -Wextra -Werror) |
| 34 | set(CMAKE_CXX_STANDARD 11) |
| 35 | |
| 36 | if(NOT CMAKE_BUILD_TYPE) |
| 37 | set(CMAKE_BUILD_TYPE Release) |
| 38 | endif() |
| 39 | |
| 40 | set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") |
| 41 | set(CMAKE_CXX_FLAGS_RELEASE "-O2") |
Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame] | 42 | |
| 43 | set (tracelibcpp_VERSION_MAJOR "0") |
| 44 | set (tracelibcpp_VERSION_MINOR "0") |
Roni Riska | 2ab92e9 | 2019-09-09 16:13:25 +0300 | [diff] [blame] | 45 | set (tracelibcpp_VERSION_MICRO "5") |
Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame] | 46 | set (tracelibcpp_VERSION_STRING |
| 47 | "${tracelibcpp_VERSION_MAJOR}.${tracelibcpp_VERSION_MINOR}.${tracelibcpp_VERSION_MICRO}") |
| 48 | |
Roni Riska | 9075724 | 2019-08-15 10:21:49 +0300 | [diff] [blame] | 49 | # Set up cpack |
| 50 | # Common |
| 51 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ implementation RIC tracing initialization") |
| 52 | set(CPACK_PACKAGE_VENDOR "Nokia") |
| 53 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") |
| 54 | set(CPACK_PACKAGE_VERSION_MAJOR ${tracelibcpp_VERSION_MAJOR}) |
| 55 | set(CPACK_PACKAGE_VERSION_MINOR ${tracelibcpp_VERSION_MINOR}) |
| 56 | set(CPACK_PACKAGE_VERSION_PATCH ${tracelibcpp_VERSION_MICRO}) |
| 57 | set(CPACK_COMPONENTS_ALL DIST DEVEL) |
| 58 | set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP ) |
| 59 | set(CPACK_GENERATOR "RPM;DEB") |
| 60 | set(CPACK_COMPONENTS_IGNORE_GROUPS 1) |
| 61 | set(CPACK_PACKAGE_CONTACT None) |
| 62 | |
| 63 | # RPM |
| 64 | set(CPACK_RPM_COMPONENT_INSTALL ON) |
| 65 | set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") |
| 66 | set(CPACK_RPM_FILE_NAME RPM-DEFAULT) |
| 67 | set(CPACK_RPM_PACKAGE_AUTOREQ 1) |
| 68 | |
| 69 | # Debian |
| 70 | set(CPACK_DEB_COMPONENT_INSTALL ON) |
| 71 | set(CPACK_DEB_PACKAGE_COMPONENT ON) |
| 72 | set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) |
| 73 | set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) |
| 74 | |
| 75 | include(CPack) |
| 76 | |
Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame] | 77 | # Add jaeger |
| 78 | hunter_add_package(jaegertracing) |
| 79 | find_package(jaegertracing CONFIG REQUIRED) |
| 80 | |
| 81 | # Unit testing support of off by default |
| 82 | # Enable it with cmake -DWITH_TESTING=ON <srcdir> |
| 83 | option(WITH_TESTING "Include using testing support" OFF) |
| 84 | |
| 85 | include_directories ("${PROJECT_SOURCE_DIR}/include/tracelibcpp") |
Roni Riska | 21cdadb | 2019-09-03 11:58:07 +0300 | [diff] [blame] | 86 | include_directories ("${PROJECT_SOURCE_DIR}/src") |
Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame] | 87 | |
| 88 | add_library(tracelibcpp SHARED |
| 89 | src/tracelib.cpp |
| 90 | ) |
| 91 | |
Roni Riska | 95f44a5 | 2019-08-19 13:56:21 +0300 | [diff] [blame] | 92 | # Library versions are on by default |
| 93 | # i.e. so versions |
Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame] | 94 | option(WITH_VERSION "Support for library versioning" ON) |
| 95 | |
| 96 | if (WITH_VERSION) |
| 97 | set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING} |
| 98 | SOVERSION ${tracelibcpp_VERSION_MAJOR}) |
| 99 | endif (WITH_VERSION) |
| 100 | |
Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame] | 101 | if (WITH_VERSION) |
| 102 | set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING} |
| 103 | SOVERSION ${tracelibcpp_VERSION_MAJOR}) |
| 104 | endif (WITH_VERSION) |
| 105 | |
| 106 | target_link_libraries(tracelibcpp PUBLIC jaegertracing::jaegertracing-static) |
| 107 | |
| 108 | include(GNUInstallDirs) |
| 109 | if (NOT DEFINED LIB_INSTALL_DIR) |
| 110 | set(LIB_INSTALL_DIR lib) |
| 111 | endif() |
| 112 | |
| 113 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/tracelibcpp |
| 114 | DESTINATION include |
| 115 | COMPONENT DEVEL) |
| 116 | |
| 117 | install(TARGETS tracelibcpp |
| 118 | COMPONENT DIST |
| 119 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} |
| 120 | NAMELINK_SKIP |
| 121 | ) |
| 122 | |
| 123 | install(TARGETS tracelibcpp |
| 124 | COMPONENT DEVEL |
| 125 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} |
| 126 | NAMELINK_ONLY |
| 127 | ) |
| 128 | |
| 129 | # Add google test |
| 130 | if (WITH_TESTING) |
Roni Riska | 95f44a5 | 2019-08-19 13:56:21 +0300 | [diff] [blame] | 131 | file( |
| 132 | DOWNLOAD https://raw.githubusercontent.com/bilke/cmake-modules/72d804cfbcf82a1e171200c9c02748fa4b7ea033/CodeCoverage.cmake |
| 133 | ${CMAKE_BINARY_DIR}/CodeCoverage.cmake) |
| 134 | |
| 135 | include("${CMAKE_BINARY_DIR}/CodeCoverage.cmake") |
| 136 | APPEND_COVERAGE_COMPILER_FLAGS() |
Roni Riska | f165e57 | 2019-08-14 10:53:40 +0300 | [diff] [blame] | 137 | hunter_add_package(GTest) |
| 138 | find_package(GTest CONFIG REQUIRED) |
| 139 | add_executable(testrunner |
| 140 | tst/testcreate.cpp |
| 141 | ) |
| 142 | target_link_libraries(testrunner GTest::main) # GTest::gtest will be linked automatically |
| 143 | target_link_libraries(testrunner GTest::gtest) |
| 144 | target_link_libraries(testrunner tracelibcpp) |
| 145 | add_test(UnitTest testrunner) |
| 146 | add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS testrunner) |
| 147 | ENABLE_TESTING() |
| 148 | endif (WITH_TESTING) |