E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 1 | #================================================================================== |
| 2 | # Copyright (c) 2019 Nokia |
| 3 | # Copyright (c) 2018-2019 AT&T Intellectual Property. |
| 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 | |
| 19 | # This CMake definition supports several -D command line options: |
| 20 | # |
| 21 | # -DDEBUG=n Enable debugging level n |
| 22 | # -DDEV_PKG=1 Development package configuration |
| 23 | # -DBUILD_DOC=1 Man pages generated |
| 24 | # -DPRESERVE_PTYPE=1 Do not change the processor type when naming deb packages |
| 25 | # -DGPROF=1 Enable profiling compile time flags |
| 26 | # -DMAN_PREFIX=<path> Supply a path where man pages are installed (default: /usr/share/man) |
| 27 | |
| 28 | project( ricxfcpp ) |
| 29 | cmake_minimum_required( VERSION 3.5 ) |
| 30 | |
E. Scott Daniels | 6ef23e1 | 2020-07-15 08:03:22 -0400 | [diff] [blame] | 31 | set( major_version "2" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this |
E. Scott Daniels | c85ac8b | 2020-08-19 09:51:33 -0400 | [diff] [blame] | 32 | set( minor_version "3" ) |
Alexandre Huff | f899326 | 2022-02-05 09:54:32 -0300 | [diff] [blame] | 33 | set( patch_level "6" ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 34 | |
| 35 | set( install_root "${CMAKE_INSTALL_PREFIX}" ) |
| 36 | set( install_inc "include/ricxfcpp" ) |
| 37 | if( MAN_PREFIX ) |
| 38 | set( install_man ${MAN_PREFIX} ) # is there a cmake var for this -- can't find one |
| 39 | else() |
| 40 | set( install_man "/usr/share/man" ) # this needs to be fixed so it's not hard coded |
| 41 | endif() |
| 42 | |
| 43 | # Must use GNUInstallDirs to install libraries into correct |
| 44 | # locations on all platforms. |
| 45 | include( GNUInstallDirs ) |
| 46 | |
| 47 | # externals may install using LIBDIR as established by the gnu include; it varies from system |
| 48 | # to system, and we don't trust that it is always set, so we default to lib if it is missing. |
| 49 | # |
| 50 | if( NOT CMAKE_INSTALL_LIBDIR ) |
| 51 | set( CMAKE_INSTALL_LIBDIR "lib" ) |
| 52 | endif() |
| 53 | |
| 54 | set( install_lib "${CMAKE_INSTALL_LIBDIR}" ) |
| 55 | message( "+++ ricxfcpp library install target directory: ${install_lib}" ) |
| 56 | |
| 57 | # ---------------- extract some things from git ------------------------------ |
| 58 | |
| 59 | # commit id for the version string |
| 60 | execute_process( |
| 61 | COMMAND bash -c "git rev-parse --short HEAD|awk '{printf\"%s\", $0}'" |
| 62 | OUTPUT_VARIABLE git_id |
| 63 | ) |
| 64 | |
| 65 | # version information for library names and version string |
| 66 | execute_process( |
| 67 | COMMAND bash -c "git describe --tags --abbrev=0 HEAD 2>/dev/null | awk -v tag=0.0.4095 ' { tag=$1 } END{ print tag suffix }'|sed 's/\\./;/g' " |
| 68 | OUTPUT_VARIABLE mmp_version_str |
| 69 | ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE |
| 70 | ) |
| 71 | message( "+++ mmp version from tag: '${mmp_version_str}'" ) |
| 72 | |
| 73 | # extra indicator to show that the build was based on modified file(s) and not the true commit |
| 74 | # (no hope of reproducing the exact library for debugging). Used only for the internal version |
| 75 | # string. |
| 76 | execute_process( |
| 77 | COMMAND bash -c "git diff --shortstat|awk -v fmt=%s -v r=-rotten '{ s=r } END { printf( fmt, s ) }'" |
| 78 | OUTPUT_VARIABLE spoiled_str |
| 79 | ) |
| 80 | |
| 81 | # uncomment these lines once CI starts adding a tag on merge |
| 82 | #set( mmp_version ${mmp_version_str} ) |
| 83 | #list( GET mmp_version 0 major_version ) |
| 84 | #list( GET mmp_version 1 minor_version ) |
| 85 | #list( GET mmp_version 2 patch_level ) |
| 86 | |
| 87 | if( DEBUG ) # if set, we'll set debugging on in the compile |
| 88 | set( debugging ${DEBUG} ) |
| 89 | message( "+++ debugging is being set to ${DEBUG}" ) |
| 90 | else() |
| 91 | set( debugging 0 ) |
| 92 | message( "+++ debugging is set to off" ) |
| 93 | endif() |
| 94 | unset( DEBUG CACHE ) # we don't want this to persist |
| 95 | |
| 96 | |
| 97 | # define constants used in the version string, debugging, etc. |
| 98 | add_definitions( |
| 99 | -DGIT_ID=${git_id} |
| 100 | -DMAJOR_VER=${major_version} |
| 101 | -DMINOR_VER=${minor_version} |
| 102 | -DPATCH_VER=${patch_level} |
| 103 | -DDEBUG=${debugging} |
| 104 | ) |
| 105 | |
| 106 | # ---------------- suss out pkg gen tools so we don't fail generating packages that the system cannot support -------------- |
| 107 | |
| 108 | # deb packages use underbars, and package manager(s) seem to flip the *_64 processor type |
| 109 | # to the old (non-standard) amd64 string, so we do it here for consistency. Set -DPRESERVE_PTYPE=1 |
| 110 | # to prevent the flip. RPM packages will always be given the system generated processor type string. |
| 111 | # |
| 112 | if( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" ) |
| 113 | if( NOT PRESERVE_PTYPE ) |
| 114 | set( deb_sys_name "amd64" ) |
| 115 | else() |
| 116 | set( deb_sys_name ${CMAKE_SYSTEM_PROCESSOR} ) |
| 117 | endif() |
| 118 | else() |
| 119 | set( deb_sys_name ${CMAKE_SYSTEM_PROCESSOR} ) |
| 120 | endif() |
| 121 | unset( PRESERVE_PTYPE CACHE ) # we don't want this to persist |
| 122 | |
| 123 | set( rpm_sys_name ${CMAKE_SYSTEM_PROCESSOR} ) |
| 124 | |
| 125 | if( DEV_PKG ) |
| 126 | set( deb_pkg_name "ricxfcpp-dev" ) |
| 127 | set( rpm_pkg_name "ricxfcpp-devel" ) |
| 128 | else() |
| 129 | set( deb_pkg_name "ricxfcpp" ) |
| 130 | set( rpm_pkg_name "ricxfcpp" ) |
| 131 | endif() |
| 132 | |
| 133 | set( pkg_label "ricxfcpp${spoiled_str}-${major_version}.${minor_version}.${patch_level}-${sys_name}" ) |
| 134 | set( rpm_pkg_label "${rpm_pkg_name}${spoiled_str}-${major_version}.${minor_version}.${patch_level}-${rpm_sys_name}" ) |
| 135 | set( deb_pkg_label "${deb_pkg_name}${spoiled_str}_${major_version}.${minor_version}.${patch_level}_${deb_sys_name}" ) |
| 136 | message( "+++ pkg name: ${deb_pkg_label}.deb" ) |
| 137 | |
| 138 | set( gen_rpm 0 ) |
| 139 | find_program( rpm NAMES rpmbuild ) # rpm package gen requires this to be installed |
| 140 | if( "${rpm}" MATCHES "rpm-NOTFOUND" ) # cannot build rpm |
| 141 | set( pkg_list "DEB" ) |
| 142 | message( "### make package will generate only deb package; cannot find support to generate rpm packages" ) |
| 143 | else() |
| 144 | message( "+++ pkg name: ${rpm_pkg_label}.rpm" ) # debugging if we think we can gen rpm too |
| 145 | set( pkg_list "DEB;RPM" ) |
| 146 | set( gen_rpm 1 ) |
| 147 | message( "+++ make package will generate both deb and rpm packages" ) |
| 148 | endif() |
| 149 | |
| 150 | |
| 151 | |
E. Scott Daniels | 6ef23e1 | 2020-07-15 08:03:22 -0400 | [diff] [blame] | 152 | # bleeding cmake names are short novels; and when lines cannot be split they're a pain |
| 153 | set ( srcd "${CMAKE_CURRENT_SOURCE_DIR}" ) |
| 154 | |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 155 | # this gets us round a chicken/egg problem. include files don't exist until make is run |
| 156 | # but Cmake insists on having these exist when we add them to include directories to |
| 157 | # enable code to find them after we build them. |
| 158 | # |
E. Scott Daniels | d486a17 | 2020-07-29 12:39:54 -0400 | [diff] [blame] | 159 | include_directories( "${srcd}/src/messaging;${srcd}/src/json;${srcd}/src/alarm;${srcd}/src/metrics;${srcd}/src/config;${srcd}/ext/jsmn" ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 160 | |
| 161 | # Compiler flags |
| 162 | # |
| 163 | set( CMAKE_POSITION_INDEPENDENT_CODE ON ) |
| 164 | set( CMAKE_C_FLAGS "-g " ) |
| 165 | set( CMAKE_CPP_FLAGS "-g " ) |
E. Scott Daniels | 6ef23e1 | 2020-07-15 08:03:22 -0400 | [diff] [blame] | 166 | set( CMAKE_CXX_FLAGS "-g " ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 167 | if( GPROF ) # if set, we'll set profiling flag on compiles |
| 168 | message( "+++ profiling is on" ) |
| 169 | set( CMAKE_C_FLAGS "-pg " ) |
| 170 | set( CMAKE_CPP_FLAGS "-pg " ) |
| 171 | else() |
| 172 | message( "+++ profiling is off" ) |
| 173 | endif() |
| 174 | unset( GPROF CACHE ) # we don't want this to persist |
| 175 | |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 176 | |
| 177 | # --------------------- external building -------------------------------------------------------- |
| 178 | execute_process( COMMAND git submodule update --init -- ext/jsmn |
| 179 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 180 | ) |
| 181 | |
| 182 | |
| 183 | # --------------------- framework building -------------------------------------------------------- |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 184 | # Include modules |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 185 | add_subdirectory( src/json ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 186 | add_subdirectory( src/messaging ) |
| 187 | add_subdirectory( src/xapp ) |
E. Scott Daniels | 6ef23e1 | 2020-07-15 08:03:22 -0400 | [diff] [blame] | 188 | add_subdirectory( src/alarm ) |
E. Scott Daniels | ef36205 | 2020-07-22 15:49:54 -0400 | [diff] [blame] | 189 | add_subdirectory( src/metrics ) |
E. Scott Daniels | d486a17 | 2020-07-29 12:39:54 -0400 | [diff] [blame] | 190 | add_subdirectory( src/config ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 191 | #add_subdirectory( doc ) # this will auto skip if {X}fm is not available |
| 192 | |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 193 | # shared and static libraries are built from the same object files. |
| 194 | # |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 195 | add_library( ricxfcpp_shared SHARED |
E. Scott Daniels | d486a17 | 2020-07-29 12:39:54 -0400 | [diff] [blame] | 196 | "$<TARGET_OBJECTS:message_objects>;$<TARGET_OBJECTS:json_objects>;$<TARGET_OBJECTS:alarm_objects>;$<TARGET_OBJECTS:metrics_objects>;$<TARGET_OBJECTS:config_objects>;$<TARGET_OBJECTS:xapp_objects>" |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 197 | ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 198 | set_target_properties( ricxfcpp_shared |
| 199 | PROPERTIES |
| 200 | OUTPUT_NAME "ricxfcpp" |
| 201 | SOVERSION ${major_version} |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 202 | VERSION ${major_version}.${minor_version}.${patch_level} |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 203 | ) |
E. Scott Daniels | ef36205 | 2020-07-22 15:49:54 -0400 | [diff] [blame] | 204 | #target_include_directories( ricxfcpp_shared PUBLIC "src/alarm" "src/metrics" "src/messenger" "src/xapp" ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 205 | |
| 206 | # we only build/export the static archive (.a) if generating a dev package |
| 207 | if( DEV_PKG ) |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 208 | add_library( ricxfcpp_static STATIC |
E. Scott Daniels | d486a17 | 2020-07-29 12:39:54 -0400 | [diff] [blame] | 209 | "$<TARGET_OBJECTS:message_objects>;$<TARGET_OBJECTS:json_objects>;$<TARGET_OBJECTS:alarm_objects>;$<TARGET_OBJECTS:config_objects>;$<TARGET_OBJECTS:metrics_objects>;$<TARGET_OBJECTS:xapp_objects>" |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 210 | ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 211 | set_target_properties( ricxfcpp_static |
| 212 | PROPERTIES |
| 213 | OUTPUT_NAME "ricxfcpp" |
| 214 | SOVERSION ${major_version} |
E. Scott Daniels | 97204c8 | 2020-06-29 15:39:57 -0400 | [diff] [blame] | 215 | VERSION ${major_version}.${minor_version}.${patch_level} |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 216 | ) |
E. Scott Daniels | ef36205 | 2020-07-22 15:49:54 -0400 | [diff] [blame] | 217 | # target_include_directories( ricxfcpp_static PUBLIC "src/alarm" "src/metrics" "src/messenger" "src/xapp" ) |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 218 | endif() |
| 219 | |
E. Scott Daniels | 4e4fb50 | 2020-03-24 12:28:06 -0400 | [diff] [blame] | 220 | # -------- unit testing ------------------------------------------------------- |
| 221 | enable_testing() |
| 222 | add_test( |
| 223 | NAME drive_unit_tests |
E. Scott Daniels | ef36205 | 2020-07-22 15:49:54 -0400 | [diff] [blame] | 224 | COMMAND bash ../test/unit_test.sh -q CMBUILD=${CMAKE_CURRENT_BINARY_DIR} |
E. Scott Daniels | 4e4fb50 | 2020-03-24 12:28:06 -0400 | [diff] [blame] | 225 | WORKING_DIRECTORY ../test |
| 226 | ) |
| 227 | |
| 228 | |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 229 | # ------------- packaging ----------------------------------------------------- |
| 230 | |
| 231 | # Define what should be installed, and where they should go. For dev package we install |
| 232 | # only the RMr headers, man pages and archive (.a) files. The run-time package gets just |
| 233 | # the library (.so) files and nothing more. |
| 234 | # |
| 235 | if( DEV_PKG ) |
| 236 | set( target_list "ricxfcpp_static" ) |
| 237 | else() |
| 238 | set( target_list "ricxfcpp_shared" ) |
| 239 | endif() |
| 240 | |
| 241 | install( TARGETS ${target_list} EXPORT LibraryConfig |
E. Scott Daniels | 6ef23e1 | 2020-07-15 08:03:22 -0400 | [diff] [blame] | 242 | LIBRARY DESTINATION ${install_lib} |
| 243 | ARCHIVE DESTINATION ${install_lib} |
| 244 | PUBLIC_HEADER DESTINATION ${install_inc} |
E. Scott Daniels | 8cb3c6f | 2020-03-19 11:36:37 -0400 | [diff] [blame] | 245 | ) |
| 246 | |
| 247 | unset( DEV_PKG CACHE ) # prevent from being a hidden setting if user redoes things |
| 248 | |
| 249 | IF( EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake" ) |
| 250 | include( InstallRequiredSystemLibraries ) |
| 251 | |
| 252 | set( CPACK_DEBIAN_PACKAGE_NAME ${deb_pkg_name} ) |
| 253 | set( CPACK_RPM_PACKAGE_NAME ${rpm_pkg_name} ) |
| 254 | |
| 255 | set( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/local;/usr/local/bin;/usr/local/include;/usr/local/share;/usr/local/lib" ) |
| 256 | |
| 257 | set( CPACK_set_DESTDIR "on" ) |
| 258 | set( CPACK_PACKAGING_INSTALL_PREFIX "${install_root}" ) |
| 259 | set( CPACK_GENERATOR "${pkg_list}" ) |
| 260 | |
| 261 | set( CPACK_PACKAGE_DESCRIPTION "C++ framework for RIC xAPPs based on RMR." ) |
| 262 | set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "RIC xAPP C++ framework library" ) |
| 263 | set( CPACK_PACKAGE_VENDOR "None" ) |
| 264 | set( CPACK_PACKAGE_CONTACT "None" ) |
| 265 | set( CPACK_PACKAGE_VERSION_MAJOR "${major_version}" ) |
| 266 | set( CPACK_PACKAGE_VERSION_MINOR "${minor_version}" ) |
| 267 | set( CPACK_PACKAGE_VERSION_PATCH "${patch_level}" ) |
| 268 | set( CPACK_PACKAGE "${pkg_label}" ) # generic name for old versions of cpack |
| 269 | set( CPACK_DEBIAN_FILE_NAME "${deb_pkg_label}.deb" ) |
| 270 | set( CPACK_RPM_FILE_NAME "${rpm_pkg_label}.rpm" ) |
| 271 | |
| 272 | # Future: define dependencies on RMR and other libs |
| 273 | |
| 274 | set( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" ) |
| 275 | set( CPACK_DEBIAN_PACKAGE_SECTION "ric" ) |
| 276 | set( CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} ) |
| 277 | set( CPACK_RPM_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} ) |
| 278 | |
| 279 | # this seems ingnored if included |
| 280 | #set( CPACK_COMPONENTS_ALL Libraries ApplicationData ) |
| 281 | |
| 282 | INCLUDE( CPack ) |
| 283 | ENDIF() |