-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgcc.cmake
86 lines (69 loc) · 2.03 KB
/
gcc.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
find_program(GCC
NAMES gcc gcc.exe
PATHS /usr/bin /bin
DOC "Path to gcc"
)
if(NOT EXISTS ${GCC})
message(FATAL_ERROR "gcc not found")
endif()
#[[
Compile source with gcc
Parameters:
INPUT <file...> - required - list of inputs
OUTPUT <file> - required - generated binary
BITS <bits> - optional - specify machine type (default 64) can be one of the following:
32 32 bit build
64 64 bit build
LINK_SCRIPT <file> - optional - use linker script by passing -T <file>
FREESTANDING - optional - passes -ffreestanding
NOEXCEPTIONS - optional - passes -fno-exceptions
NORTTI - optional - passes -fno-rtti
NOSTDLIB - optional - passes -nostdlib
WALL - optonal - passes -Wall
WEXTRA - optional - passes -Wextra
]]
function(gcc)
set(_options NOEXCEPTIONS NORTTI WALL WEXTRA FREESTANDING)
set(_single_args OUTPUT BITS LINK_SCRIPT)
set(_multi_args INPUTS)
cmake_parse_arguments(gcc "${_options}" "${_single_args}" "${_multi_args}" ${ARGN})
set(_cmd ${GCC} -o ${gcc_OUTPUT})
if(gcc_BITS)
set(_cmd ${_cmd} -m${gcc_BITS})
else()
set(_cmd ${_cmd} -m64)
endif()
if(gcc_LINK_SCRIPT)
get_filename_component(gcc_LINK_SCRIPT ${gcc_LINK_SCRIPT} ABSOLUTE)
set(_cmd ${_cmd} -T ${gcc_LINK_SCRIPT})
endif()
if(gcc_NOEXCEPTIONS)
set(_cmd ${_cmd} -fno-exceptions)
endif()
if(gcc_NORTTI)
set(_cmd ${_cmd} -fno-rtti)
endif()
if(gcc_WALL)
set(_cmd ${_cmd} -Wall)
endif()
if(gcc_WEXTRA)
set(_cmd ${_cmd} -Wextra)
endif()
if(gcc_FREESTANDING)
set(_cmd ${_cmd} -ffreestanding)
endif()
if(gcc_NOSTDLIB)
set(_cmd ${_cmd} -nostdlib)
endif()
foreach(_tmp ${gcc_INPUTS})
get_filename_component(_tmp ${_tmp} ABSOLUTE)
set(_cmd ${_cmd} ${_tmp})
endforeach()
add_custom_command(
OUTPUT ${gcc_OUTPUT}
DEPENDS ${gcc_INPUT} ${gcc_INPUTS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
COMMAND ${CMAKE_COMMAND} -E echo ${_cmd}
COMMAND ${_cmd}
)
endfunction()