cmake.define 3.9 KB
Newer Older
1 2
cmake_minimum_required(VERSION 3.16)

X
Xiaoyu Wang 已提交
3
set(CMAKE_VERBOSE_MAKEFILE OFF)
wafwerar's avatar
wafwerar 已提交
4

wafwerar's avatar
wafwerar 已提交
5 6
SET(BUILD_SHARED_LIBS "OFF")

wafwerar's avatar
wafwerar 已提交
7 8 9 10 11 12 13 14 15 16
#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 "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})

sangshuduo's avatar
sangshuduo 已提交
17
find_package(Git QUIET)
wafwerar's avatar
wafwerar 已提交
18
if(GIT_FOUND AND EXISTS "${TD_SOURCE_DIR}/.git")
sangshuduo's avatar
sangshuduo 已提交
19 20 21 22
# Update submodules as needed
    option(GIT_SUBMODULE "Check submodules during build" ON)
    if(GIT_SUBMODULE)
        message(STATUS "Submodule update")
wafwerar's avatar
wafwerar 已提交
23
        execute_process(COMMAND cd ${TD_SOURCE_DIR} && ${GIT_EXECUTABLE} submodule update --init --recursive
sangshuduo's avatar
sangshuduo 已提交
24 25 26 27 28 29 30 31
                        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                        RESULT_VARIABLE GIT_SUBMOD_RESULT)
        if(NOT GIT_SUBMOD_RESULT EQUAL "0")
            message(WARNING "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
        endif()
    endif()
endif()

wafwerar's avatar
wafwerar 已提交
32
if(NOT EXISTS "${TD_SOURCE_DIR}/tools/taos-tools/CMakeLists.txt")
sangshuduo's avatar
sangshuduo 已提交
33 34 35
    message(WARNING "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules manually if you need build them.")
endif()

wafwerar's avatar
wafwerar 已提交
36 37 38 39
if (NOT DEFINED TD_GRANT)
  SET(TD_GRANT FALSE)
endif()

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
IF ("${BUILD_TOOLS}" STREQUAL "")
  IF (TD_LINUX)
    IF (TD_ARM_32)
      SET(BUILD_TOOLS "false")
    ELSEIF (TD_ARM_64)
      SET(BUILD_TOOLS "false")
    ELSE ()
      SET(BUILD_TOOLS "false")
    ENDIF ()
  ELSEIF (TD_DARWIN)
    SET(BUILD_TOOLS "false")
  ELSE ()
    SET(BUILD_TOOLS "false")
  ENDIF ()
ENDIF ()

IF ("${BUILD_TOOLS}" MATCHES "false")
    MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}")
    SET(TD_TAOS_TOOLS FALSE)
ELSE ()
    MESSAGE("")
    MESSAGE("${Green} Will build taos_tools! ${ColourReset}")
    MESSAGE("")
    SET(TD_TAOS_TOOLS TRUE)
ENDIF ()

IF (TD_WINDOWS)
    MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}")
wmmhello's avatar
wmmhello 已提交
68
    SET(COMMON_FLAGS "/W3 /D_WIN32")
wafwerar's avatar
wafwerar 已提交
69
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
wafwerar's avatar
wafwerar 已提交
70 71 72 73 74 75
    # IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
    #  SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
    # ENDIF ()

    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
76 77

ELSE ()
78 79 80 81 82 83
    IF (${SANITIZER} MATCHES "true")
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}     -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
	MESSAGE(STATUS "Will compile with Address Sanitizer!")
    ELSE ()
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
84
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-literal-suffix -Werror=return-type -fpermissive -fPIC -gdwarf-2 -g3")
85 86 87 88 89 90
    ENDIF ()

    MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}")
    IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
        ADD_DEFINITIONS("-D_TD_ARM_")
    ELSE ()
91 92 93 94 95 96 97
        ADD_DEFINITIONS("-msse4.2")
        IF("${FMA_SUPPORT}" MATCHES "true")
            MESSAGE(STATUS "turn fma function support on")
            ADD_DEFINITIONS("-mfma")
        ELSE ()
            MESSAGE(STATUS "turn fma function support off")
        ENDIF()
98
    ENDIF ()
99 100

ENDIF ()