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

MESSAGE("Current system is ${CMAKE_SYSTEM_NAME}")

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

10 11 12 13 14 15
MESSAGE("Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
if(CMAKE_COMPILER_IS_GNUCXX MATCHES 1)
    set(CXX_COMPILER_IS_GNU TRUE)
else()
    set(CXX_COMPILER_IS_GNU FALSE)
endif()
16

17
MESSAGE("Current system name is ${CMAKE_SYSTEM_NAME}.")
18

19 20 21 22
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")
23
    ELSE ()
24 25 26
        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")
27 28
    ENDIF ()

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

31 32 33 34 35 36 37 38 39 40 41
        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")
42

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

        MESSAGE("Current system processor is ${CMAKE_SYSTEM_PROCESSOR}.")
        IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
wafwerar's avatar
wafwerar 已提交
49
            MESSAGE("Current system arch is 64")
50 51 52 53 54 55
            SET(TD_DARWIN_64 TRUE)
            ADD_DEFINITIONS("-D_TD_DARWIN_64")
        ENDIF ()

        ADD_DEFINITIONS("-DHAVE_UNISTD_H")
    ENDIF ()
56 57 58 59 60 61 62 63 64 65 66 67 68 69

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

71 72
ENDIF()

73 74 75 76 77 78
IF ("${CPUTYPE}" STREQUAL "")
  MESSAGE(STATUS "The current platform " ${CMAKE_SYSTEM_PROCESSOR} " is detected")

  IF (CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64)|(AMD64)")
    MESSAGE(STATUS "The current platform is amd64")
    SET(PLATFORM_ARCH_STR "amd64")
79
    SET(TD_INTEL_64 TRUE)
80 81 82
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)")
    MESSAGE(STATUS "The current platform is x86")
    SET(PLATFORM_ARCH_STR "i386")
83
    SET(TD_INTEL_32 TRUE)
84 85 86
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l")
    MESSAGE(STATUS "The current platform is aarch32")
    SET(PLATFORM_ARCH_STR "arm")
87
    SET(TD_ARM_32 TRUE)
wafwerar's avatar
wafwerar 已提交
88 89
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_32")
90 91 92
  ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
    MESSAGE(STATUS "The current platform is aarch64")
    SET(PLATFORM_ARCH_STR "arm64")
93
    SET(TD_ARM_64 TRUE)
wafwerar's avatar
wafwerar 已提交
94 95
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_64")
96 97 98 99
  ENDIF ()
ELSE ()
  # if generate ARM version:
  #   cmake -DCPUTYPE=aarch32 .. or cmake -DCPUTYPE=aarch64
wafwerar's avatar
wafwerar 已提交
100
  IF (${CPUTYPE} MATCHES "aarch32" OR ${CPUTYPE} MATCHES "arm32")
101 102
    SET(PLATFORM_ARCH_STR "arm")
    MESSAGE(STATUS "input cpuType: aarch32")
wafwerar's avatar
wafwerar 已提交
103 104
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_32")
105
    SET(TD_ARM_32 TRUE)
wafwerar's avatar
wafwerar 已提交
106
  ELSEIF (${CPUTYPE} MATCHES "aarch64" OR ${CPUTYPE} MATCHES "arm64")
107 108
    SET(PLATFORM_ARCH_STR "arm64")
    MESSAGE(STATUS "input cpuType: aarch64")
wafwerar's avatar
wafwerar 已提交
109 110
    ADD_DEFINITIONS("-D_TD_ARM_")
    ADD_DEFINITIONS("-D_TD_ARM_64")
111
    SET(TD_ARM_64 TRUE)
112 113 114
  ELSEIF (${CPUTYPE} MATCHES "mips64")
    SET(PLATFORM_ARCH_STR "mips")
    MESSAGE(STATUS "input cpuType: mips64")
115
    SET(TD_MIPS_64 TRUE)
wafwerar's avatar
wafwerar 已提交
116 117
    ADD_DEFINITIONS("-D_TD_MIPS_")
    ADD_DEFINITIONS("-D_TD_MIPS_64")
118 119 120
  ELSEIF (${CPUTYPE} MATCHES "x64")
    SET(PLATFORM_ARCH_STR "amd64")
    MESSAGE(STATUS "input cpuType: x64")
121
    SET(TD_INTEL_64 TRUE)
122 123 124
  ELSEIF (${CPUTYPE} MATCHES "x86")
    SET(PLATFORM_ARCH_STR "i386")
    MESSAGE(STATUS "input cpuType: x86")
125
    SET(TD_INTEL_32 TRUE)
126 127 128 129 130 131 132
  ELSE ()
    MESSAGE(STATUS "input cpuType unknown " ${CPUTYPE})
  ENDIF ()
ENDIF ()

MESSAGE(STATUS "platform arch:" ${PLATFORM_ARCH_STR})

133 134
MESSAGE("C Compiler ID: ${CMAKE_C_COMPILER_ID}")
MESSAGE("CXX Compiler ID: ${CMAKE_CXX_COMPILER_ID}")