forked from TinyCC/tinycc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tcc.cmake
68 lines (58 loc) · 2.21 KB
/
tcc.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
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
if(SYSTEM_NAME STREQUAL Native AND HOST_ARCH)
if (WIN32)
set(SYSTEM_NAME Windows)
elseif (APPLE)
set(SYSTEM_NAME Darwin)
elseif (UNIX)
set(SYSTEM_NAME Linux)
else()
set(SYSTEM_NAME Generic)
endif()
set(IS_NATIVE TRUE)
elseif(NOT HOST_ARCH OR NOT SYSTEM_NAME OR NOT CMAKE_BUILD_TYPE)
message(SEND_ERROR "the `cmake_tcc . . .` missing:
- `BUILD_TYPE` required to be specified: Debug, Release, ...
- `SYSTEM_NAME` required to be specified: Native, Windows, Linux, GNU, Generic, Android, FreeBSD, Darwin, ...
- `HOST_ARCH` required to be specified: i386, x86_64, armv7, arm64, riscv64, ...
Note: Native is for regular `tcc` compiler, otherwise cross compiler.
")
endif()
set(CMAKE_SYSTEM_NAME ${SYSTEM_NAME})
set(COMPILER_PREFIX ${HOST_ARCH})
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES HOST_ARCH)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
if(HOST_ARCH STREQUAL armv7)
set(COMPILER_PREFIX ${HOST_ARCH}-wince)
elseif(HOST_ARCH STREQUAL i386 OR HOST_ARCH STREQUAL x86_64)
set(COMPILER_PREFIX ${HOST_ARCH}-win32)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(HOST_ARCH STREQUAL arm64 OR HOST_ARCH STREQUAL x86_64)
set(COMPILER_PREFIX ${HOST_ARCH}-osx)
endif()
endif()
set(EXT )
if(WIN32)
set(EXT .exe)
endif()
if(IS_NATIVE STREQUAL TRUE)
set(program "$ENV{CC}")
else()
set(program "$ENV{CPATH}/${COMPILER_PREFIX}-tcc${EXT}")
endif()
find_program(CMAKE_C_COMPILER NAMES ${program} PATHS ENV PATH NO_DEFAULT_PATH)
set(TOOLCHAIN_PREFIX ${COMPILER_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
if(IS_NATIVE STREQUAL TRUE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -bt -b -g ")
else()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g ")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -L\"$ENV{LIBRARY_PATH}\" -I\"$ENV{C_INCLUDE_PATH}\" ")
message (STATUS "Using compiler: ${CMAKE_C_COMPILER}")
message (STATUS "Using architecture: ${HOST_ARCH}")
message (STATUS "Using library directory: $ENV{LIBRARY_PATH}")
message (STATUS "Using toolchain prefix: ${TOOLCHAIN_PREFIX}")