cmake.platform 6.5 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")
T
t_max 已提交
59 60 61 62 63 64 65 66
        execute_process(COMMAND geos-config --cflags OUTPUT_VARIABLE GEOS_CFLAGS)
        execute_process(COMMAND geos-config --ldflags OUTPUT_VARIABLE GEOS_LDFLAGS)
        string(SUBSTRING ${GEOS_CFLAGS} 2 -1 GEOS_CFLAGS)
        string(REGEX REPLACE "\n" "" GEOS_CFLAGS ${GEOS_CFLAGS})
        string(SUBSTRING ${GEOS_LDFLAGS} 2 -1 GEOS_LDFLAGS)
        string(REGEX REPLACE "\n" "" GEOS_LDFLAGS ${GEOS_LDFLAGS})
        MESSAGE("GEOS_CFLAGS "${GEOS_CFLAGS})
        MESSAGE("GEOS_LDFLAGS "${GEOS_LDFLAGS})
67
        ADD_DEFINITIONS("-DDARWIN -Wno-tautological-pointer-compare")
T
t_max 已提交
68 69
        INCLUDE_DIRECTORIES(${GEOS_CFLAGS})
        LINK_DIRECTORIES(${GEOS_LDFLAGS})
70

wafwerar's avatar
wafwerar 已提交
71 72
        IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
            MESSAGE("Current system arch is arm64")
73
            SET(TD_DARWIN_64 TRUE)
wafwerar's avatar
wafwerar 已提交
74
            SET(TD_DARWIN_ARM64 TRUE)
75
            ADD_DEFINITIONS("-D_TD_DARWIN_64")
wafwerar's avatar
wafwerar 已提交
76 77 78 79 80 81 82 83
            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")
84 85 86 87
        ENDIF ()

        ADD_DEFINITIONS("-DHAVE_UNISTD_H")
    ENDIF ()
88 89 90 91 92 93 94 95 96 97 98 99 100 101

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

103 104
ENDIF()

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

dengyihao's avatar
dengyihao 已提交
175 176 177 178 179 180 181 182
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()

183
MESSAGE(STATUS "Platform arch:" ${PLATFORM_ARCH_STR})
184

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