E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 1 | #================================================================================== |
| 2 | # Copyright (c) 2021 AT&T Intellectual Property. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | #================================================================================== |
| 16 | # |
| 17 | |
| 18 | # This CMake definition supports several -D command line options: |
| 19 | # |
| 20 | # -DDEV_PKG=1 Development package configuration |
| 21 | # -DBUILD_DOC=1 Man pages generated |
| 22 | # -DGPROF=1 Enable profiling compile time flags |
| 23 | # -D-DPRESERVE_PTYPE=1 to prevent changing the processor type to a standard string |
| 24 | |
| 25 | project( libe2ap ) |
| 26 | cmake_minimum_required( VERSION 3.5 ) |
| 27 | |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 28 | # |
| 29 | # Versioning is based on the E2 specification version number in play when the generated |
| 30 | # code in src/e2ap was created. The major/minor numbers should match the working group |
| 31 | # name (e.g. ORAN-WG3.E2AP-v01.00, would be 1.0). The patch version can be increased for |
| 32 | # small tweaks and possibly corrections (omissions/inclusions etc.) as is needed. |
| 33 | # |
E. Scott Daniels | b4d2184 | 2021-02-24 13:26:27 -0500 | [diff] [blame] | 34 | set( major_version "1" ) |
subhash kumar singh | 43b6c8d | 2021-06-02 15:12:14 +0530 | [diff] [blame] | 35 | set( minor_version "1" ) |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 36 | set( patch_level "0" ) |
| 37 | |
| 38 | set( install_root "${CMAKE_INSTALL_PREFIX}" ) |
| 39 | set( install_inc "include/riclibe2ap" ) |
| 40 | if( MAN_PREFIX ) |
| 41 | set( install_man ${MAN_PREFIX} ) # is there a cmake var for this -- can't find one |
| 42 | else() |
| 43 | set( install_man "/usr/share/man" ) # this needs to be fixed so it's not hard coded |
| 44 | endif() |
| 45 | |
| 46 | # Must use GNUInstallDirs to install libraries into correct |
| 47 | # locations on all platforms. |
| 48 | include( GNUInstallDirs ) |
| 49 | |
| 50 | # externals may install using LIBDIR as established by the gnu include; it varies from system |
| 51 | # to system, and we don't trust that it is always set, so we default to lib if it is missing. |
| 52 | # |
| 53 | if( NOT CMAKE_INSTALL_LIBDIR ) |
| 54 | set( CMAKE_INSTALL_LIBDIR "lib" ) |
| 55 | endif() |
| 56 | |
| 57 | set( install_lib "${CMAKE_INSTALL_LIBDIR}" ) |
| 58 | message( "+++ riclibe2ap library install target directory: ${install_lib}" ) |
| 59 | |
| 60 | # ---------------- extract some things from git ------------------------------ |
| 61 | |
| 62 | # commit id for the version string |
| 63 | execute_process( |
| 64 | COMMAND bash -c "git rev-parse --short HEAD|awk '{printf\"%s\", $0}'" |
| 65 | OUTPUT_VARIABLE git_id |
| 66 | ) |
| 67 | |
| 68 | # version information for library names and version string |
| 69 | execute_process( |
| 70 | 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' " |
| 71 | OUTPUT_VARIABLE mmp_version_str |
| 72 | ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE |
| 73 | ) |
| 74 | message( "+++ mmp version from tag: '${mmp_version_str}'" ) |
| 75 | |
| 76 | # extra indicator to show that the build was based on modified file(s) and not the true commit |
| 77 | # (no hope of reproducing the exact library for debugging). Used only for the internal version |
| 78 | # string. |
| 79 | execute_process( |
| 80 | COMMAND bash -c "git diff --shortstat|awk -v fmt=%s -v r=-rotten '{ s=r } END { printf( fmt, s ) }'" |
| 81 | OUTPUT_VARIABLE spoiled_str |
| 82 | ) |
| 83 | |
| 84 | # uncomment these lines once CI starts adding a tag on merge |
| 85 | #set( mmp_version ${mmp_version_str} ) |
| 86 | #list( GET mmp_version 0 major_version ) |
| 87 | #list( GET mmp_version 1 minor_version ) |
| 88 | #list( GET mmp_version 2 patch_level ) |
| 89 | |
| 90 | # define constants used in the version string, debugging, etc. |
| 91 | add_definitions( |
| 92 | -DGIT_ID=${git_id} |
| 93 | -DMAJOR_VER=${major_version} |
| 94 | -DMINOR_VER=${minor_version} |
| 95 | -DPATCH_VER=${patch_level} |
| 96 | ) |
| 97 | |
| 98 | # ---------------- suss out pkg gen tools so we don't fail generating packages that the system cannot support -------------- |
| 99 | |
| 100 | # deb packages use underbars, and package manager(s) seem to flip the *_64 processor type |
| 101 | # to the old (non-standard) amd64 string, so we do it here for consistency. Set -DPRESERVE_PTYPE=1 |
| 102 | # to prevent the flip. RPM packages will always be given the system generated processor type string. |
| 103 | # |
| 104 | if( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" ) |
| 105 | if( NOT PRESERVE_PTYPE ) |
| 106 | set( deb_sys_name "amd64" ) |
| 107 | else() |
| 108 | set( deb_sys_name ${CMAKE_SYSTEM_PROCESSOR} ) |
| 109 | endif() |
| 110 | else() |
| 111 | set( deb_sys_name ${CMAKE_SYSTEM_PROCESSOR} ) |
| 112 | endif() |
| 113 | unset( PRESERVE_PTYPE CACHE ) # we don't want this to persist |
| 114 | |
| 115 | set( rpm_sys_name ${CMAKE_SYSTEM_PROCESSOR} ) |
| 116 | |
| 117 | if( DEV_PKG ) |
| 118 | set( deb_pkg_name "riclibe2ap-dev" ) |
| 119 | set( rpm_pkg_name "riclibe2ap-devel" ) |
| 120 | else() |
| 121 | set( deb_pkg_name "riclibe2ap" ) |
| 122 | set( rpm_pkg_name "riclibe2ap" ) |
| 123 | endif() |
| 124 | |
| 125 | set( pkg_label "riclibe2ap${spoiled_str}-${major_version}.${minor_version}.${patch_level}-${sys_name}" ) |
| 126 | set( rpm_pkg_label "${rpm_pkg_name}${spoiled_str}-${major_version}.${minor_version}.${patch_level}-${rpm_sys_name}" ) |
| 127 | set( deb_pkg_label "${deb_pkg_name}${spoiled_str}_${major_version}.${minor_version}.${patch_level}_${deb_sys_name}" ) |
| 128 | message( "+++ pkg name: ${deb_pkg_label}.deb" ) |
| 129 | |
| 130 | set( gen_rpm 0 ) |
| 131 | find_program( rpm NAMES rpmbuild ) # rpm package gen requires this to be installed |
| 132 | if( "${rpm}" MATCHES "rpm-NOTFOUND" ) # cannot build rpm |
| 133 | set( pkg_list "DEB" ) |
| 134 | message( "### make package will generate only deb package; cannot find support to generate rpm packages" ) |
| 135 | else() |
| 136 | message( "+++ pkg name: ${rpm_pkg_label}.rpm" ) # debugging if we think we can gen rpm too |
| 137 | set( pkg_list "DEB;RPM" ) |
| 138 | set( gen_rpm 1 ) |
| 139 | message( "+++ make package will generate both deb and rpm packages" ) |
| 140 | endif() |
| 141 | |
| 142 | |
| 143 | |
| 144 | # bleeding cmake names are short novels; and when lines cannot be split they're a pain, so we create a synonym |
| 145 | set ( srcd "${CMAKE_CURRENT_SOURCE_DIR}" ) |
| 146 | |
| 147 | # this gets us round a chicken/egg problem. include files don't exist until make is run |
| 148 | # but Cmake insists on having these exist when we add them to include directories to |
| 149 | # enable code to find them after we build them. |
| 150 | # |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 151 | # the source directories need to be explicitly added here |
subhash kumar singh | 746aa4b | 2021-05-25 00:50:47 +0530 | [diff] [blame] | 152 | include_directories( "${srcd}/src/e2ap" "${srcd}/src/wrapper") |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 153 | |
| 154 | # Compiler flags |
| 155 | # |
| 156 | set( CMAKE_POSITION_INDEPENDENT_CODE ON ) |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 157 | set( CMAKE_C_FLAGS "-g -DASN_DISABLE_OER_SUPPORT" ) |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 158 | set( CMAKE_CPP_FLAGS "-g " ) |
| 159 | set( CMAKE_CXX_FLAGS "-g " ) |
| 160 | if( GPROF ) # if set, we'll set profiling flag on compiles |
| 161 | message( "+++ profiling is on" ) |
| 162 | set( CMAKE_C_FLAGS "-pg " ) |
| 163 | set( CMAKE_CPP_FLAGS "-pg " ) |
| 164 | else() |
| 165 | message( "+++ profiling is off" ) |
| 166 | endif() |
| 167 | unset( GPROF CACHE ) # we don't want this to persist |
| 168 | |
| 169 | |
| 170 | # --------------------- external building -------------------------------------------------------- |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 171 | # TESTING -- this likely can go, but until we are sure we don't have an external thing to pull/build |
| 172 | # keep it as an example |
| 173 | #execute_process( COMMAND git submodule update --init -- ext/jsmn |
| 174 | # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 175 | # ) |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 176 | |
| 177 | |
| 178 | # --------------------------------building -------------------------------------------------------- |
| 179 | # Include modules |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 180 | # |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 181 | add_subdirectory( src/e2ap ) |
subhash kumar singh | 746aa4b | 2021-05-25 00:50:47 +0530 | [diff] [blame] | 182 | add_subdirectory( src/wrapper ) |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 183 | |
| 184 | # shared and static libraries are built from the same object files. |
| 185 | # |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 186 | add_library( riclibe2ap SHARED |
subhash kumar singh | 746aa4b | 2021-05-25 00:50:47 +0530 | [diff] [blame] | 187 | "$<TARGET_OBJECTS:e2ap_objects>;$<TARGET_OBJECTS:wrapper_objects>;" |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 188 | ) |
| 189 | set_target_properties( riclibe2ap |
| 190 | PROPERTIES |
| 191 | OUTPUT_NAME "riclibe2ap" |
| 192 | SOVERSION ${major_version} |
| 193 | VERSION ${major_version}.${minor_version}.${patch_level} |
| 194 | ) |
| 195 | |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 196 | # we only build/export the static archive (.a) if generating a dev package |
| 197 | if( DEV_PKG ) |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 198 | add_library( riclibe2ap_static STATIC |
subhash kumar singh | 746aa4b | 2021-05-25 00:50:47 +0530 | [diff] [blame] | 199 | "$<TARGET_OBJECTS:e2ap_objects>;$<TARGET_OBJECTS:wrapper_objects>;" |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 200 | ) |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 201 | set_target_properties( riclibe2ap_static |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 202 | PROPERTIES |
| 203 | OUTPUT_NAME "riclibe2ap" |
| 204 | SOVERSION ${major_version} |
| 205 | VERSION ${major_version}.${minor_version}.${patch_level} |
| 206 | ) |
| 207 | endif() |
| 208 | |
| 209 | # -------- unit testing ------------------------------------------------------- |
E. Scott Daniels | 9a5c363 | 2021-02-08 16:13:49 -0500 | [diff] [blame] | 210 | # There are no real tests as the code is generated, but CI might need/want to |
| 211 | # be able to run 'make test'. This allows for it. |
| 212 | # |
| 213 | enable_testing() |
| 214 | add_test( |
| 215 | NAME drive_unit_tests |
| 216 | COMMAND bash ../test/unit_test.sh -q CMBUILD=${CMAKE_CURRENT_BINARY_DIR} |
| 217 | WORKING_DIRECTORY ../test |
| 218 | ) |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 219 | |
| 220 | |
| 221 | # ------------- packaging ----------------------------------------------------- |
| 222 | |
| 223 | # Define what should be installed, and where they should go. For dev package we install |
| 224 | # only the RMr headers, man pages and archive (.a) files. The run-time package gets just |
| 225 | # the library (.so) files and nothing more. |
| 226 | # |
| 227 | if( DEV_PKG ) |
E. Scott Daniels | e6b9f97 | 2021-02-08 15:26:40 -0500 | [diff] [blame] | 228 | set( target_list "riclibe2ap_static" ) |
E. Scott Daniels | 5a5c63c | 2021-02-05 09:36:46 -0500 | [diff] [blame] | 229 | else() |
| 230 | set( target_list "riclibe2ap" ) |
| 231 | endif() |
| 232 | |
| 233 | install( TARGETS ${target_list} EXPORT LibraryConfig |
| 234 | LIBRARY DESTINATION ${install_lib} |
| 235 | ARCHIVE DESTINATION ${install_lib} |
| 236 | PUBLIC_HEADER DESTINATION ${install_inc} |
| 237 | ) |
| 238 | |
| 239 | unset( DEV_PKG CACHE ) # prevent from being a hidden setting if user redoes things |
| 240 | |
| 241 | IF( EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake" ) |
| 242 | include( InstallRequiredSystemLibraries ) |
| 243 | |
| 244 | set( CPACK_DEBIAN_PACKAGE_NAME ${deb_pkg_name} ) |
| 245 | set( CPACK_RPM_PACKAGE_NAME ${rpm_pkg_name} ) |
| 246 | |
| 247 | set( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/local;/usr/local/bin;/usr/local/include;/usr/local/share;/usr/local/lib" ) |
| 248 | |
| 249 | set( CPACK_set_DESTDIR "on" ) |
| 250 | set( CPACK_PACKAGING_INSTALL_PREFIX "${install_root}" ) |
| 251 | set( CPACK_GENERATOR "${pkg_list}" ) |
| 252 | |
| 253 | set( CPACK_PACKAGE_DESCRIPTION "C++ framework for RIC xAPPs based on RMR." ) |
| 254 | set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "RIC xAPP C++ framework library" ) |
| 255 | set( CPACK_PACKAGE_VENDOR "None" ) |
| 256 | set( CPACK_PACKAGE_CONTACT "None" ) |
| 257 | set( CPACK_PACKAGE_VERSION_MAJOR "${major_version}" ) |
| 258 | set( CPACK_PACKAGE_VERSION_MINOR "${minor_version}" ) |
| 259 | set( CPACK_PACKAGE_VERSION_PATCH "${patch_level}" ) |
| 260 | set( CPACK_PACKAGE "${pkg_label}" ) # generic name for old versions of cpack |
| 261 | set( CPACK_DEBIAN_FILE_NAME "${deb_pkg_label}.deb" ) |
| 262 | set( CPACK_RPM_FILE_NAME "${rpm_pkg_label}.rpm" ) |
| 263 | |
| 264 | # Future: define dependencies on RMR and other libs |
| 265 | |
| 266 | set( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" ) |
| 267 | set( CPACK_DEBIAN_PACKAGE_SECTION "ric" ) |
| 268 | set( CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} ) |
| 269 | set( CPACK_RPM_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} ) |
| 270 | |
| 271 | # this seems ingnored if included |
| 272 | #set( CPACK_COMPONENTS_ALL Libraries ApplicationData ) |
| 273 | |
| 274 | INCLUDE( CPack ) |
| 275 | ENDIF() |