Back to home page

Enduro/X

 
 

    


0001 ##
0002 ## @brief Enduro Execution platform main Make descriptor
0003 ##
0004 ## @file CMakeLists.txt
0005 ##
0006 ## -----------------------------------------------------------------------------
0007 ## Enduro/X Middleware Platform for Distributed Transaction Processing
0008 ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009 ## Copyright (C) 2017-2018, Mavimax, Ltd. All Rights Reserved.
0010 ## This software is released under one of the following licenses:
0011 ## AGPL or Mavimax's license for commercial use.
0012 ## -----------------------------------------------------------------------------
0013 ## AGPL license:
0014 ## 
0015 ## This program is free software; you can redistribute it and/or modify it under
0016 ## the terms of the GNU Affero General Public License, version 3 as published
0017 ## by the Free Software Foundation;
0018 ##
0019 ## This program is distributed in the hope that it will be useful, but WITHOUT ANY
0020 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0021 ## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0022 ## for more details.
0023 ##
0024 ## You should have received a copy of the GNU Affero General Public License along 
0025 ## with this program; if not, write to the Free Software Foundation, Inc., 
0026 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0027 ##
0028 ## -----------------------------------------------------------------------------
0029 ## A commercial use license is available from Mavimax, Ltd
0030 ## contact@mavimax.com
0031 ## -----------------------------------------------------------------------------
0032 ##
0033 
0034 cmake_minimum_required (VERSION 2.6) 
0035 project (ENDUROX) 
0036 set(VERSION "6.0.25")
0037 set(PROJ_NAME "Enduro/X")
0038 set(RELEASE "1")
0039 
0040 
0041 ################################################################################
0042 # OS Configuration
0043 ################################################################################
0044 
0045 EXEC_PROGRAM(uname ARGS -a OUTPUT_VARIABLE _TMP_CMAKE_OS_NAME)
0046 string(REGEX MATCH "^[a-zA-Z0-9-]*" _TMP_CMAKE_OS_NAME_EXTR ${_TMP_CMAKE_OS_NAME})
0047 string(TOUPPER ${_TMP_CMAKE_OS_NAME_EXTR} CMAKE_OS_NAME)
0048 
0049 # Force C++ for C
0050 #SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
0051 
0052 message("CMake CMAKE_OS_NAME  = ${CMAKE_OS_NAME}")
0053 message("CMake CMAKE_C_COMPILER_ID  = ${CMAKE_C_COMPILER_ID}")
0054 message("CMake CMAKE_CXX_COMPILER_ID  = ${CMAKE_CXX_COMPILER_ID}")
0055 
0056 OPTION(DEFINE_FORCEPOLL "Force POLL (even on linux)" OFF)
0057 OPTION(DEFINE_FORCEFDPOLL "Force FDPOLL" OFF)
0058 OPTION(DEFINE_FORCEKQUEUE "Force Kqueue (BSD poll framework)" OFF)
0059 
0060 OPTION(DEFINE_RELEASEBUILD "Do relesae build" OFF)
0061 OPTION(DEFINE_FORCEEMQ "Force Emulated Message Queue" OFF)
0062 OPTION(DEFINE_SYSVQ "Force System V Message Queue" OFF)
0063 OPTION(DEFINE_ALIGNMENT_FORCE "Force alignment" OFF)
0064 OPTION(DEFINE_SANITIZE "Enable GCC/Clang Address Sanitizer (for debug)" OFF)
0065 
0066 SET (EX_ALIGNMENT_BYTES "4")
0067 
0068 SET ( CMAKE_CXX_FLAGS "-O2 -fno-exceptions -fno-rtti" CACHE STRING "compile flags" FORCE)
0069 
0070 # Support #310 Ubuntu 18.04 prints lot of unneeded warnings...
0071 if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
0072 #    SET(CMAKE_C_FLAGS "-Wno-format-truncation -Wstringop-overflow=0 -D_DEFAULT_SOURCE=1 ${CMAKE_C_FLAGS}")
0073     SET(CMAKE_C_FLAGS "-Wno-stringop-overflow -Wno-format-truncation -Wformat-overflow=0 ${CMAKE_C_FLAGS}")
0074 endif()
0075 
0076 # Enable release only if specified.
0077 # By default if RELEASE_BUILD is not defined, then we run in debug!
0078 IF (DEFINE_RELEASEBUILD)
0079         MESSAGE( RELEASE_BUILD )
0080         SET(CMAKE_BUILD_TYPE release)
0081         SET(CMAKE_C_FLAGS "-fstack-protector -O2 ${CMAKE_C_FLAGS}")
0082 ELSE ()
0083         MESSAGE( DEBUG_BUILD )
0084         SET(CMAKE_BUILD_TYPE debug)
0085 # Memory debugging:
0086 #       SET(CMAKE_C_FLAGS "-fsanitize=alignment -fsanitize=address -fno-omit-frame-pointer -O1 -ggdb ${CMAKE_C_FLAGS}")
0087 
0088     IF (DEFINE_SANITIZE)
0089         SET(CMAKE_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -O1 -ggdb ${CMAKE_C_FLAGS}")
0090     ELSE ()
0091         SET(CMAKE_C_FLAGS "-fstack-protector -O2 -ggdb ${CMAKE_C_FLAGS}")
0092     ENDIF()
0093 ENDIF ()
0094 
0095 # -pthread needed for System V pthread_atfork()
0096 SET(RT_LIB rt dl)
0097 if( ${CMAKE_OS_NAME} STREQUAL "LINUX" )
0098 
0099     set(EX_OS_LINUX "1")
0100     set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0101 
0102     # gnu pg fixes for rpi
0103     if(EXISTS "/opt/vc/include/bcm_host.h")
0104         SET(CMAKE_C_FLAGS "-D_FILE_OFFSET_BITS=64 ${CMAKE_C_FLAGS}")
0105     endif()
0106 
0107     # Configure backend transport
0108     IF(DEFINE_SYSVQ)
0109         message("Linux - forced poll()")
0110         set(EX_USE_SYSVQ "1")
0111     ELSEIF(DEFINE_FORCEPOLL)
0112         message("Linux - forced poll()")
0113         set(EX_USE_POLL "1")
0114     ELSEIF(DEFINE_FORCEFDPOLL)
0115         message("Linux - forced fdpoll()")
0116         set(EX_USE_FDPOLL "1")
0117     ELSEIF(DEFINE_FORCEEMQ)
0118         message("Linux - forced emulated message q")
0119         set(EX_USE_EMQ "1")
0120         set(EX_USE_POLL "1")
0121     ELSE()
0122         message("Linux - forced epoll()")
0123         set(EX_USE_EPOLL "1")
0124     ENDIF()
0125 elseif(${CMAKE_OS_NAME} STREQUAL "AIX")
0126 # Configure the compiler, we support XLC too..
0127 
0128         message("No threads mode for CPM - bit slower child process exit status check...")
0129         # Seems aix 7.1 does not like threads mixed with fork...
0130         set(EX_CPM_NO_THREADS "1")
0131         set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0132 
0133         if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
0134             message("GNU compiler")
0135             set ( CMAKE_C_FLAGS "-D_SEM_SEMUN_UNDEFINED -D_THREAD_SAFE -pthread -maix64 ${CMAKE_C_FLAGS}")
0136         elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "XL")
0137             message("XL compiler")
0138             set ( CMAKE_C_FLAGS " -D_SEM_SEMUN_UNDEFINED -D_THREAD_SAFE ")
0139             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qwarn64 -qpic -bexpfull -b64")
0140             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -brtl -qtls -q64 -qlanglvl=extc99")
0141             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-997 -qprocimported=setjmp -lbsd")
0142             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-747")
0143             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-742")
0144             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-743")
0145             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-744")
0146             set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-745")
0147 
0148             if (NOT DEFINE_RELEASEBUILD)
0149                     message("XL compiler: with -g (debug symbols...)")
0150                     set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
0151             endif()
0152         endif()
0153 
0154     set(EX_USE_SYSVQ "1")
0155     set(EX_OS_AIX "1")
0156 elseif(${CMAKE_OS_NAME} STREQUAL "HP-UX")
0157     set(EX_USE_POLL "1")
0158     set(EX_OS_HPUX "1")
0159     set(NDRX_LD_LIBRARY_PATH "SHLIB_PATH")
0160 elseif(${CMAKE_OS_NAME} STREQUAL "SUNOS")
0161     set(EX_CPM_NO_THREADS "1")
0162     set(EX_OS_SUNOS "1")
0163     set(EX_USE_SYSVQ "1")
0164     set(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -m64")
0165     set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -m64")
0166 
0167     set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0168     # Bug #219 !!! _REENTRANT makes errno thread safe
0169     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT")
0170 
0171     if ("${CMAKE_C_COMPILER_ID}" STREQUAL "SunPro")
0172         # set new config for SunPro
0173         SET(CMAKE_C_FLAGS "-D_REENTRANT -m64")
0174         message("SUN Studio compiler (building for 64bit) ")
0175 
0176         # Bug #219 !!! _REENTRANT makes errno thread safe
0177         # For GNU I guess 
0178         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -errtags -fast -xc99=all -erroff=E_PTR_TO_VOID_IN_ARITHMETIC ")
0179         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_EMPTY_MBR_DECLARATION -erroff=E_NO_IMPLICIT_DECL_ALLOWED")
0180         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_EMPTY_DECLARATION -erroff=E_ARGUEMENT_MISMATCH -erroff=E_ZERO_OR_NEGATIVE_SUBSCRIPT")
0181         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_ARG_INCOMPATIBLE_WITH_ARG_L")
0182         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_BAD_PTR_INT_COMBINATION")
0183 
0184         # Add Sun Studio C runtime
0185         SET(RT_LIB ${RT_LIB} Crun)
0186     endif()
0187 
0188 elseif(${CMAKE_OS_NAME} STREQUAL "FREEBSD")
0189     set(RT_LIB rt)
0190     # seem that threading model also does not work here...
0191     set(EX_CPM_NO_THREADS "1")
0192     set(EX_OS_FREEBSD "1")
0193     # Best option...
0194     set(EX_USE_KQUEUE "1")
0195     set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0196 elseif(${CMAKE_OS_NAME} STREQUAL "CYGWIN")
0197     set(EX_OS_CYGWIN "1")
0198     set(EX_USE_POLL "1")
0199     set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0200 elseif(${CMAKE_OS_NAME} STREQUAL "DARWIN")
0201     set(RT_LIB dl)
0202     set(EX_OS_DARWIN "1")
0203     set(EX_USE_EMQ "1")
0204     set(EX_USE_POLL "1")
0205     set(NDRX_LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH")
0206 # Unknown OS:
0207 else()
0208         message( FATAL_ERROR "Unsupported OS" )
0209 endif()
0210 
0211 IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
0212     set(EX_ALIGNMENT_BYTES "8")
0213     set(EX_ALIGNMENT_FORCE "1")
0214 ENDIF ()
0215 
0216 IF (DEFINE_ALIGNMENT_FORCE)
0217     set(EX_ALIGNMENT_FORCE "1")
0218 ENDIF()
0219 
0220 IF(EX_USE_SYSVQ)
0221     set(EX_POLLER_STR   "SystemV")
0222 ELSEIF(EX_USE_FDPOLL)
0223     set(EX_POLLER_STR   "fdpoll")
0224 ELSEIF(EX_USE_EMQ)
0225     set(EX_POLLER_STR   "emq")
0226 ELSEIF(EX_USE_POLL)
0227     set(EX_POLLER_STR   "poll")
0228 ELSEIF(EX_USE_EPOLL)
0229     set(EX_POLLER_STR   "epoll")
0230 ELSEIF(EX_USE_KQUEUE)
0231     set(EX_POLLER_STR   "kqueue")
0232 ELSE()
0233     message( FATAL_ERROR "ERROR! Invalid queue transport backend!" )
0234 ENDIF()
0235 
0236 message("CMake EX_ALIGNMENT_BYTES  = ${EX_ALIGNMENT_BYTES}")
0237 message("Poller  = ${EX_POLLER_STR}")
0238 message("ALIGNMENT_FORCE  = ${EX_ALIGNMENT_FORCE}")
0239 
0240 ################################################################################
0241 # "Configure"
0242 ################################################################################
0243 
0244 # In this file we are doing all of our 'configure' checks. Things like checking
0245 # for headers, functions, libraries, types and size of types.
0246 INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
0247 INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
0248 INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
0249 INCLUDE (${CMAKE_ROOT}/Modules/CheckCSourceCompiles.cmake)
0250 INCLUDE (${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake)
0251 INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
0252 INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
0253 
0254 
0255 CHECK_C_SOURCE_COMPILES("extern const char * __progname; int main() {return __progname[0];}" HAVE_PROGNAME)
0256 CHECK_C_SOURCE_COMPILES("int main() {__builtin_expect(1, 1);}" HAVE_EXPECT)
0257 CHECK_C_SOURCE_COMPILES("int main() { int X = 0; __sync_bool_compare_and_swap(&X, 0, 1); __sync_synchronize();}" HAVE_SYNC)
0258 CHECK_C_SOURCE_COMPILES("#include <stdio.h> \n int main() {char buf[128]; size_t len; getline(buf, &len, stdin);}" HAVE_GETLINE)
0259 CHECK_C_SOURCE_COMPILES("#include <string.h> \n int main() {char dest[1]; char src[1]; strlcpy(dest, src, 1);}" HAVE_STRLCPY)
0260 CHECK_C_SOURCE_COMPILES("#include <string.h> \n int main() {strnlen(\"ABC\", 1);}" HAVE_STRNLEN)
0261 CHECK_C_SOURCE_COMPILES("#include <string.h> \n int main() {char tmp[8]={0x0}; strcat_s(tmp, sizeof(tmp), \"abc\");}" EX_HAVE_STRCAT_S)
0262 CHECK_C_SOURCE_COMPILES("#include <string.h> \n int main() {char *tmp; asprintf(&tmp, \"HELLO\");}" EX_HAVE_ASPRINTF)
0263 
0264 # To check for an include file you do this: 
0265 CHECK_INCLUDE_FILE("stdint.h"        HAVE_STDINT_H)
0266 CHECK_INCLUDE_FILE("getopt.h"       HAVE_GETOPT_H)
0267         
0268 
0269 # To check the size of a primitive type:
0270 CHECK_TYPE_SIZE("int"   EX_SIZEOF_INT)
0271 CHECK_TYPE_SIZE("long"  EX_SIZEOF_LONG)
0272 CHECK_TYPE_SIZE("void*"  EX_SIZEOF_VOIDPTR)
0273 
0274 MATH (EXPR EX_PLATFORM_BITS "${EX_SIZEOF_VOIDPTR} * 8")
0275 
0276 IF (DEFINE_DISABLEPSCRIPT)
0277     set(NDRX_DISABLEPSCRIPT "1")
0278 ENDIF()
0279 
0280 IF (DEFINE_SANITIZE)
0281     set(NDRX_SANITIZE "1")
0282 ENDIF()
0283 
0284 # Output the project version
0285 set(NDRX_VERSION_STR "${PROJ_NAME} ${VERSION}")
0286 
0287 ################################################################################
0288 # Install dir config
0289 ################################################################################
0290 get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
0291 
0292 message("LIB: ${LIB64}")
0293 
0294 if(${CMAKE_OS_NAME} STREQUAL "DARWIN")
0295     set(LIB_SUFFIX "")
0296 # Seems like BSD does not use lib64 folder
0297 elseif ("${CMAKE_OS_NAME}" STREQUAL "FREEBSD")
0298     set(LIB_SUFFIX "")
0299 elseif ("${LIB64}" STREQUAL "TRUE")
0300     set(LIB_SUFFIX 64)
0301 else()
0302     set(LIB_SUFFIX "")
0303 endif()
0304 
0305 message("LIB_SUFFIX: ${LIB_SUFFIX}")
0306 
0307 set(INSTALL_LIB_DIR lib${LIB_SUFFIX} CACHE PATH "Installation directory for libraries")
0308 
0309 message("INSTALL_LIB_DIR: ${INSTALL_LIB_DIR}")
0310 
0311 mark_as_advanced(INSTALL_LIB_DIR) 
0312 MESSAGE( STATUS "INSTALL_LIB_DIR: " ${INSTALL_LIB_DIR} )
0313 
0314 ################################################################################
0315 # Options
0316 ################################################################################
0317 
0318 # Option to disable gpg-me (gpg-me enabled by default)
0319 
0320 OPTION(DEFINE_DISABLEGPGME "Use GPG-ME encryption" OFF)
0321  
0322 IF(DEFINE_DISABLEGPGME)
0323     ADD_DEFINITIONS(-DDISABLEGPGME)
0324 ENDIF(DEFINE_DISABLEGPGME)
0325 
0326 OPTION(DEFINE_DISABLEPSCRIPT "Disable Platform Script" OFF)
0327 ###############################################################################
0328 
0329 ################################################################################
0330 # Option to disable documentation build (dos are enabled by default)
0331 OPTION(DEFINE_DISABLEDOC "Disable documentation generation" OFF) 
0332 ################################################################################
0333 
0334 ################################################################################
0335 # Submakes
0336 ################################################################################
0337 # Recurse into the project subdirectories. This does not actually
0338 # cause another cmake executable to run. The same process will walk through 
0339 # the project's entire directory structure. 
0340 add_subdirectory (libnstd)
0341 add_subdirectory (embedfile)
0342 add_subdirectory (libcgreen)
0343 add_subdirectory (libexuuid)
0344 add_subdirectory (libubf)
0345 add_subdirectory (libnetproto)
0346 add_subdirectory (libexthpool)
0347 add_subdirectory (ubftest)
0348 add_subdirectory (mkfldhdr)
0349 # Enduro/X sub-directories for ATMI
0350 add_subdirectory (libatmi) # General Purpose ATMI library
0351 add_subdirectory (libatmisrv) #  ATMI server library 
0352 add_subdirectory (libatmiclt) #  ATMI client library 
0353 add_subdirectory (libexnet)
0354 add_subdirectory (libexmemck)
0355 add_subdirectory (libndrxconf)
0356 
0357 IF (NOT DEFINE_DISABLEPSCRIPT)
0358         add_subdirectory (libps) # Platform script
0359         add_subdirectory (libpsstdlib) # Platform script standard library
0360 ENDIF()
0361 
0362 add_subdirectory (tpevsrv)
0363 add_subdirectory (tpcachesv)
0364 add_subdirectory (tpcached)
0365 add_subdirectory (tprecover) # Special recovery server
0366 add_subdirectory (tpbrdcstsv) # tpbroadcast remote machine dispatcher
0367 add_subdirectory (ud)
0368 
0369 
0370 IF (NOT DEFINE_DISABLEPSCRIPT)
0371         add_subdirectory (pscript) # Platform script interpreter
0372 ENDIF()
0373 
0374 add_subdirectory (viewc) # View compiler
0375 add_subdirectory (ndrxd) # Enduro X daemon
0376 add_subdirectory (xadmin) # Enduro X command line interface
0377 add_subdirectory (lmdb_util) # LMDB/EXDB Admin utilities
0378 add_subdirectory (xmemck) # Enduro X memcory checking tool
0379 add_subdirectory (bridge) # Cluster bridge server
0380 add_subdirectory (tmsrv) # Transaction Manager server for XA transactions
0381 add_subdirectory (tmqueue) # Persistant Queue server
0382 add_subdirectory (cpmsrv) # Client Process Monitor
0383 add_subdirectory (xadrv) # XA Drivers for RMs
0384 add_subdirectory (cconfsrv) # Common-Config server
0385 add_subdirectory (plugins) # XA Drivers for RMs
0386 add_subdirectory (enctools) # XA Drivers for RMs
0387 add_subdirectory (atmitest) #  ATMI testing
0388 
0389 IF(DEFINE_DISABLEDOC)
0390         message("Documentation disabled - not building")
0391 ELSE (DEFINE_DISABLEDOC)
0392         add_subdirectory (doc) #  Documentation project.
0393 ENDIF (DEFINE_DISABLEDOC)
0394 
0395 add_subdirectory (include) #  For install
0396 add_subdirectory (scripts) #  For install
0397 add_subdirectory (sampleconfig) #  For install
0398 
0399 
0400 ################################################################################
0401 # uninstall target
0402 ################################################################################
0403 configure_file(
0404     "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
0405     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
0406     IMMEDIATE @ONLY)
0407 
0408 add_custom_target(uninstall
0409     COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
0410 ################################################################################
0411 # Packages
0412 ################################################################################
0413 
0414 find_program(LSB_RELEASE_EXECUTABLE lsb_release)
0415 if(LSB_RELEASE_EXECUTABLE)
0416         execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -si
0417                 OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT_OS
0418                 ERROR_QUIET
0419                 OUTPUT_STRIP_TRAILING_WHITESPACE)
0420 
0421         string(TOLOWER 
0422                 ${_TMP_LSB_RELEASE_OUTPUT_OS}
0423         LSB_RELEASE_OUTPUT_OS)
0424         string(REPLACE " " "_" LSB_RELEASE_OUTPUT_OS ${LSB_RELEASE_OUTPUT_OS})
0425 
0426         execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sr
0427                 OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT_VER
0428                 ERROR_QUIET
0429                 OUTPUT_STRIP_TRAILING_WHITESPACE)
0430         string(REPLACE "." "_" LSB_RELEASE_OUTPUT_VER ${_TMP_LSB_RELEASE_OUTPUT_VER})
0431         #string(REGEX MATCH "^[0-9]+" LSB_RELEASE_OUTPUT_VER ${_TMP_LSB_RELEASE_OUTPUT_VER})
0432 elseif (EXISTS /etc/os-release)
0433 
0434         execute_process(COMMAND bash -c "cat /etc/os-release | egrep '^NAME=' | cut -d '\"' -f2"
0435                 OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT_OS
0436                 OUTPUT_STRIP_TRAILING_WHITESPACE)
0437 
0438         string(TOLOWER 
0439                 ${_TMP_LSB_RELEASE_OUTPUT_OS}
0440         LSB_RELEASE_OUTPUT_OS)
0441         string(REPLACE " " "_" LSB_RELEASE_OUTPUT_OS ${LSB_RELEASE_OUTPUT_OS})
0442 
0443         # fixes for CentOs 7.1810, having something like "7 (Core)" in output.
0444         execute_process(COMMAND bash -c "cat /etc/os-release | egrep '^VERSION=' | cut -d ' ' -f1 | cut -d '\"' -f2"
0445                 OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT_VER
0446                 OUTPUT_STRIP_TRAILING_WHITESPACE)
0447         string(REPLACE "." "_" LSB_RELEASE_OUTPUT_VER ${_TMP_LSB_RELEASE_OUTPUT_VER})
0448         #string(REGEX MATCH "^[0-9]+" LSB_RELEASE_OUTPUT_VER ${_TMP_LSB_RELEASE_OUTPUT_VER})
0449 else ()
0450         set(LSB_RELEASE_OUTPUT_OS ${CMAKE_OS_NAME})
0451 
0452         string(REPLACE "." "_" _TMP_LSB_RELEASE_OUTPUT_VER ${CMAKE_SYSTEM_VERSION})
0453         string(REPLACE "-" "_" LSB_RELEASE_OUTPUT_VER ${_TMP_LSB_RELEASE_OUTPUT_VER})
0454         
0455         # If it is AIX, then we can extract version from uname
0456         if(${CMAKE_OS_NAME} STREQUAL "AIX")
0457                 execute_process(COMMAND uname -v
0458                         OUTPUT_VARIABLE _TMP_OS_MAJOR_VER OUTPUT_STRIP_TRAILING_WHITESPACE)
0459                 execute_process(COMMAND uname -r
0460                         OUTPUT_VARIABLE _TMP_OS_MINOR_VER OUTPUT_STRIP_TRAILING_WHITESPACE)
0461                 set(LSB_RELEASE_OUTPUT_VER ${_TMP_OS_MAJOR_VER}_${_TMP_OS_MINOR_VER})
0462         endif()
0463         
0464 endif()
0465 
0466 message("LSB_RELEASE OS  = ${LSB_RELEASE_OUTPUT_OS}")
0467 message("LSB_RELEASE VER = ${LSB_RELEASE_OUTPUT_VER}")
0468 set(EX_LSB_RELEASE_VER ${LSB_RELEASE_OUTPUT_VER})
0469 
0470 string(REPLACE "_" ";" LSB_VERSION_LIST ${LSB_RELEASE_OUTPUT_VER})
0471 
0472 list( LENGTH LSB_VERSION_LIST TMP_LIST_LEN ) 
0473 
0474 if (TMP_LIST_LEN LESS 1)
0475         # No version at all!!
0476         set(EX_LSB_RELEASE_VER_MAJOR "0")
0477         set(EX_LSB_RELEASE_VER_MINOR "0")
0478 elseif (TMP_LIST_LEN LESS 2)
0479         # Bug #198 - FedoraCore do not have minor version numbers
0480         list(GET LSB_VERSION_LIST 0 EX_LSB_RELEASE_VER_MAJOR)
0481         set(EX_LSB_RELEASE_VER_MINOR "0")
0482 
0483 else ()
0484         list(GET LSB_VERSION_LIST 0 EX_LSB_RELEASE_VER_MAJOR)
0485         list(GET LSB_VERSION_LIST 1 EX_LSB_RELEASE_VER_MINOR)
0486 endif()
0487 
0488 MESSAGE( "EX_LSB_RELEASE_VER_MAJOR = " ${EX_LSB_RELEASE_VER_MAJOR} )
0489 MESSAGE( "EX_LSB_RELEASE_VER_MINOR = " ${EX_LSB_RELEASE_VER_MINOR} )
0490 
0491 # Support only for Linux
0492 MESSAGE( "CPack:Debug: CMAKE_SYSTEM_NAME = " ${CMAKE_SYSTEM_NAME} )
0493 MESSAGE( "CPack:Debug: CMAKE_SYSTEM_PROCESSOR = " ${CMAKE_SYSTEM_PROCESSOR} )
0494 set(CPACK_MONOLITHIC_INSTALL 1)
0495 
0496 #
0497 # Generate configuration 
0498 #
0499 configure_file ("${PROJECT_SOURCE_DIR}/include/ndrx_config.h.in"
0500                 "${PROJECT_BINARY_DIR}/include/ndrx_config.h" )
0501 
0502 # Test the available generators and then configure output
0503 find_program(RPMPROG "rpmbuild")
0504 find_program(APTPROG "dpkg")
0505 
0506 # avoid file /usr/share/man from install of endurox-3.5.1-1.x86_64 conflicts with file from package filesystem-3.2-21.el7.x86_64
0507 # problems...
0508 set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/share/man
0509                 /usr/share/man/man3
0510                 /usr/share/man/man5
0511                 /usr/share/man/man8
0512                 /usr/lib64/pkgconfig
0513                 /usr/lib/pkgconfig)
0514 message("Excl: ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}")
0515 
0516 set(CPACK_GENERATOR "TGZ")
0517 if(RPMPROG)
0518         message("Outputting RPM")
0519         set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM")
0520 endif()
0521 
0522 if(APTPROG)
0523         message("Outputting DEB")
0524         set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB")
0525 endif()
0526 
0527 set(CPACK_PACKAGE_CONTACT "madars.vitolins@gmail.com")
0528 set(CPACK_PACKAGE_VERSION ${VERSION})
0529 #set(CPACK_DEBIAN_PACKAGE_DEPENDS "libxml2,openssl,libgpgme11")
0530 #set(CPACK_RPM_PACKAGE_REQUIRES "libxml2,openssl,libssl,libgpgme11")
0531 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LO)
0532 message("CPack:Debug: PROJECT NAME = ${PROJECT_NAME_LO}")
0533 set(CPACK_PACKAGE_FILE_NAME         ${PROJECT_NAME_LO}-${VERSION}-${RELEASE}.${LSB_RELEASE_OUTPUT_OS}${LSB_RELEASE_OUTPUT_VER}_${CMAKE_C_COMPILER_ID}_${EX_POLLER_STR}.${CMAKE_SYSTEM_PROCESSOR}_${EX_PLATFORM_BITS})
0534 message("CPack:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
0535 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Enduro/X Middleware Platform")
0536 set(CPACK_DEBIAN_PACKAGE_DESCRIPTION  ${CPACK_PACKAGE_DESCRIPTION})
0537 set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
0538 #set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/Debian/postinst")
0539 
0540 include(CPack)
0541 ################################################################################
0542 # Source indexing for quick symbol lookup
0543 # note that "glimpse" package must be installed.
0544 # to exclude any directory or name from indexing,
0545 # put the name in the glimpse_index/.glimpse_exclude
0546 ################################################################################
0547 
0548 add_custom_target(index glimpseindex -H ./glimpse_index ${PROJECT_SOURCE_DIR}
0549                     COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/glimpse_index/glim.cmake)
0550 #this also shall generate the glimp command in the current project
0551 
0552 # vim: set ts=4 sw=4 et smartindent: