platform.inc 6.6 KB
Newer Older
S
[TD-58]  
slguan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine)

#
# If it is a Windows operating system
#   1.Use command line tool of VS2013 or higher version
#     mkdir build; cd build;
#     cmake -G "NMake Makefiles" ..
#     nmake install
#   2.Use the VS development interface tool
#     mkdir build; cd build;
#     cmake -A x64 ..
#     open the file named TDengine.sln
#

# Set macro definitions according to os platform
SET(TD_LINUX_64 FALSE)
SET(TD_LINUX_32 FALSE)
SET(TD_ARM FALSE)
SET(TD_ARM_64 FALSE)
SET(TD_ARM_32 FALSE)
SET(TD_MIPS FALSE)
SET(TD_MIPS_64 FALSE)
SET(TD_MIPS_32 FALSE)
SET(TD_DARWIN_64 FALSE)
SET(TD_WINDOWS_64 FALSE)

# if generate ARM version:
#   cmake -DCPUTYPE=aarch32 .. or cmake -DCPUTYPE=aarch64
IF (${CPUTYPE} MATCHES "aarch32")
  SET(TD_ARM TRUE)
  SET(TD_ARM_32 TRUE)
  SET(TD_PAGMODE_LITE TRUE)
  ADD_DEFINITIONS(-D_TD_ARM_)
  ADD_DEFINITIONS(-D_TD_ARM_32_)
S
Shengliang Guan 已提交
36
  MESSAGE(STATUS "input cpuType: aarch32")
S
[TD-58]  
slguan 已提交
37 38 39 40 41
ELSEIF (${CPUTYPE} MATCHES "aarch64")
  SET(TD_ARM TRUE)
  SET(TD_ARM_64 TRUE)
  ADD_DEFINITIONS(-D_TD_ARM_)
  ADD_DEFINITIONS(-D_TD_ARM_64_)
S
Shengliang Guan 已提交
42
   MESSAGE(STATUS "input cpuType: aarch64")
S
[TD-58]  
slguan 已提交
43 44 45 46 47
ELSEIF (${CPUTYPE} MATCHES "mips64")
  SET(TD_MIPS TRUE)
  SET(TD_MIPS_64 TRUE)
  ADD_DEFINITIONS(-D_TD_MIPS_)
  ADD_DEFINITIONS(-D_TD_MIPS_64_)
S
Shengliang Guan 已提交
48
  MESSAGE(STATUS "input cpuType: mips64")
S
[TD-58]  
slguan 已提交
49
ELSEIF (${CPUTYPE} MATCHES "x64")
S
Shengliang Guan 已提交
50
  MESSAGE(STATUS "input cpuType: x64")
S
[TD-58]  
slguan 已提交
51
ELSEIF (${CPUTYPE} MATCHES "x86")
S
Shengliang Guan 已提交
52
  MESSAGE(STATUS "input cpuType: x86")
S
[TD-58]  
slguan 已提交
53 54 55 56 57 58 59 60 61 62 63
ELSE ()
  MESSAGE(STATUS "input cpuType: " ${CPUTYPE})
ENDIF ()

#
# Get OS information and store in variable TD_OS_INFO.
#
execute_process(COMMAND chmod 777 ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh)
execute_process(COMMAND ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
MESSAGE(STATUS "The current os is " ${TD_OS_INFO})

H
Haojun Liao 已提交
64 65
ADD_DEFINITIONS(-D_TD_LINUX_64)

S
[TD-58]  
slguan 已提交
66 67 68
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
    SET(TD_LINUX_64 TRUE)
H
hjxilinx 已提交
69
    ADD_DEFINITIONS(-D_M_X64)
S
Shengliang Guan 已提交
70
    ADD_DEFINITIONS(-D_TD_LINUX_64)
S
[TD-58]  
slguan 已提交
71 72
    MESSAGE(STATUS "The current platform is Linux 64-bit")
  ELSEIF (${CMAKE_SIZEOF_VOID_P} MATCHES 4)
S
Shengliang Guan 已提交
73 74
    SET(TD_LINUX_32 TRUE)
    ADD_DEFINITIONS(-D_TD_LINUX_32)
S
[TD-58]  
slguan 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88
    IF (TD_ARM)
      #ADD_DEFINITIONS(-D_M_IX86)
      MESSAGE(STATUS "The current platform is Linux 32-bit")
    ELSE ()
      MESSAGE(FATAL_ERROR "The current platform is Linux 32-bit, but no ARM not supported yet")
      EXIT ()
    ENDIF ()
  ELSE ()
    MESSAGE(FATAL_ERROR "The current platform is Linux neither 32-bit nor 64-bit, not supported yet")
    EXIT ()
  ENDIF ()
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
    SET(TD_DARWIN_64 TRUE)
S
Shengliang Guan 已提交
89
    ADD_DEFINITIONS(-D_TD_DARWIN_64)
S
[TD-58]  
slguan 已提交
90 91 92 93 94 95 96 97 98
    MESSAGE(STATUS "The current platform is Darwin 64-bit")
  ELSE ()
    MESSAGE(FATAL_ERROR "The current platform is Darwin 32-bit, not supported yet")
    EXIT ()
  ENDIF ()
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
    SET(TD_WINDOWS_64 TRUE)
    ADD_DEFINITIONS(-D_M_X64)
S
Shengliang Guan 已提交
99
    ADD_DEFINITIONS(-D_TD_WINDOWS_64)
S
[TD-58]  
slguan 已提交
100 101
    MESSAGE(STATUS "The current platform is Windows 64-bit")
  ELSE ()
S
Shengliang Guan 已提交
102 103
    SET(TD_WINDOWS_32 TRUE)
    ADD_DEFINITIONS(-D_TD_WINDOWS_32)
S
[TD-58]  
slguan 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116
    MESSAGE(FATAL_ERROR "The current platform is Windows 32-bit, not supported yet")
    EXIT ()
  ENDIF ()
ELSE()
  MESSAGE(FATAL_ERROR "The current platform is not Linux/Darwin/Windows, stop compile")
  EXIT ()
ENDIF ()

IF (TD_LINUX_64)
    SET(DEBUG_FLAGS "-O0 -DDEBUG")
    SET(RELEASE_FLAGS "-O0")
    IF (NOT TD_ARM)
      IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
117
        SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
S
[TD-58]  
slguan 已提交
118
      ELSE ()
119
        SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -malign-double -g3 -gdwarf-2 -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
S
[TD-58]  
slguan 已提交
120 121
      ENDIF ()
    ELSE ()
122
      SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
S
[TD-58]  
slguan 已提交
123 124 125 126 127 128 129 130 131
    ENDIF ()
    ADD_DEFINITIONS(-DLINUX)
    ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
    IF (${TD_OS_INFO} MATCHES "Alpine")
      MESSAGE(STATUS "The current OS is Alpine, append extra flags")
      SET(COMMON_FLAGS "${COMMON_FLAGS} -largp")
      link_libraries(/usr/lib/libargp.a)
      ADD_DEFINITIONS(-D_ALPINE)
    ENDIF ()
132 133 134 135 136 137
    IF (${COVER} MATCHES "true")
      MESSAGE(STATUS "Test coverage mode, add extra flags")
      SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
      SET(GCC_COVERAGE_LINK_FLAGS    "-lgcov --coverage")
      SET(COMMON_FLAGS "${COMMON_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
    ENDIF ()
S
[TD-58]  
slguan 已提交
138 139 140 141 142 143
  ELSEIF (TD_LINUX_32)
    IF (NOT TD_ARM)
      EXIT ()
    ENDIF ()
    SET(DEBUG_FLAGS "-O0 -DDEBUG")
    SET(RELEASE_FLAGS "-O0")
144
    SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -munaligned-access -fpack-struct=8 -latomic -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
S
[TD-58]  
slguan 已提交
145 146 147 148 149 150 151 152 153
    ADD_DEFINITIONS(-DLINUX)
    ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
    ADD_DEFINITIONS(-DUSE_LIBICONV)
    IF (${TD_OS_INFO} MATCHES "Alpine")
      MESSAGE(STATUS "The current OS is Alpine, add extra flags")
      SET(COMMON_FLAGS "${COMMON_FLAGS} -largp")
      link_library(/usr/lib/libargp.a)
      ADD_DEFINITIONS(-D_ALPINE)
    ENDIF ()
154 155 156 157 158 159
    IF (${COVER} MATCHES "true")
      MESSAGE(STATUS "Test coverage mode, add extra flags")
      SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
      SET(GCC_COVERAGE_LINK_FLAGS    "-lgcov --coverage")
      SET(COMMON_FLAGS "${COMMON_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
    ENDIF ()
S
[TD-58]  
slguan 已提交
160 161 162
  ELSEIF (TD_WINDOWS_64)
    SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
    IF (NOT TD_GODLL)
163
      SET(COMMON_FLAGS "/nologo /WX /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
S
[TD-58]  
slguan 已提交
164 165 166 167 168 169 170 171 172
      SET(DEBUG_FLAGS "/Zi /W3 /GL")
      SET(RELEASE_FLAGS "/W0 /GL")
    ENDIF ()
    ADD_DEFINITIONS(-DWINDOWS)
    ADD_DEFINITIONS(-D__CLEANUP_C)
    ADD_DEFINITIONS(-DPTW32_STATIC_LIB)
    ADD_DEFINITIONS(-DPTW32_BUILD)
    ADD_DEFINITIONS(-D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  ELSEIF (TD_DARWIN_64)
173
    SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -g -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
S
[TD-58]  
slguan 已提交
174 175 176 177 178 179 180
    SET(DEBUG_FLAGS "-O0 -DDEBUG")
    SET(RELEASE_FLAGS "-O0")
    ADD_DEFINITIONS(-DDARWIN)
    ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
  ELSE ()
    MESSAGE(FATAL_ERROR "The current platform is not support yet, stop compile")
    EXIT ()
181
  ENDIF ()