cmake.platform 5.1 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 40
        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 ()

    ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
41

42 43
        SET(TD_DARWIN TRUE)
        SET(OSTYPE "macOS")
44
        ADD_DEFINITIONS("-DDARWIN -Wno-tautological-pointer-compare")
45

wafwerar's avatar
wafwerar 已提交
46 47
        IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
            MESSAGE("Current system arch is arm64")
48
            SET(TD_DARWIN_64 TRUE)
wafwerar's avatar
wafwerar 已提交
49
            SET(TD_DARWIN_ARM64 TRUE)
50
            ADD_DEFINITIONS("-D_TD_DARWIN_64")
wafwerar's avatar
wafwerar 已提交
51 52 53 54 55 56 57 58
            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")
59 60 61 62
        ENDIF ()

        ADD_DEFINITIONS("-DHAVE_UNISTD_H")
    ENDIF ()
63 64 65 66 67 68 69 70 71 72 73 74 75 76

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 ()
77

78 79
ENDIF()

80 81
IF ("${CPUTYPE}" STREQUAL "")
  IF (CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64)|(AMD64)")
H
Haojun Liao 已提交
82
    MESSAGE(STATUS "Current platform is amd64")
83
    SET(PLATFORM_ARCH_STR "amd64")
84
    SET(TD_INTEL_64 TRUE)
sangshuduo's avatar
sangshuduo 已提交
85
    ADD_DEFINITIONS("-D_TD_X86_")
86
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)")
H
Haojun Liao 已提交
87
    MESSAGE(STATUS "Current platform is x86")
88
    SET(PLATFORM_ARCH_STR "i386")
89
    SET(TD_INTEL_32 TRUE)
sangshuduo's avatar
sangshuduo 已提交
90
    ADD_DEFINITIONS("-D_TD_X86_")
91
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l")
H
Haojun Liao 已提交
92
    MESSAGE(STATUS "Current platform is aarch32")
93
    SET(PLATFORM_ARCH_STR "arm")
94
    SET(TD_ARM_32 TRUE)
wafwerar's avatar
wafwerar 已提交
95 96
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_32")
97
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64)|(arm64)")
H
Haojun Liao 已提交
98
    MESSAGE(STATUS "Current platform is aarch64")
99
    SET(PLATFORM_ARCH_STR "arm64")
100
    SET(TD_ARM_64 TRUE)
wafwerar's avatar
wafwerar 已提交
101 102
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_64")
103 104 105 106 107 108
  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")
109 110 111 112
  ENDIF ()
ELSE ()
  # if generate ARM version:
  #   cmake -DCPUTYPE=aarch32 .. or cmake -DCPUTYPE=aarch64
wafwerar's avatar
wafwerar 已提交
113
  IF (${CPUTYPE} MATCHES "aarch32" OR ${CPUTYPE} MATCHES "arm32")
114 115
    SET(PLATFORM_ARCH_STR "arm")
    MESSAGE(STATUS "input cpuType: aarch32")
wafwerar's avatar
wafwerar 已提交
116 117
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_32")
118
    SET(TD_ARM_32 TRUE)
wafwerar's avatar
wafwerar 已提交
119
  ELSEIF (${CPUTYPE} MATCHES "aarch64" OR ${CPUTYPE} MATCHES "arm64")
120 121
    SET(PLATFORM_ARCH_STR "arm64")
    MESSAGE(STATUS "input cpuType: aarch64")
wafwerar's avatar
wafwerar 已提交
122 123
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_64")
124
    SET(TD_ARM_64 TRUE)
125 126 127 128 129 130
  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")
131 132 133
  ELSEIF (${CPUTYPE} MATCHES "mips64")
    SET(PLATFORM_ARCH_STR "mips")
    MESSAGE(STATUS "input cpuType: mips64")
134
    SET(TD_MIPS_64 TRUE)
wafwerar's avatar
wafwerar 已提交
135 136
    ADD_DEFINITIONS("-D_TD_MIPS_")
    ADD_DEFINITIONS("-D_TD_MIPS_64")
137 138 139
  ELSEIF (${CPUTYPE} MATCHES "x64")
    SET(PLATFORM_ARCH_STR "amd64")
    MESSAGE(STATUS "input cpuType: x64")
140
    SET(TD_INTEL_64 TRUE)
141 142 143
  ELSEIF (${CPUTYPE} MATCHES "x86")
    SET(PLATFORM_ARCH_STR "i386")
    MESSAGE(STATUS "input cpuType: x86")
144
    SET(TD_INTEL_32 TRUE)
145 146 147 148 149
  ELSE ()
    MESSAGE(STATUS "input cpuType unknown " ${CPUTYPE})
  ENDIF ()
ENDIF ()

150
MESSAGE(STATUS "Platform arch:" ${PLATFORM_ARCH_STR})
151

H
Haojun Liao 已提交
152 153
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})")