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