cmake.platform 6.0 KB
Newer Older
1
cmake_minimum_required(VERSION 3.0)
2 3 4 5 6 7

# init
SET(TD_LINUX FALSE)
SET(TD_WINDOWS FALSE)
SET(TD_DARWIN FALSE)

8 9 10 11 12
if(CMAKE_COMPILER_IS_GNUCXX MATCHES 1)
    set(CXX_COMPILER_IS_GNU TRUE)
else()
    set(CXX_COMPILER_IS_GNU FALSE)
endif()
13

H
Haojun Liao 已提交
14
MESSAGE("Current system: ${CMAKE_SYSTEM_NAME}")
15

16 17 18 19
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

    IF (${CXX_COMPILER_IS_GNU})
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
20
    ELSE ()
21 22 23
        ADD_DEFINITIONS("-Wno-tautological-constant-out-of-range-compare -Wno-pointer-sign -Wno-unknown-warning-option")
        set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup")
        set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
24 25
    ENDIF ()

H
Haojun Liao 已提交
26 27
    MESSAGE("Current system processor: ${CMAKE_SYSTEM_PROCESSOR}")

28
    IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
29

30 31 32 33 34 35 36 37 38 39
        SET(TD_LINUX TRUE)
        SET(OSTYPE "Linux")
        ADD_DEFINITIONS("-DLINUX")

        IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
            SET(TD_LINUX_64 TRUE)
        ELSE ()
            SET(TD_LINUX_32 TRUE)
        ENDIF ()

sangshuduo's avatar
sangshuduo 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
        EXECUTE_PROCESS(COMMAND chmod 777  ${CMAKE_CURRENT_LIST_DIR}/../packaging/tools/get_os.sh)
	EXECUTE_PROCESS(COMMAND readlink /bin/sh OUTPUT_VARIABLE SHELL_LINK)
	MESSAGE(STATUS "The shell is: " ${SHELL_LINK})
	
        IF (${SHELL_LINK} MATCHES "dash")
	    EXECUTE_PROCESS(COMMAND  ${CMAKE_CURRENT_LIST_DIR}/../packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
	ELSE ()
	    EXECUTE_PROCESS(COMMAND sh  ${CMAKE_CURRENT_LIST_DIR}/../packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO)
	ENDIF ()    
	MESSAGE(STATUS "The current OS is " ${TD_OS_INFO})
	IF (${TD_OS_INFO} MATCHES "Alpine")
	    SET(TD_ALPINE TRUE)
            ADD_DEFINITIONS("-D_ALPINE")
	ENDIF ()

55
    ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
56

57 58
        SET(TD_DARWIN TRUE)
        SET(OSTYPE "macOS")
59
        ADD_DEFINITIONS("-DDARWIN -Wno-tautological-pointer-compare")
60

wafwerar's avatar
wafwerar 已提交
61 62
        IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
            MESSAGE("Current system arch is arm64")
63
            SET(TD_DARWIN_64 TRUE)
wafwerar's avatar
wafwerar 已提交
64
            SET(TD_DARWIN_ARM64 TRUE)
65
            ADD_DEFINITIONS("-D_TD_DARWIN_64")
wafwerar's avatar
wafwerar 已提交
66 67 68 69 70 71 72 73
            ADD_DEFINITIONS("-D_TD_DARWIN_ARM64")
        ENDIF ()
        IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
            MESSAGE("Current system arch is x86_64")
            SET(TD_DARWIN_64 TRUE)
            SET(TD_DARWIN_X64 TRUE)
            ADD_DEFINITIONS("-D_TD_DARWIN_64")
            ADD_DEFINITIONS("-D_TD_DARWIN_X64")
74 75 76 77
        ENDIF ()

        ADD_DEFINITIONS("-DHAVE_UNISTD_H")
    ENDIF ()
78 79 80 81 82 83 84 85 86 87 88 89 90 91

ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")

    SET(TD_WINDOWS TRUE)
    SET(OSTYPE "Windows")
    ADD_DEFINITIONS("-DWINDOWS")

    IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
        SET(TD_WINDOWS_64 TRUE)
    	ADD_DEFINITIONS("-D_TD_WINDOWS_64")
    ELSE ()
        SET(TD_WINDOWS_32 TRUE)
    	ADD_DEFINITIONS("-D_TD_WINDOWS_32")
    ENDIF ()
92

93 94
ENDIF()

95 96
IF ("${CPUTYPE}" STREQUAL "")
  IF (CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64)|(AMD64)")
H
Haojun Liao 已提交
97
    MESSAGE(STATUS "Current platform is amd64")
98
    SET(PLATFORM_ARCH_STR "amd64")
99
    SET(TD_INTEL_64 TRUE)
sangshuduo's avatar
sangshuduo 已提交
100
    ADD_DEFINITIONS("-D_TD_X86_")
101
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)")
H
Haojun Liao 已提交
102
    MESSAGE(STATUS "Current platform is x86")
103
    SET(PLATFORM_ARCH_STR "i386")
104
    SET(TD_INTEL_32 TRUE)
sangshuduo's avatar
sangshuduo 已提交
105
    ADD_DEFINITIONS("-D_TD_X86_")
106
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l")
H
Haojun Liao 已提交
107
    MESSAGE(STATUS "Current platform is aarch32")
108
    SET(PLATFORM_ARCH_STR "arm")
109
    SET(TD_ARM_32 TRUE)
wafwerar's avatar
wafwerar 已提交
110 111
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_32")
112
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64)|(arm64)")
H
Haojun Liao 已提交
113
    MESSAGE(STATUS "Current platform is aarch64")
114
    SET(PLATFORM_ARCH_STR "arm64")
115
    SET(TD_ARM_64 TRUE)
wafwerar's avatar
wafwerar 已提交
116 117
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_64")
118 119 120 121 122 123
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
    MESSAGE(STATUS "The current platform is loongarch64")
    SET(PLATFORM_ARCH_STR "loongarch64")
    SET(TD_LOONGARCH_64 TRUE)
    ADD_DEFINITIONS("-D_TD_LOONGARCH_")
    ADD_DEFINITIONS("-D_TD_LOONGARCH_64")
124 125 126 127
  ENDIF ()
ELSE ()
  # if generate ARM version:
  #   cmake -DCPUTYPE=aarch32 .. or cmake -DCPUTYPE=aarch64
wafwerar's avatar
wafwerar 已提交
128
  IF (${CPUTYPE} MATCHES "aarch32" OR ${CPUTYPE} MATCHES "arm32")
129 130
    SET(PLATFORM_ARCH_STR "arm")
    MESSAGE(STATUS "input cpuType: aarch32")
wafwerar's avatar
wafwerar 已提交
131 132
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_32")
133
    SET(TD_ARM_32 TRUE)
wafwerar's avatar
wafwerar 已提交
134
  ELSEIF (${CPUTYPE} MATCHES "aarch64" OR ${CPUTYPE} MATCHES "arm64")
135 136
    SET(PLATFORM_ARCH_STR "arm64")
    MESSAGE(STATUS "input cpuType: aarch64")
wafwerar's avatar
wafwerar 已提交
137 138
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_64")
139
    SET(TD_ARM_64 TRUE)
140 141 142 143 144 145
  ELSEIF (${CPUTYPE} MATCHES "loongarch64")
    SET(PLATFORM_ARCH_STR "loongarch64")
    MESSAGE(STATUS "input cpuType: loongarch64")
    SET(TD_LOONGARCH_64 TRUE)
    ADD_DEFINITIONS("-D_TD_LOONGARCH_")
    ADD_DEFINITIONS("-D_TD_LOONGARCH_64")
146 147 148
  ELSEIF (${CPUTYPE} MATCHES "mips64")
    SET(PLATFORM_ARCH_STR "mips")
    MESSAGE(STATUS "input cpuType: mips64")
149
    SET(TD_MIPS_64 TRUE)
wafwerar's avatar
wafwerar 已提交
150 151
    ADD_DEFINITIONS("-D_TD_MIPS_")
    ADD_DEFINITIONS("-D_TD_MIPS_64")
152 153 154
  ELSEIF (${CPUTYPE} MATCHES "x64")
    SET(PLATFORM_ARCH_STR "amd64")
    MESSAGE(STATUS "input cpuType: x64")
155
    SET(TD_INTEL_64 TRUE)
156 157 158
  ELSEIF (${CPUTYPE} MATCHES "x86")
    SET(PLATFORM_ARCH_STR "i386")
    MESSAGE(STATUS "input cpuType: x86")
159
    SET(TD_INTEL_32 TRUE)
160 161 162 163 164
  ELSE ()
    MESSAGE(STATUS "input cpuType unknown " ${CPUTYPE})
  ENDIF ()
ENDIF ()

dengyihao's avatar
dengyihao 已提交
165 166 167 168 169 170 171 172
IF(APPLE)
    set(CMAKE_THREAD_LIBS_INIT "-lpthread")
    set(CMAKE_HAVE_THREADS_LIBRARY 1)
    set(CMAKE_USE_WIN32_THREADS_INIT 0)
    set(CMAKE_USE_PTHREADS 1)
    set(THREADS_PREFER_PTHREAD_FLAG ON)
ENDIF()

173
MESSAGE(STATUS "Platform arch:" ${PLATFORM_ARCH_STR})
174

H
Haojun Liao 已提交
175 176
MESSAGE("C Compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID}, ${CMAKE_C_COMPILER_VERSION})")
MESSAGE("CXX Compiler: ${CMAKE_CXX_COMPILER} (${CMAKE_C_COMPILER_ID}, ${CMAKE_CXX_COMPILER_VERSION})")