Back to home page

Enduro/X

 
 

    


0001 ##
0002 ## @brief Enduro/X Build Compiler configuration
0003 ##
0004 ## @file ex_comp.cmake
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-2023, Mavimax, Ltd. All Rights Reserved.
0010 ## This software is released under one of the following licenses:
0011 ## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012 ## See LICENSE file for full text.
0013 ## -----------------------------------------------------------------------------
0014 ## AGPL license:
0015 ##
0016 ## This program is free software; you can redistribute it and/or modify it under
0017 ## the terms of the GNU Affero General Public License, version 3 as published
0018 ## by the Free Software Foundation;
0019 ##
0020 ## This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022 ## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023 ## for more details.
0024 ##
0025 ## You should have received a copy of the GNU Affero General Public License along 
0026 ## with this program; if not, write to the Free Software Foundation, Inc.,
0027 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028 ##
0029 ## -----------------------------------------------------------------------------
0030 ## A commercial use license is available from Mavimax, Ltd
0031 ## contact@mavimax.com
0032 ## -----------------------------------------------------------------------------
0033 ##
0034 
0035 cmake_minimum_required (VERSION 3.5) 
0036 
0037 #
0038 # Configure C/C++ Compiler for the platform
0039 # 
0040 macro(ex_comp_settings)
0041 
0042     # Force C++ for C
0043     #SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
0044 
0045     set (CMAKE_C_STANDARD 11)
0046     set (CMAKE_C_STANDARD_REQUIRED 99)
0047 
0048     message("CMake CMAKE_OS_NAME  = ${CMAKE_OS_NAME}")
0049     message("CMake CMAKE_C_COMPILER_ID  = ${CMAKE_C_COMPILER_ID}")
0050     message("CMake CMAKE_CXX_COMPILER_ID  = ${CMAKE_CXX_COMPILER_ID}")
0051 
0052     OPTION(DEFINE_FORCEPOLL "Force POLL (even on linux)" OFF)
0053     OPTION(DEFINE_FORCEFDPOLL "Force FDPOLL" OFF)
0054     OPTION(DEFINE_FORCEKQUEUE "Force Kqueue (BSD poll framework)" OFF)
0055 
0056     OPTION(DEFINE_RELEASEBUILD "Do relesae build" OFF)
0057     OPTION(DEFINE_FORCEEMQ "Force Emulated Message Queue" OFF)
0058     OPTION(DEFINE_SYSVQ "Force System V Message Queue" OFF)
0059     OPTION(DEFINE_SVAPOLL "Force System V Queues with AIX Poll" OFF)
0060     OPTION(DEFINE_ALIGNMENT_FORCE "Force alignment" OFF)
0061     OPTION(DEFINE_SANITIZE "Enable GCC/Clang Address Sanitizer (for debug)" OFF)
0062 
0063 
0064     SET (EX_ALIGNMENT_BYTES "4")
0065 
0066     # Support #310 Ubuntu 18.04 prints lot of unneeded warnings...
0067     if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
0068         SET(CMAKE_C_FLAGS "-Wno-stringop-overflow -Wno-format-truncation -Wformat-overflow=0 ${CMAKE_C_FLAGS}")
0069     endif()
0070 
0071     SET (STACK_PROTECTOR "-fstack-protector")
0072 
0073     if(${CMAKE_OS_NAME} STREQUAL "AIX" OR ${CMAKE_OS_NAME} STREQUAL "SUNOS")
0074         # not for aix, on gcc 9 does not build
0075         SET (STACK_PROTECTOR "")
0076     endif()
0077 
0078     # set O flag common for all compilers:
0079     SET ( CMAKE_C_FLAGS "-O2 ${CMAKE_C_FLAGS}" CACHE STRING "compile flags" FORCE)
0080     SET ( CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}" CACHE STRING "compile flags" FORCE)
0081 
0082     # GNU like compiler configuration
0083     if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" )
0084 
0085         if (DEFINE_RELEASEBUILD)
0086             SET(CMAKE_CXX_FLAGS "${STACK_PROTECTOR} -O2 ${CMAKE_CXX_FLAGS}")
0087         else()
0088             IF (DEFINE_SANITIZE)
0089                 SET(CMAKE_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-inline-functions -O1 -ggdb ${CMAKE_CXX_FLAGS}")
0090             else()
0091                 SET(CMAKE_CXX_FLAGS "${STACK_PROTECTOR} -ggdb ${CMAKE_CXX_FLAGS}")
0092             endif()
0093         endif()
0094 
0095     endif()
0096 
0097     # GNU like compiler configuration
0098     if ( ${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang")
0099 
0100         if (DEFINE_RELEASEBUILD)
0101             SET(CMAKE_C_FLAGS "${STACK_PROTECTOR} ${CMAKE_C_FLAGS}")
0102         else()
0103             IF (DEFINE_SANITIZE)
0104                 SET(CMAKE_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-inline-functions -O1 -ggdb ${CMAKE_C_FLAGS}")
0105             else()
0106                 SET(CMAKE_C_FLAGS "${STACK_PROTECTOR} -ggdb ${CMAKE_C_FLAGS}")
0107             endif()
0108         endif()
0109 
0110     endif()
0111 
0112     IF (MUTEX_DEBUG)
0113         SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
0114         SET(CMAKE_CXX_FLAGS "-D_GNU_SOURCE ${CMAKE_CXX_FLAGS}")
0115     ENDIF()
0116 
0117     # -pthread needed for System V pthread_atfork()
0118     SET(RT_LIB rt dl)
0119     if( CMAKE_OS_NAME STREQUAL "LINUX" )
0120 
0121         set(EX_OS_LINUX "1")
0122         set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0123 
0124         # gnu pg fixes for rpi
0125         if(EXISTS "/opt/vc/include/bcm_host.h")
0126             SET(CMAKE_C_FLAGS "-D_FILE_OFFSET_BITS=64 ${CMAKE_C_FLAGS}")
0127         endif()
0128 
0129         # Configure backend transport
0130         IF(DEFINE_SYSVQ)
0131             message("Linux - forced poll()")
0132             set(EX_USE_SYSVQ "1")
0133         ELSEIF(DEFINE_SVAPOLL)
0134             message("Linux - forced dev mode System V poll()")
0135             set(EX_USE_SVAPOLL "1")
0136         ELSEIF(DEFINE_FORCEPOLL)
0137             message("Linux - forced poll()")
0138             set(EX_USE_POLL "1")
0139         ELSEIF(DEFINE_FORCEFDPOLL)
0140             message("Linux - forced fdpoll()")
0141             set(EX_USE_FDPOLL "1")
0142         ELSEIF(DEFINE_FORCEEMQ)
0143             message("Linux - forced emulated message q")
0144             set(EX_USE_EMQ "1")
0145             set(EX_USE_POLL "1")
0146         ELSE()
0147             message("Linux - forced epoll()")
0148             set(EX_USE_EPOLL "1")
0149         ENDIF()
0150     elseif(CMAKE_OS_NAME STREQUAL "AIX")
0151             # Configure the compiler, we support XLC too..
0152             message("No threads mode for CPM - bit slower child process exit status check...")
0153             # Seems aix 7.1 does not like threads mixed with fork...
0154             set(EX_CPM_NO_THREADS "1")
0155             set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0156 
0157         if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
0158                 message("GNU compiler")
0159                 set ( CMAKE_C_FLAGS "-D_SEM_SEMUN_UNDEFINED -D_MSGQSUPPORT -D_THREAD_SAFE -pthread -maix64 -Wl,-brtl,-bexpall,-berok ${CMAKE_C_FLAGS}")
0160                 set ( CMAKE_CXX_FLAGS "-D_SEM_SEMUN_UNDEFINED -D_MSGQSUPPORT -D_THREAD_SAFE -pthread -maix64 -Wl,-brtl,-bexpall,-berok ${CMAKE_CXX_FLAGS}")
0161         elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
0162                 message("Clang Open XL compiler")
0163                 # seems having issues with tls libndrxxaqdisk.so, access to G_nstd_tls from the lib causes segmentation fault
0164                 set ( CMAKE_C_FLAGS "-D_SEM_SEMUN_UNDEFINED -D_MSGQSUPPORT -ftls-model=global-dynamic -D_THREAD_SAFE -pthread -brtl -bexpall -berok -Wno-unused-command-line-argument ${CMAKE_C_FLAGS}")
0165                 set ( CMAKE_CXX_FLAGS "-D_SEM_SEMUN_UNDEFINED -D_MSGQSUPPORT -ftls-model=global-dynamic -D_THREAD_SAFE -pthread -brtl -bexpall -berok -Wno-unused-command-line-argument ${CMAKE_CXX_FLAGS}")
0166                 set ( CMAKE_SHARED_LINKER_FLAGS "-shared -Wl,-G")
0167         elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "XL")
0168                 message("XL compiler")
0169                 SET ( CMAKE_CXX_FLAGS "-D_MSGQSUPPORT -qtls -q64 -b64 -qsuppress=1500-030 ${CMAKE_CXX_FLAGS}" CACHE STRING "compile flags" FORCE)
0170                 set ( CMAKE_C_FLAGS " -D_MSGQSUPPORT -qsuppress=1500-030 -D_SEM_SEMUN_UNDEFINED -D_THREAD_SAFE ${CMAKE_C_FLAGS}")
0171                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qwarn64 -qpic -bexpfull -b64")
0172                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -brtl -qtls -q64")
0173                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-997 -qprocimported=setjmp")
0174                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-747")
0175                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-742")
0176                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-743")
0177                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-744")
0178                 set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -qsuppress=1506-745")
0179                 set ( CMAKE_SHARED_LINKER_FLAGS "-G")
0180 
0181                 if (NOT DEFINE_RELEASEBUILD)
0182                         message("XL compiler: with -g (debug symbols...)")
0183                         set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
0184                 endif()
0185         endif()
0186 
0187         IF(DEFINE_SVAPOLL)
0188             message("AIX - Force svapoll")
0189             set(EX_USE_SVAPOLL "1")
0190         ELSE()
0191             set(EX_USE_SYSVQ "1")
0192         ENDIF()
0193         set(EX_OS_AIX "1")
0194     elseif(CMAKE_OS_NAME STREQUAL "HP-UX")
0195         set(EX_USE_POLL "1")
0196         set(EX_OS_HPUX "1")
0197         set(NDRX_LD_LIBRARY_PATH "SHLIB_PATH")
0198     elseif(CMAKE_OS_NAME STREQUAL "SUNOS")
0199         set(EX_CPM_NO_THREADS "1")
0200         set(EX_OS_SUNOS "1")
0201         set(EX_USE_SYSVQ "1")
0202         set(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -m64")
0203         set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -m64")
0204 
0205         set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0206         # Bug #219 !!! _REENTRANT makes errno thread safe
0207         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT")
0208 
0209         if (CMAKE_C_COMPILER_ID STREQUAL "SunPro")
0210             # set new config for SunPro
0211         SET(CMAKE_C_FLAGS "-D_REENTRANT -m64")
0212             message("SUN Studio compiler (building for 64bit) ")
0213 
0214             # Bug #219 !!! _REENTRANT makes errno thread safe
0215             # For GNU I guess
0216             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -errtags -fast -erroff=E_PTR_TO_VOID_IN_ARITHMETIC ")
0217             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_EMPTY_MBR_DECLARATION -erroff=E_NO_IMPLICIT_DECL_ALLOWED")
0218             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_EMPTY_DECLARATION -erroff=E_ARGUEMENT_MISMATCH -erroff=E_ZERO_OR_NEGATIVE_SUBSCRIPT")
0219             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_ARG_INCOMPATIBLE_WITH_ARG_L")
0220             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_BAD_PTR_INT_COMBINATION")
0221             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=SEC_UNINITIALIZED_MEM_READ")
0222             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=E_INIT_DOES_NOT_FIT")
0223             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -erroff=SEC_ARR_OUTSIDE_BOUND_READ")
0224 
0225             # Add Sun Studio C runtime
0226             SET(RT_LIB ${RT_LIB} Crun)
0227         endif()
0228 
0229     elseif(CMAKE_OS_NAME STREQUAL "FREEBSD")
0230         set(RT_LIB rt)
0231         # seem that threading model also does not work here...
0232         set(EX_CPM_NO_THREADS "1")
0233         set(EX_OS_FREEBSD "1")
0234         # Best option...
0235         set(EX_USE_KQUEUE "1")
0236         set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0237     elseif(CMAKE_OS_NAME STREQUAL "CYGWIN")
0238         set(EX_OS_CYGWIN "1")
0239         set(EX_USE_POLL "1")
0240         set(NDRX_LD_LIBRARY_PATH "LD_LIBRARY_PATH")
0241     elseif(CMAKE_OS_NAME STREQUAL "DARWIN")
0242         set(RT_LIB dl)
0243         set(EX_OS_DARWIN "1")
0244         set(EX_USE_EMQ "1")
0245         set(EX_USE_POLL "1")
0246         set(NDRX_LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH")
0247     # Unknown OS:
0248     else()
0249         message( FATAL_ERROR "Unsupported OS" )
0250     endif()
0251 
0252     IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
0253         set(EX_ALIGNMENT_BYTES "8")
0254         set(EX_ALIGNMENT_FORCE "1")
0255     ENDIF ()
0256 
0257     IF (DEFINE_ALIGNMENT_FORCE)
0258         set(EX_ALIGNMENT_FORCE "1")
0259     ENDIF()
0260 
0261 
0262 endmacro(ex_comp_settings)
0263 
0264 # find flex & bison
0265 macro(ex_comp_find_flexbison)
0266     # Osx has very outdated bison,
0267     # thus install by brew install bison
0268     if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
0269 
0270         if(EXISTS "/opt/homebrew/opt/bison/bin/bison")
0271             set(BISON_EXECUTABLE "/opt/homebrew/opt/bison/bin/bison" CACHE PATH "Bison executable")
0272         else()
0273             set(BISON_EXECUTABLE "/usr/local/opt/bison/bin/bison" CACHE PATH "Bison executable")
0274         endif()
0275 
0276     endif()
0277 
0278     find_package(BISON)
0279     find_package(FLEX)
0280 
0281 endmacro(ex_comp_find_flexbison)
0282 
0283 # vim: set ts=4 sw=4 et smartindent: