CMakeLists.txt 5.1 KB
Newer Older
1
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
S
slguan 已提交
2 3 4
PROJECT(TDengine)

ADD_SUBDIRECTORY(monitor)
5 6

IF (TD_BUILD_HTTP)
7 8 9
  MESSAGE("")
  MESSAGE("${Yellow} use original embedded httpd ${ColourReset}")
  MESSAGE("")
10
  ADD_SUBDIRECTORY(http)
11 12
ELSEIF(TD_BUILD_TAOSA_INTERNAL)
  MESSAGE("${Yellow} use taosa internal as httpd ${ColourReset}")
13 14
ELSE ()
  MESSAGE("")
15
  MESSAGE("${Green} use taosadapter as httpd, platform is ${PLATFORM_ARCH_STR} ${ColourReset}")
16 17 18 19 20 21 22 23 24 25 26 27 28

  EXECUTE_PROCESS(
      COMMAND  git rev-parse --abbrev-ref HEAD
      RESULT_VARIABLE result_taos_version
      OUTPUT_VARIABLE taos_version
      )

  STRING(FIND ${taos_version} release is_release_branch)

  IF ("${is_release_branch}" STREQUAL "0")
      STRING(SUBSTRING "${taos_version}" 12 -1 taos_version)
      STRING(STRIP "${taos_version}" taos_version)
  ELSE ()
29
      STRING(CONCAT taos_version "_branch_" "${taos_version}")
30 31
      STRING(STRIP "${taos_version}" taos_version)
  ENDIF ()
32
  EXECUTE_PROCESS(
33
      COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter
34 35 36 37
      )
  EXECUTE_PROCESS(
      COMMAND git rev-parse --short HEAD
      RESULT_VARIABLE commit_sha1
38
      OUTPUT_VARIABLE taosadapter_commit_sha1
39
      )
40
  IF ("${taosadapter_commit_sha1}" STREQUAL "")
41
      SET(taosadapter_commit_sha1 "unknown")
42
  ELSE ()
43 44
      STRING(SUBSTRING "${taosadapter_commit_sha1}" 0 7 taosadapter_commit_sha1)
      STRING(STRIP "${taosadapter_commit_sha1}" taosadapter_commit_sha1)
45
  ENDIF ()
46
  MESSAGE("${Green} taosAdapter will use ${taos_version} and commit ${taosadapter_commit_sha1} as version ${ColourReset}")
47 48 49
  EXECUTE_PROCESS(
      COMMAND cd ..
      )
50 51 52

  IF (TD_LINUX)
      include(ExternalProject)
53 54 55 56 57 58 59 60 61
      set(_upx_prefix "$ENV{HOME}/.taos/externals/upx")
      ExternalProject_Add(upx
          PREFIX              "${_upx_prefix}"
          URL                 https://github.com/upx/upx/releases/download/v3.96/upx-3.96-${PLATFORM_ARCH_STR}_linux.tar.xz
          CONFIGURE_COMMAND   ""
          BUILD_COMMAND       ""
          INSTALL_COMMAND     ""
          )

62 63 64 65
      ExternalProject_Add(taosadapter
          PREFIX        "taosadapter"
          SOURCE_DIR    ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter
          BUILD_ALWAYS         off
66
          DEPENDS             taos upx
67 68 69 70
          BUILD_IN_SOURCE     1
          CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config"
          PATCH_COMMAND
          COMMAND     git clean -f -d
71
          BUILD_COMMAND
72
          COMMAND cmake -E echo "building taosadapter ..."
73 74
          COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib  go build -a -ldflags "-s -w -X github.com/taosdata/taosadapter/version.Version=${taos_version} -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}"
          COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib  go build -a -o taosadapter-debug -ldflags "-X github.com/taosdata/taosadapter/version.Version=${taos_version} -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}"
75
          INSTALL_COMMAND
76
          COMMAND ${_upx_prefix}/src/upx/upx taosadapter
77 78 79 80
          COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin
          COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/
          COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/
          COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/
81
          COMMAND cmake -E copy taosadapter-debug ${CMAKE_BINARY_DIR}/build/bin
82
          )
83
      unset(_upx_prefix)
84 85 86 87 88 89 90 91 92 93 94
  ELSEIF (TD_DARWIN)
      include(ExternalProject)
      ExternalProject_Add(taosadapter
          PREFIX        "taosadapter"
          SOURCE_DIR    ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter
          BUILD_ALWAYS         off
          DEPENDS             taos
          BUILD_IN_SOURCE     1
          CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config"
          PATCH_COMMAND
          COMMAND     git clean -f -d
95
          BUILD_COMMAND
96 97
          COMMAND    CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib  go build -a -ldflags "-s -w -X github.com/taosdata/taosadapter/version.Version=${taos_version} -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}"
          COMMAND    CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib  go build -a -o taosadapter-debug -ldflags "-X github.com/taosdata/taosadapter/version.Version=${taos_version} -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}"
98 99 100 101 102
          INSTALL_COMMAND
          COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin
          COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/
          COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/
          COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/
103
          COMMAND cmake -E copy taosadapter-debug ${CMAKE_BINARY_DIR}/build/bin
104 105 106 107
          )
  ELSE ()
      MESSAGE("${Yellow} Windows system still use original embedded httpd ${ColourReset}")
  ENDIF ()
108
ENDIF ()