CMakeLists.txt 9.2 KB
Newer Older
H
Hongze Cheng 已提交
1
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
H
hzcheng 已提交
2 3 4 5 6 7
PROJECT(TDengine)

SET(CMAKE_C_STANDARD 11)
SET(CMAKE_VERBOSE_MAKEFILE ON)

#
S
slguan 已提交
8
# If need to set debug options
S
slguan 已提交
9
#   1.Generate debug version:
S
slguan 已提交
10
#     mkdir debug; cd debug;
S
slguan 已提交
11 12
#     cmake -DCMAKE_BUILD_TYPE=Debug ..
#   2.Generate release version:
S
slguan 已提交
13 14 15 16 17
#     mkdir release; cd release;
#     cmake -DCMAKE_BUILD_TYPE=Release ..
#

#
S
slguan 已提交
18 19 20 21 22
# 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
S
slguan 已提交
23
#   2.Use the VS development interface tool
S
slguan 已提交
24 25 26
#     mkdir build; cd build;
#     cmake -A x64 ..
#     open the file named TDengine.sln
H
hzcheng 已提交
27 28
#

S
slguan 已提交
29 30 31 32 33 34 35 36 37 38 39 40
IF (NOT DEFINED TD_CLUSTER)
  MESSAGE(STATUS "Build the Lite Version")
  SET(TD_CLUSTER FALSE)
  SET(TD_LITE TRUE)

  SET(TD_COMMUNITY_DIR ${PROJECT_SOURCE_DIR})
  MESSAGE(STATUS "Community directory: " ${TD_COMMUNITY_DIR})


  # Set macro definitions according to os platform
  SET(TD_LINUX_64 FALSE)
  SET(TD_LINUX_32 FALSE)
L
lihui 已提交
41 42 43
  SET(TD_ARM FALSE)
  SET(TD_ARM_64 FALSE)
  SET(TD_ARM_32 FALSE)
S
slguan 已提交
44 45 46
  SET(TD_MIPS_64 FALSE)
  SET(TD_DARWIN_64 FALSE)
  SET(TD_WINDOWS_64 FALSE)
L
lihui 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

  # if generate ARM version:
  #   cmake -DARMVER=arm32 .. or cmake -DARMVER=arm64
  IF (${ARMVER} MATCHES "arm32")
    SET(TD_ARM TRUE)
    SET(TD_ARM_32 TRUE)
    ADD_DEFINITIONS(-D_TD_ARM_)
    ADD_DEFINITIONS(-D_TD_ARM_32_)
  ELSEIF (${ARMVER} MATCHES "arm64")
    SET(TD_ARM TRUE)
    SET(TD_ARM_64 TRUE)
    ADD_DEFINITIONS(-D_TD_ARM_)
    ADD_DEFINITIONS(-D_TD_ARM_64_)
  ENDIF ()

L
lihui 已提交
62 63
  IF (TD_ARM)
    ADD_DEFINITIONS(-D_TD_ARM_)
L
lihui 已提交
64 65
    IF (TD_ARM_32)
      ADD_DEFINITIONS(-D_TD_ARM_32_)
L
lihui 已提交
66 67 68 69
    ELSEIF (TD_ARM_64)
      ADD_DEFINITIONS(-D_TD_ARM_64_)
    ELSE ()
      EXIT ()
L
lihui 已提交
70
    ENDIF ()
L
lihui 已提交
71
  ENDIF ()
S
slguan 已提交
72 73 74 75 76 77 78

  IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
      SET(TD_LINUX_64 TRUE)
      SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux)
      ADD_DEFINITIONS(-D_M_X64)
      MESSAGE(STATUS "The current platform is Linux 64-bit")
L
lihui 已提交
79
  ELSEIF (${CMAKE_SIZEOF_VOID_P} MATCHES 4)
L
lihui 已提交
80
    IF (TD_ARM)
S
slguan 已提交
81
      SET(TD_LINUX_32 TRUE)
L
lihui 已提交
82 83 84 85 86 87 88 89 90
      SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux)
      #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")
S
slguan 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
      EXIT ()
    ENDIF ()
  ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
      SET(TD_DARWIN_64 TRUE)
      SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/darwin)
      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)
      SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/windows)
      ADD_DEFINITIONS(-D_M_X64)
      MESSAGE(STATUS "The current platform is Windows 64-bit")
    ELSE ()
      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 ()
S
slguan 已提交
116

S
slguan 已提交
117 118 119
  FIND_PROGRAM(TD_MVN_INSTALLED mvn)
  IF (TD_MVN_INSTALLED)
    MESSAGE(STATUS "MVN is installed and JDBC will be compiled")
HowkWolf's avatar
HowkWolf 已提交
120
  ELSE ()
S
slguan 已提交
121
    MESSAGE(STATUS "MVN is not installed and JDBC is not compiled")
HowkWolf's avatar
HowkWolf 已提交
122
  ENDIF ()
S
slguan 已提交
123 124 125 126 127

  #
  # debug flag  
  #
  # ADD_DEFINITIONS(-D_CHECK_HEADER_FILE_)
weixin_48148422's avatar
weixin_48148422 已提交
128 129 130
  IF (${MEM_CHECK} MATCHES "true")
    ADD_DEFINITIONS(-DTAOS_MEM_CHECK)
  ENDIF ()
S
slguan 已提交
131 132 133 134

  IF (TD_CLUSTER)
    ADD_DEFINITIONS(-DCLUSTER)
    ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=3)
S
slguan 已提交
135
  ELSE ()
S
slguan 已提交
136 137
    ADD_DEFINITIONS(-DLITE)
    ADD_DEFINITIONS(-DTSDB_REPLICA_MAX_NUM=1)
S
slguan 已提交
138
  ENDIF ()
S
slguan 已提交
139 140 141
  IF (TD_LINUX_64)
    SET(DEBUG_FLAGS "-O0 -DDEBUG")
    SET(RELEASE_FLAGS "-O0")
L
lihui 已提交
142
    IF (NOT TD_ARM)
L
lihui 已提交
143
      IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
S
slguan 已提交
144
        SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
L
lihui 已提交
145
      ELSE ()
S
slguan 已提交
146
        SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
L
lihui 已提交
147
      ENDIF ()
S
slguan 已提交
148
    ELSE ()
S
slguan 已提交
149
      SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
S
slguan 已提交
150 151 152
    ENDIF ()
    ADD_DEFINITIONS(-DLINUX)
    ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
L
lihui 已提交
153
  ELSEIF (TD_LINUX_32)
L
lihui 已提交
154
    IF (NOT TD_ARM)
L
lihui 已提交
155 156 157 158
      EXIT ()
    ENDIF ()
    SET(DEBUG_FLAGS "-O0 -DDEBUG")
    SET(RELEASE_FLAGS "-O0")
S
slguan 已提交
159
    SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -g -fsigned-char -munaligned-access -fpack-struct=8 -latomic -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
L
lihui 已提交
160 161 162
    ADD_DEFINITIONS(-DLINUX)
    ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
    ADD_DEFINITIONS(-DUSE_LIBICONV)
S
slguan 已提交
163 164 165 166 167 168 169 170 171 172 173
  ELSEIF (TD_WINDOWS_64)
    SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
    SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
    SET(DEBUG_FLAGS "/Zi /W3 /GL")
    SET(RELEASE_FLAGS "/W0 /GL")
    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)
S
slguan 已提交
174
    SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
S
slguan 已提交
175 176 177 178
    SET(DEBUG_FLAGS "-O0 -DDEBUG")
    SET(RELEASE_FLAGS "-O0")
    ADD_DEFINITIONS(-DDARWIN)
    ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
S
slguan 已提交
179
  ELSE ()
S
slguan 已提交
180
    MESSAGE(FATAL_ERROR "The current platform is not support yet, stop compile")
S
slguan 已提交
181 182 183
    EXIT ()
  ENDIF ()

S
slguan 已提交
184 185 186
  # Set compiler options
  SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_FLAGS} ${DEBUG_FLAGS}")
  SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FLAGS}")
S
slguan 已提交
187

S
slguan 已提交
188 189 190 191
  # Set c++ compiler options
  # SET(COMMON_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
  # SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} ${DEBUG_FLAGS}")
  # SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ${RELEASE_FLAGS}")
S
slguan 已提交
192

S
slguan 已提交
193 194 195 196
  IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
    MESSAGE(STATUS "Build Debug Version")
  ELSEIF (${CMAKE_BUILD_TYPE} MATCHES "Release")
    MESSAGE(STATUS "Build Release Version")
S
slguan 已提交
197
  ELSE ()
S
slguan 已提交
198 199 200 201 202 203 204
    IF (TD_WINDOWS_64)
      SET(CMAKE_BUILD_TYPE "Release")
      MESSAGE(STATUS "Build Release Version in Windows as default")
    ELSE ()
      SET(CMAKE_BUILD_TYPE "Debug")
      MESSAGE(STATUS "Build Debug Version as default")
    ENDIF()
S
slguan 已提交
205
  ENDIF ()
S
slguan 已提交
206

S
slguan 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
  #set output directory
  SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
  SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
  SET(TD_TESTS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/test)

  MESSAGE(STATUS "Operating system dependency directory: " ${TD_OS_DIR})
  MESSAGE(STATUS "Project source directory: " ${PROJECT_SOURCE_DIR})
  MESSAGE(STATUS "Project binary files output path: " ${PROJECT_BINARY_DIR})
  MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH})
  MESSAGE(STATUS "Project library files output path: " ${LIBRARY_OUTPUT_PATH})

  IF (TD_LINUX_64)
    SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
    INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
    INSTALL(CODE "execute_process(COMMAND chmod 777 ${TD_MAKE_INSTALL_SH})")
    INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} ${TD_COMMUNITY_DIR} ${PROJECT_BINARY_DIR})")
L
lihui 已提交
223
  ELSEIF (TD_LINUX_32)
L
lihui 已提交
224
    IF (NOT TD_ARM)
L
lihui 已提交
225 226 227 228 229 230
      EXIT ()
    ENDIF ()
    SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
    INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
    INSTALL(CODE "execute_process(COMMAND chmod 777 ${TD_MAKE_INSTALL_SH})")
    INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} ${TD_COMMUNITY_DIR} ${PROJECT_BINARY_DIR})")  
S
slguan 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
  ELSEIF (TD_WINDOWS_64)
    SET(CMAKE_INSTALL_PREFIX C:/TDengine)
    INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/go DESTINATION connector)
    INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/grafana DESTINATION connector)
    INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/python DESTINATION connector)
    INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/tests/examples DESTINATION .)
    INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/packaging/cfg DESTINATION .)
    INSTALL(FILES ${TD_COMMUNITY_DIR}/src/inc/taos.h DESTINATION include)
    INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.lib DESTINATION driver)
    INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.exp DESTINATION driver)
    INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.dll DESTINATION driver)
    INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/taos.exe DESTINATION .)
    #INSTALL(TARGETS taos RUNTIME DESTINATION driver)
    #INSTALL(TARGETS shell RUNTIME DESTINATION .)
    IF (TD_MVN_INSTALLED)
      INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-1.0.2-dist.jar DESTINATION connector/jdbc)
    ENDIF ()
  ENDIF ()
H
hzcheng 已提交
249 250
ENDIF ()

S
slguan 已提交
251 252
ADD_SUBDIRECTORY(deps)
ADD_SUBDIRECTORY(src)
H
hzcheng 已提交
253

S
slguan 已提交
254
INCLUDE(CPack)