X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=CMakeLists.txt;h=17be9edb8dddfb313a816d3e121f275d9be749f9;hb=7c52a6ab0050917fc823989f1bbe7e40d62ee198;hp=65db51ca0af0ab00ceb1fb49fa4151a353845048;hpb=3ca996aaf32fe37d727b29d6fb88354365988561;p=ric-plt%2Flib%2Frmr.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 65db51c..17be9ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,24 +19,31 @@ # This CMake definition supports several -D command line options: # +# -DDEBUG=n Enable debugging level n # -DDEV_PKG=1 Development package configuration # -DBUILD_DOC=1 Man pages generated +# -DBUILD_NNG=1 Enable building of NNG and the RMR NNG based libraries +# -DIGNORE_LIBDIR=1 Installation of rmr libries is into /usr/local/lib and ignores +# value in CMAKE_INSTALL_LIBDIR. +# system preferred (typically /usr/local/lib64). # -DPRESERVE_PTYPE=1 Do not change the processor type when naming deb packages # -DPACK_EXTERNALS=1 Include external libraries used to build in the run-time package # (This makes some stand-alone unit testing of bindings possible, it # is not meant to be used for production package generation.) -# -DSKIP_EXTERNALS=1 Do not use Nano/NNG submodules when building; uee installed packages +# -DGPROF=1 Enable profiling compile time flags +# -DSKIP_EXTERNALS=1 Do not use NNG submodule when building; uee installed packages # -DMAN_PREFIX= Supply a path where man pages are installed (default: /usr/share/man) +# See ci/build_all for an example of how to build and test + project( rmr LANGUAGES C ) cmake_minimum_required( VERSION 3.5 ) -set( major_version "1" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this +set( major_version "4" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this set( minor_version "0" ) -set( patch_level "43" ) +set( patch_level "4" ) set( install_root "${CMAKE_INSTALL_PREFIX}" ) -set( install_lib "lib" ) set( install_inc "include/rmr" ) if( MAN_PREFIX ) set( install_man ${MAN_PREFIX} ) # is there a cmake var for this -- can't find one @@ -44,17 +51,24 @@ else() set( install_man "/usr/share/man" ) # this needs to be fixed so it's not hard coded endif() -# Must use GNUInstallDirs to install libraries into correct -# locations on all platforms. +# Must use GNUInstallDirs to install libraries into correct locations on all platforms. include( GNUInstallDirs ) -# nano/nng install using LIBDIR as established by the gnu include; it varies from system -# to system, and we don't trust that it is always set, so we default to lib. +# We install using LIBDIR as established by the gnu include; it varies from system +# to system, and we don't trust that it is always set, so we default to lib if it is missing. # if( NOT CMAKE_INSTALL_LIBDIR ) set( CMAKE_INSTALL_LIBDIR "lib" ) endif() +if( IGNORE_LIBDIR ) # if set, then force to lib otherwise use "system preference" + set( install_lib "lib" ) +else() + set( install_lib "${CMAKE_INSTALL_LIBDIR}" ) +endif() +unset(IGNORE_LIBDIR CACHE ) # we don't want this to persist +message( "+++ RMR library install target directory: ${install_lib}" ) + # ---------------- extract some things from git ------------------------------ # commit id for the version string @@ -69,6 +83,7 @@ execute_process( OUTPUT_VARIABLE mmp_version_str ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) +message( "+++ mmp version from tag: '${mmp_version_str}'" ) # extra indicator to show that the build was based on modified file(s) and not the true commit # (no hope of reproducing the exact library for debugging). Used only for the internal version @@ -84,19 +99,29 @@ execute_process( #list( GET mmp_version 1 minor_version ) #list( GET mmp_version 2 patch_level ) +if( DEBUG ) # if set, we'll set debugging on in the compile + set( debugging ${DEBUG} ) + message( "+++ debugging is being set to ${DEBUG}" ) +else() + set( debugging 0 ) + message( "+++ debugging is set to off" ) +endif() +unset( DEBUG CACHE ) # we don't want this to persist + -# define constants used in the version string +# define constants used in the version string, debugging, etc. add_definitions( -DGIT_ID=${git_id} -DMAJOR_VER=${major_version} -DMINOR_VER=${minor_version} -DPATCH_VER=${patch_level} + -DDEBUG=${debugging} ) # ---------------- suss out pkg gen tools so we don't fail generating packages that the system cannot support -------------- # deb packages use underbars, and package manager(s) seem to flip the *_64 processor type -# to the old (non-standard) amd64 string, so we do it here for consistency. Set -DPRESERVE_PTYPE=1 +# to the old (non-standard) amd64 string, so we do it here for consistency. Set -DPRESERVE_PTYPE=1 # to prevent the flip. RPM packages will always be given the system generated processor type string. # if( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" ) @@ -124,9 +149,8 @@ set( pkg_label "rmr${spoiled_str}-${major_version}.${minor_version}.${patch_leve set( rpm_pkg_label "${rpm_pkg_name}${spoiled_str}-${major_version}.${minor_version}.${patch_level}-${rpm_sys_name}" ) set( deb_pkg_label "${deb_pkg_name}${spoiled_str}_${major_version}.${minor_version}.${patch_level}_${deb_sys_name}" ) message( "+++ pkg name: ${deb_pkg_label}.deb" ) -message( "+++ pkg name: ${rpm_pkg_label}.rpm" ) -set( out_yml /tmp/build_output.yml ) # we will record package names (we record only untainted names) +#set( out_yml /tmp/build_output.yml ) # we will record package names (we record only untainted names) find_program( rpm NAMES rpmbuild ) # rpm package gen requires this to be installed set( gen_rpm 0 ) @@ -134,102 +158,67 @@ if( "${rpm}" MATCHES "rpm-NOTFOUND" ) # cannot build rpm set( pkg_list "DEB" ) message( "### make package will generate only deb package; cannot find support to generate rpm packages" ) else() + message( "+++ pkg name: ${rpm_pkg_label}.rpm" ) # debugging if we think we can gen rpm too set( pkg_list "DEB;RPM" ) set( gen_rpm 1 ) message( "+++ make package will generate both deb and rpm packages" ) endif() -execute_process( - COMMAND bash -c "printf '# RMr build generated list of package paths\n---\n' >${out_yml}" -) - -execute_process( - COMMAND bash -c " echo deb: ${CMAKE_CURRENT_BINARY_DIR}/${deb_pkg_label}.deb >>${out_yml}" -) - -if( gen_rpm ) - execute_process( - COMMAND bash -c " echo rpm: ${CMAKE_CURRENT_BINARY_DIR}/${rpm_pkg_label}.rpm >>${out_yml}" - ) -endif() - -execute_process( - COMMAND bash -c "printf '...\n' >>${out_yml}" -) - # ---------------- setup nano/nng things --------------------------------------- -if( NOT SKIP_EXTERNALS ) - set( need_ext 1 ) # we force dependences on these for right build order - execute_process( COMMAND git submodule update --init -- ext/nng - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - - execute_process( COMMAND git submodule update --init -- ext/nanomsg - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - if( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/ext/nng/CMakeLists.txt ) - message( FATAL_ERROR "cannot find nng in our git source as a submodule: Giving up" ) # this will abort which seems wrong, but tdam. - endif() - - include( ExternalProject ) - ExternalProject_Add( - ext_nng - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/nng" - CMAKE_ARGS "-DBUILD_SHARED_LIBS=1" - CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}" - BUILD_COMMAND "make" - UPDATE_COMMAND "" - TEST_COMMAND "" - STEP_TARGETS build - ) - ExternalProject_Add( - nanomsg - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanomsg" - BUILD_COMMAND "make" - UPDATE_COMMAND "" - CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}" - TEST_COMMAND "" - STEP_TARGETS build - ) - - # it seems impossible to install everything that lands in {bin}/lib, so we need to - # hard code (shudder) some things. Even worse, we have to make exceptions for - # builds on apple (osx) since their naming convention wandered off the path. - set( nng_major 1 ) - set( nng_minor 1.0 ) - set( nano_major 5 ) - set( nano_minor 1.0 ) - set( so ${CMAKE_SHARED_LIBRARY_SUFFIX} ) # cmake variables are impossibly long :( - if( NOT APPLE ) # probably breaks in windows, but idc - set( nng_so_suffix ${so} ) - set( nng_so_suffix_m ${so}.${nng_major} ) - set( nng_so_suffix_mm ${so}.${nng_major}.${nng_minor} ) - - set( nano_so_suffix ${so} ) - set( nano_so_suffix_m ${so}.${nano_major} ) - set( nano_so_suffix_mm ${so}.${nano_major}.${nano_minor} ) - else() - # of course apple puts versions before the suffix :( - set( nng_so_suffix ${so} ) # so has a lead dot, so NOT needed - set( nng_so_suffix_m ".${nng_major}${so}" ) # these need leading dots - set( nng_so_suffix_mm ".${nng_major}.${nng_minor}${so}" ) - - set( nano_so_suffix ${so} ) - set( nano_so_suffix_m ".${nano_major}${so}" ) - set( nano_so_suffix_mm ".${nano_major}.${nano_minor}${so}" ) - endif() - - message( "+++ installing nano/nng with: ${nano_major}.${nano_minor} | ${nng_major}.${nng_minor}" ) +if( NOT BUILD_NNG ) + set( PACK_EXTERNALS 0 ) else() - if( PACK_EXTERNALS ) - # This makes some stand-alone unit testing possible for bindings and transport layer testing; - # it is not meant for production packages. - # - unset( SKIP_EXTERNALS CACHE ) # must remove so as not to trap user into a never ending failure - unset( PACK_EXTERNALS CACHE ) - message( FATAL_ERROR "ERROR: PACK_EXTERNALS can be set only if SKIP_EXTERNALS is unset (=0, or not supplied on command line)" ) + if( NOT SKIP_EXTERNALS ) + set( need_ext 1 ) # we force dependences on these for right build order + execute_process( COMMAND git submodule update --init -- ext/nng + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + if( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/ext/nng/CMakeLists.txt ) + message( FATAL_ERROR "cannot find nng in our git source as a submodule: Giving up" ) # this will abort which seems wrong, but tdam. + endif() + + include( ExternalProject ) + ExternalProject_Add( + ext_nng + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/nng" + CMAKE_ARGS "-DBUILD_SHARED_LIBS=1" + CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}" + BUILD_COMMAND "make" + UPDATE_COMMAND "" + TEST_COMMAND "" + STEP_TARGETS build + ) + + # it seems impossible to install everything that lands in {bin}/lib, so we need to + # hard code (shudder) some things. Even worse, we have to make exceptions for + # builds on apple (osx) since their naming convention wandered off the path. + set( nng_major 1 ) + set( nng_minor 1.0 ) + set( so ${CMAKE_SHARED_LIBRARY_SUFFIX} ) # cmake variables are impossibly long :( + if( NOT APPLE ) # probably breaks in windows, but idc + set( nng_so_suffix ${so} ) + set( nng_so_suffix_m ${so}.${nng_major} ) + set( nng_so_suffix_mm ${so}.${nng_major}.${nng_minor} ) + else() + # of course apple puts versions before the suffix :( + set( nng_so_suffix ${so} ) # so has a lead dot, so NOT needed + set( nng_so_suffix_m ".${nng_major}${so}" ) # these need leading dots + set( nng_so_suffix_mm ".${nng_major}.${nng_minor}${so}" ) + endif() + + message( "+++ building with nng: ${nng_major}.${nng_minor}" ) + else() + if( PACK_EXTERNALS ) + # This makes some stand-alone unit testing possible for bindings and transport layer testing; + # it is not meant for production packages. + # + unset( SKIP_EXTERNALS CACHE ) # must remove so as not to trap user into a never ending failure + unset( PACK_EXTERNALS CACHE ) + message( FATAL_ERROR "ERROR: PACK_EXTERNALS can be set only if SKIP_EXTERNALS is unset (=0, or not supplied on command line)" ) + endif() + set( need_ext 0 ) endif() - set( need_ext 0 ) endif() @@ -245,98 +234,142 @@ include_directories( "${CMAKE_CURRENT_BINARY_DIR}/include" ) # Compiler flags # set( CMAKE_POSITION_INDEPENDENT_CODE ON ) -set( CMAKE_CXX_FLAGS "-g -Wall " ) +#set( CMAKE_C_FLAGS "-g -Wall " ) +#set( CMAKE_C_FLAGS "-g " ) +if( GPROF ) # if set, we'll set profiling flag on compiles + message( "+++ profiling is on" ) + set( CMAKE_C_FLAGS "-pg " ) +else() + message( "+++ profiling is off" ) + set( CMAKE_C_FLAGS "-g " ) +endif() +unset( GPROF CACHE ) # we don't want this to persist # Include modules add_subdirectory( src/rmr/common ) -add_subdirectory( src/rmr/nanomsg ) -add_subdirectory( src/rmr/nng ) +if( BUILD_NNG ) + add_subdirectory( src/rmr/nng ) +endif() +add_subdirectory( src/rmr/si ) add_subdirectory( doc ) # this will auto skip if {X}fm is not available # shared and static libraries are built from the same object files. -# Nanomsg based library (librmr ) while nng based is librmr_nng. -# library is built by pulling object files from either the nano or nng and common subdirs +# librmr_* is a combination of common and * specific rmr functions. # -add_library( rmr_shared SHARED "$;$" ) -set_target_properties( rmr_shared - PROPERTIES - OUTPUT_NAME "rmr" +if( BUILD_NNG ) + add_library( rmr_nng_shared SHARED "$;$" ) + set_target_properties( rmr_nng_shared + PROPERTIES + OUTPUT_NAME "rmr_nng" SOVERSION ${major_version} VERSION ${major_version}.${minor_version}.${patch_level} ) -add_library( rmr_nng_shared SHARED "$;$" ) -set_target_properties( rmr_nng_shared + # we only build/export the static archive (.a) if generating a dev package + if( DEV_PKG ) + add_library( rmr_nng_static STATIC "$;$" ) + set_target_properties( rmr_nng_static + PROPERTIES + OUTPUT_NAME "rmr_nng" + SOVERSION ${major_version} + VERSION ${major_version}.${minor_version}.${patch_level} ) + endif() +endif() + +add_library( rmr_si_shared SHARED "$;$" ) +set_target_properties( rmr_si_shared PROPERTIES - OUTPUT_NAME "rmr_nng" + OUTPUT_NAME "rmr_si" SOVERSION ${major_version} VERSION ${major_version}.${minor_version}.${patch_level} ) -# we only build/export the static archive (.a) if generating a dev package -if( DEV_PKG ) - add_library( rmr_nng_static STATIC "$;$" ) - set_target_properties( rmr_nng_static - PROPERTIES - OUTPUT_NAME "rmr_nng" - SOVERSION ${major_version} - VERSION ${major_version}.${minor_version}.${patch_level} ) - - add_library( rmr_static STATIC "$;$" ) - - set_target_properties( rmr_static - PROPERTIES - OUTPUT_NAME "rmr" - SOVERSION ${major_version} - VERSION ${major_version}.${minor_version}.${patch_level} ) -endif() +# even if not generating a development package we still need to generate the .a so that health check +# can link against it to avoid RPM install issues. +# +add_library( rmr_si_static STATIC "$;$" ) +set_target_properties( rmr_si_static + PROPERTIES + OUTPUT_NAME "rmr_si" + SOVERSION ${major_version} + VERSION ${major_version}.${minor_version}.${patch_level} ) -# if externals need to be built, then we must force them to be built first by depending on them -if( need_ext ) - if( DEV_PKG ) - add_dependencies( rmr_static;rmr_shared nanomsg ) - add_dependencies( rmr_nng_shared;rmr_nng_static ext_nng ) - else() - add_dependencies( rmr_shared nanomsg ) - add_dependencies( rmr_nng_shared ext_nng ) +if( BUILD_NNG ) + # if externals need to be built, then we must force them to be built first by depending on them + if( need_ext ) + if( DEV_PKG ) + add_dependencies( rmr_nng_shared;rmr_nng_static ext_nng ) + else() + add_dependencies( rmr_nng_shared ext_nng ) + endif() endif() endif() +# ------------- testing ------------------------------------------------------- +enable_testing() +# cmake cannot set env vars, so we have to passed desired vars on the wrapper command +add_test( + NAME drive_unit_tests + COMMAND bash ../test/run_unit_tests.sh CMBUILD=${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ../test +) + +# cmake seems unable to start test/app_test/run_all.ksh, so we have to lump +# a dummy script in ./test that does the obvious thing. +add_test( + NAME drive_app + COMMAND bash ./run_app_tests.sh LD_LIBRARY_PATH=${install_root}/lib C_INCLUDE_PATH=${install_root}/include CMBUILD=${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ../test +) + + +# --- support binaries that depend on the libs identified above --------------- +add_subdirectory( src/support ) + +# ------------- packaging ----------------------------------------------------- + # -if( APPLE ) - message( "### apple hack: forcing hard coded library paths for nng/nano dynamic libraries" ) - target_link_libraries( rmr_shared ${CMAKE_CURRENT_BINARY_DIR}/lib/libnanomsg${nano_so_suffix} ) - target_link_libraries( rmr_nng_shared ${CMAKE_CURRENT_BINARY_DIR}/lib/libnng${nng_so_suffix} ) +if( BUILD_NNG ) + if( APPLE ) + message( "### apple hack: forcing hard coded library paths for nng/nano dynamic libraries" ) + target_link_libraries( rmr_nng_shared ${CMAKE_CURRENT_BINARY_DIR}/lib/libnng${nng_so_suffix} ) + endif() endif() # Define what should be installed, and where they should go. For dev package we install # only the RMr headers, man pages and archive (.a) files. The run-time package gets just # the library (.so) files and nothing more. # -if( DEV_PKG ) - set( target_list "rmr_nng_static;rmr_static" ) +if( BUILD_NNG ) + if( DEV_PKG ) + set( target_list "rmr_nng_static;rmr_si_static" ) + else() + set( target_list "rmr_nng_shared;rmr_si_shared" ) + endif() else() - set( target_list "rmr_nng_shared;rmr_shared" ) + if( DEV_PKG ) + set( target_list "rmr_si_static" ) + else() + set( target_list "rmr_si_shared" ) + endif() endif() install( TARGETS ${target_list} EXPORT LibraryConfig - LIBRARY DESTINATION ${install_lib} - ARCHIVE DESTINATION ${install_lib} - PUBLIC_HEADER DESTINATION ${install_inc} + LIBRARY DESTINATION ${install_lib} + ARCHIVE DESTINATION ${install_lib} + PUBLIC_HEADER DESTINATION ${install_inc} ) -unset( DEV_PKG CACHE ) # prevent from being a hiddent setting if user redoes things +unset( DEV_PKG CACHE ) # prevent from being a hidden setting if user redoes things # install any nano/nng libraries in to the deb as well, but ONLY if asked for on the 'cmake ..' command -# (sure would be nice if FILEs allowed for globbing; sadlyy it does not.) +# (sure would be nice if FILEs allowed for globbing; sadly it does not.) Disabled by default if BUILD_NNG +# is turned off. # if( PACK_EXTERNALS ) message( "+++ including nano and nng libraries in the deb" ) install( FILES - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libnanomsg${nano_so_suffix} - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libnanomsg${nano_so_suffix_m} - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libnanomsg${nano_so_suffix_mm} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libnng${nng_so_suffix} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libnng${nng_so_suffix_m} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libnng${nng_so_suffix_mm} @@ -354,6 +387,9 @@ IF( EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake" ) set( CPACK_DEBIAN_PACKAGE_NAME ${deb_pkg_name} ) set( CPACK_RPM_PACKAGE_NAME ${rpm_pkg_name} ) + # auto dependency checking makes the RPM install fail, see NOTES + set( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION="/usr/local /usr/local/bin /usr/local/lib" ) + set( CPACK_set_DESTDIR "on" ) set( CPACK_PACKAGING_INSTALL_PREFIX "${install_root}" ) set( CPACK_GENERATOR "${pkg_list}" ) @@ -369,7 +405,7 @@ IF( EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake" ) set( CPACK_DEBIAN_FILE_NAME "${deb_pkg_label}.deb" ) set( CPACK_RPM_FILE_NAME "${rpm_pkg_label}.rpm" ) - # we build and ship the libraries, so there is NO dependency + # there is not an NNG package, so we cannot define a dependency set( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" ) set( CPACK_DEBIAN_PACKAGE_SECTION "ric" )