-
Notifications
You must be signed in to change notification settings - Fork 1
/
cvbuild.cmake
121 lines (116 loc) · 3.75 KB
/
cvbuild.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Author: Zhuo Zhang <imzhuo@foxmail.com>
# Homepage: https://github.com/zchrissirhcz/rocbuild
# Last update: 2024-06-12 00:00:00
cmake_minimum_required(VERSION 3.15)
include_guard()
set(CVBUILD_VERSION "2024.06.12")
###############################################################
#
# Platform determinations
#
###############################################################
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CVBUILD_PLATFORM "windows")
elseif(ANDROID)
set(CVBUILD_PLATFORM "android")
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CVBUILD_PLATFORM "linux")
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CVBUILD_PLATFORM "mac")
else()
message(FATAL_ERROR "un-configured platform: ${CMAKE_SYSTEM_NAME}")
endif()
if(CVBUILD_VERBOSE)
message(STATUS "----- CVBUILD_PLATFORM: ${CVBUILD_PLATFORM}")
endif()
###############################################################
#
# Architecture determinations
#
###############################################################
if((IOS AND CMAKE_OSX_ARCHITECTURES MATCHES "arm")
OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|Arm|ARM|aarch64|AAarch64|AARCH64)"))
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CVBUILD_ARCH arm64)
else()
set(CVBUILD_ARCH arm32)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips|Mips|MIPS)")
set(CVBUILD_ARCH mips)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|Riscv|RISCV)")
set(CVBUILD_ARCH riscv)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|PowerPC|POWERPC)")
set(CVBUILD_ARCH powerpc)
else()
set(CVBUILD_ARCH x86)
#if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") #wasm
#endif()
endif()
if (CVBUILD_VERBOSE)
message(STATUS "----- CVBUILD_ARCH: ${CVBUILD_ARCH}")
endif()
###############################################################
#
# ABI determinations
#
###############################################################
if (ANDROID)
set(CVBUILD_ABI ${ANDROID_ABI})
elseif(CVBUILD_ARCH STREQUAL x86)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CVBUILD_ABI "x64")
else()
set(CVBUILD_ABI "x86")
endif()
elseif(CVBUILD_ARCH MATCHES arm)
# determine ARCH from compiler name. Note: we can't use MATCHES for c++ compiler, since `++` failed for regular expression
if(CMAKE_C_COMPILER MATCHES "aarch64-linux-gnu-gcc")
set(CVBUILD_ABI "aarch64")
elseif(CMAKE_C_COMPILER MATCHES "arm-linux-gnueabihf-gcc")
set(CVBUILD_ABI "arm-eabihf")
elseif(CMAKE_C_COMPILER MATCHES "aarch64-none-linux-gnu-gcc")
set(CVBUILD_ABI "aarch64")
elseif(NOT CMAKE_CROSS_COMPILATION)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CVBUILD_ABI "aarch64")
else()
message(FATAL_ERROR "un-assigned ABI, please add it now")
endif()
else()
message(FATAL_ERROR "un-assigned ABI, please add it now")
endif()
else()
message(FATAL_ERROR "un-assigned ABI, please add it now")
endif()
if (CVBUILD_VERBOSE)
message(STATUS "----- CVBUILD_ABI: ${CVBUILD_ABI}")
endif()
###############################################################
#
# Visual Studio stuffs: vs_version, vc_version
#
###############################################################
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
if(MSVC_VERSION EQUAL 1600)
set(vs_version vs2010)
set(vc_version vc10)
elseif(MSVC_VERSION EQUAL 1700)
set(vs_version vs2012)
set(vc_version vc11)
elseif(MSVC_VERSION EQUAL 1800)
set(vs_version vs2013)
set(vc_version vc12)
elseif(MSVC_VERSION EQUAL 1900)
set(vs_version vs2015)
set(vc_version vc14)
elseif(MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1920)
set(vs_version vs2017)
set(vc_version vc15)
elseif(MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS_EQUAL 1930)
set(vs_version vs2019)
set(vc_version vc16)
elseif(MSVC_VERSION GREATER_EQUAL 1930)
set(vs_version vs2022)
set(vc_version vc17)
endif()
endif()