blob: de817248f17a0d5cf7d0cd9fa77a886956f0e544 [file] [log] [blame]
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -05001#==================================================================================
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
25project( libe2ap )
26cmake_minimum_required( VERSION 3.5 )
27
E. Scott Danielse6b9f972021-02-08 15:26:40 -050028#
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 Danielsb4d21842021-02-24 13:26:27 -050034set( major_version "1" )
35set( minor_version "0" )
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -050036set( patch_level "0" )
37
38set( install_root "${CMAKE_INSTALL_PREFIX}" )
39set( install_inc "include/riclibe2ap" )
40if( MAN_PREFIX )
41 set( install_man ${MAN_PREFIX} ) # is there a cmake var for this -- can't find one
42else()
43 set( install_man "/usr/share/man" ) # this needs to be fixed so it's not hard coded
44endif()
45
46# Must use GNUInstallDirs to install libraries into correct
47# locations on all platforms.
48include( 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#
53if( NOT CMAKE_INSTALL_LIBDIR )
54 set( CMAKE_INSTALL_LIBDIR "lib" )
55endif()
56
57set( install_lib "${CMAKE_INSTALL_LIBDIR}" )
58message( "+++ riclibe2ap library install target directory: ${install_lib}" )
59
60# ---------------- extract some things from git ------------------------------
61
62# commit id for the version string
63execute_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
69execute_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)
74message( "+++ 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.
79execute_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.
91add_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#
104if( ${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()
110else()
111 set( deb_sys_name ${CMAKE_SYSTEM_PROCESSOR} )
112endif()
113unset( PRESERVE_PTYPE CACHE ) # we don't want this to persist
114
115set( rpm_sys_name ${CMAKE_SYSTEM_PROCESSOR} )
116
117if( DEV_PKG )
118 set( deb_pkg_name "riclibe2ap-dev" )
119 set( rpm_pkg_name "riclibe2ap-devel" )
120else()
121 set( deb_pkg_name "riclibe2ap" )
122 set( rpm_pkg_name "riclibe2ap" )
123endif()
124
125set( pkg_label "riclibe2ap${spoiled_str}-${major_version}.${minor_version}.${patch_level}-${sys_name}" )
126set( rpm_pkg_label "${rpm_pkg_name}${spoiled_str}-${major_version}.${minor_version}.${patch_level}-${rpm_sys_name}" )
127set( deb_pkg_label "${deb_pkg_name}${spoiled_str}_${major_version}.${minor_version}.${patch_level}_${deb_sys_name}" )
128message( "+++ pkg name: ${deb_pkg_label}.deb" )
129
130set( gen_rpm 0 )
131find_program( rpm NAMES rpmbuild ) # rpm package gen requires this to be installed
132if( "${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" )
135else()
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" )
140endif()
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
145set ( 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 Danielse6b9f972021-02-08 15:26:40 -0500151# the source directories need to be explicitly added here
152include_directories( "${srcd}/src/e2ap" )
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500153
154# Compiler flags
155#
156set( CMAKE_POSITION_INDEPENDENT_CODE ON )
E. Scott Danielse6b9f972021-02-08 15:26:40 -0500157set( CMAKE_C_FLAGS "-g -DASN_DISABLE_OER_SUPPORT" )
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500158set( CMAKE_CPP_FLAGS "-g " )
159set( CMAKE_CXX_FLAGS "-g " )
160if( 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 " )
164else()
165 message( "+++ profiling is off" )
166endif()
167unset( GPROF CACHE ) # we don't want this to persist
168
169
170# --------------------- external building --------------------------------------------------------
E. Scott Danielse6b9f972021-02-08 15:26:40 -0500171# 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 Daniels5a5c63c2021-02-05 09:36:46 -0500176
177
178# --------------------------------building --------------------------------------------------------
179# Include modules
E. Scott Danielse6b9f972021-02-08 15:26:40 -0500180#
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500181add_subdirectory( src/e2ap )
182
183# shared and static libraries are built from the same object files.
184#
E. Scott Danielse6b9f972021-02-08 15:26:40 -0500185add_library( riclibe2ap SHARED
186 "$<TARGET_OBJECTS:e2ap_objects>;"
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500187)
188set_target_properties( riclibe2ap
189 PROPERTIES
190 OUTPUT_NAME "riclibe2ap"
191 SOVERSION ${major_version}
192 VERSION ${major_version}.${minor_version}.${patch_level}
193)
194
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500195# we only build/export the static archive (.a) if generating a dev package
196if( DEV_PKG )
E. Scott Danielse6b9f972021-02-08 15:26:40 -0500197 add_library( riclibe2ap_static STATIC
198 "$<TARGET_OBJECTS:e2ap_objects>;"
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500199 )
E. Scott Danielse6b9f972021-02-08 15:26:40 -0500200 set_target_properties( riclibe2ap_static
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500201 PROPERTIES
202 OUTPUT_NAME "riclibe2ap"
203 SOVERSION ${major_version}
204 VERSION ${major_version}.${minor_version}.${patch_level}
205 )
206endif()
207
208# -------- unit testing -------------------------------------------------------
E. Scott Daniels9a5c3632021-02-08 16:13:49 -0500209# There are no real tests as the code is generated, but CI might need/want to
210# be able to run 'make test'. This allows for it.
211#
212enable_testing()
213add_test(
214 NAME drive_unit_tests
215 COMMAND bash ../test/unit_test.sh -q CMBUILD=${CMAKE_CURRENT_BINARY_DIR}
216 WORKING_DIRECTORY ../test
217)
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500218
219
220# ------------- packaging -----------------------------------------------------
221
222# Define what should be installed, and where they should go. For dev package we install
223# only the RMr headers, man pages and archive (.a) files. The run-time package gets just
224# the library (.so) files and nothing more.
225#
226if( DEV_PKG )
E. Scott Danielse6b9f972021-02-08 15:26:40 -0500227 set( target_list "riclibe2ap_static" )
E. Scott Daniels5a5c63c2021-02-05 09:36:46 -0500228else()
229 set( target_list "riclibe2ap" )
230endif()
231
232install( TARGETS ${target_list} EXPORT LibraryConfig
233 LIBRARY DESTINATION ${install_lib}
234 ARCHIVE DESTINATION ${install_lib}
235 PUBLIC_HEADER DESTINATION ${install_inc}
236)
237
238unset( DEV_PKG CACHE ) # prevent from being a hidden setting if user redoes things
239
240IF( EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake" )
241 include( InstallRequiredSystemLibraries )
242
243 set( CPACK_DEBIAN_PACKAGE_NAME ${deb_pkg_name} )
244 set( CPACK_RPM_PACKAGE_NAME ${rpm_pkg_name} )
245
246 set( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/local;/usr/local/bin;/usr/local/include;/usr/local/share;/usr/local/lib" )
247
248 set( CPACK_set_DESTDIR "on" )
249 set( CPACK_PACKAGING_INSTALL_PREFIX "${install_root}" )
250 set( CPACK_GENERATOR "${pkg_list}" )
251
252 set( CPACK_PACKAGE_DESCRIPTION "C++ framework for RIC xAPPs based on RMR." )
253 set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "RIC xAPP C++ framework library" )
254 set( CPACK_PACKAGE_VENDOR "None" )
255 set( CPACK_PACKAGE_CONTACT "None" )
256 set( CPACK_PACKAGE_VERSION_MAJOR "${major_version}" )
257 set( CPACK_PACKAGE_VERSION_MINOR "${minor_version}" )
258 set( CPACK_PACKAGE_VERSION_PATCH "${patch_level}" )
259 set( CPACK_PACKAGE "${pkg_label}" ) # generic name for old versions of cpack
260 set( CPACK_DEBIAN_FILE_NAME "${deb_pkg_label}.deb" )
261 set( CPACK_RPM_FILE_NAME "${rpm_pkg_label}.rpm" )
262
263 # Future: define dependencies on RMR and other libs
264
265 set( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" )
266 set( CPACK_DEBIAN_PACKAGE_SECTION "ric" )
267 set( CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} )
268 set( CPACK_RPM_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} )
269
270 # this seems ingnored if included
271 #set( CPACK_COMPONENTS_ALL Libraries ApplicationData )
272
273 INCLUDE( CPack )
274ENDIF()