forked from 0x10cAtlas/AtlasOS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DCPUToolchain.cmake
139 lines (133 loc) · 6.04 KB
/
DCPUToolchain.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Check to ensure that the appropriate tool path
# has been defined.
if(NOT DEFINED DCPUTOOLCHAIN)
# The developer must define the path to the DCPUTOOLCHAIN
# binaries.
message(FATAL_ERROR "You must define DCPUTOOLCHAIN as the path to toolchain binaries.")
else(NOT DEFINED DCPUTOOLCHAIN)
# Reconfigure the variable to point to the correct location.
set(DCPUTOOLCHAIN "${CMAKE_CURRENT_LIST_DIR}/${DCPUTOOLCHAIN}")
endif(NOT DEFINED DCPUTOOLCHAIN)
# Define a general function that allows us to
# define tools and their handling of files.
function(define_dcpu_tool tool toolargs verb files runasm outvar)
set(tout "")
foreach(arg ${ARGN})
set(UARGN "${UARGN} ${arg}")
endforeach(arg ${ARGN})
if("${toolargs}" STREQUAL "")
message(" .. defining tool ${tool} with '${files}'")
else("${toolargs}" STREQUAL "")
message(" .. defining tool ${tool} ${toolargs} with '${files}'")
endif("${toolargs}" STREQUAL "")
if(DEFINED VERY_VERBOSE)
message(" recognising ${UARGN}")
endif(DEFINED VERY_VERBOSE)
foreach(i ${files})
get_filename_component(fext "${i}" EXT)
get_filename_component(fpth "${i}" PATH)
get_filename_component(fbse "${i}" NAME_WE)
string(TOLOWER "${fext}" fextc)
if(DEFINED VERY_VERBOSE)
message(" .. scanning ${i}")
message(" extension: ${fext}")
endif(DEFINED VERY_VERBOSE)
set(extension_matches false)
foreach(e ${ARGN})
if(DEFINED VERY_VERBOSE)
message(" .. checking ${e}")
endif(DEFINED VERY_VERBOSE)
if("${fext}" STREQUAL "${e}")
if(DEFINED VERY_VERBOSE)
message(" (extension matches)")
endif(DEFINED VERY_VERBOSE)
set(extension_matches true)
endif("${fext}" STREQUAL "${e}")
endforeach(e ${ARGN})
if(${extension_matches} STREQUAL "true")
if(${runasm} STREQUAL "true")
if(DEFINED VERY_VERBOSE)
message(" .. adding command")
message(" output: ${fpth}/${fbse}.o")
message(" command: ${DCPUTOOLCHAIN}/${tool}${CMAKE_EXECUTABLE_SUFFIX} ${toolargs} -o \"${fpth}/${fbse}.oa\" \"${i}\"")
message(" command: ${DCPUTOOLCHAIN}/dtasm${CMAKE_EXECUTABLE_SUFFIX} -i -o \"${fpth}/${fbse}.o\" \"${fpth}/${fbse}.oa\"")
message(" depends: ${tool} dtasm ${i}")
endif(DEFINED VERY_VERBOSE)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.oa
COMMAND ${DCPUTOOLCHAIN}/${tool}${CMAKE_EXECUTABLE_SUFFIX}
ARGS ${toolargs} -I "${CMAKE_CURRENT_SOURCE_DIR}/include" -o "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.oa" "${CMAKE_CURRENT_SOURCE_DIR}/${i}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${i}"
COMMENT "${verb} ${fbse}${fext} with DCPU-Toolchain...")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o
COMMAND ${DCPUTOOLCHAIN}/dtasm${CMAKE_EXECUTABLE_SUFFIX}
ARGS -i -o "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o" -s "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.os" "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.oa"
DEPENDS ${tool} dtasm "${CMAKE_CURRENT_SOURCE_DIR}/${i}" "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.oa"
COMMENT "Assembling ${fpth}/${fbse}.oa with DCPU-Toolchain...")
if("${tout}" STREQUAL "")
set(tout "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o")
else("${tout}" STREQUAL "")
list(APPEND tout "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o")
endif("${tout}" STREQUAL "")
set(${outvar} "${${outvar}} ${tout}" PARENT_SCOPE)
else(${runasm} STREQUAL "true")
if(DEFINED VERY_VERBOSE)
message(" .. adding command")
message(" output: ${fpth}/${fbse}.o")
message(" command: ${DCPUTOOLCHAIN}/${tool}${CMAKE_EXECUTABLE_SUFFIX} ${toolargs} -o \"${fpth}/${fbse}.o\" \"${i}\"")
message(" depends: ${tool}")
endif(DEFINED VERY_VERBOSE)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o
COMMAND ${DCPUTOOLCHAIN}/${tool}${CMAKE_EXECUTABLE_SUFFIX}
ARGS ${toolargs} -s "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.os" -o "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o" "${CMAKE_CURRENT_SOURCE_DIR}/${i}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${i}"
COMMENT "${verb} ${fbse}${fext} with DCPU-Toolchain...")
if("${tout}" STREQUAL "")
set(tout "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o")
else("${tout}" STREQUAL "")
list(APPEND tout "${CMAKE_CURRENT_SOURCE_DIR}/${fpth}/${fbse}.o")
endif("${tout}" STREQUAL "")
set(${outvar} "${${outvar}} ${tout}" PARENT_SCOPE)
endif(${runasm} STREQUAL "true")
endif(${extension_matches} STREQUAL "true")
endforeach(i ${files})
endfunction(define_dcpu_tool tool toolargs files outvar)
# Define function to specify a standard library target.
function(add_dcpu_image target)
set(toutputs "")
message(" >> ${target}")
# Define each of the tools using the files list.
define_dcpu_tool(dtasm "-i" "Assembling" "${ARGN}" "false" tasmoutputs ".dasm" ".dasm16")
define_dcpu_tool(dtcc "" "Compiling" "${ARGN}" "true" tcoutputs ".c")
# Define the linker.
string(STRIP "${tasmoutputs}" tasmoutputs)
string(STRIP "${tcoutputs}" tcoutputs)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${target}.dcpu16"
COMMAND ${DCPUTOOLCHAIN}/dtld${CMAKE_EXECUTABLE_SUFFIX}
ARGS -s "${CMAKE_CURRENT_BINARY_DIR}/${target}.dsym16" --symbol-extension="os" -o "${CMAKE_CURRENT_BINARY_DIR}/${target}.dcpu16" ${tasmoutputs} ${tcoutputs}
DEPENDS ${tasmoutputs} ${tcoutputs}
COMMENT "Linking ${target}.dcpu16 as image with DCPU-Toolchain...")
# Define our target.
foreach(i ${tasmoutputs})
if(DEFINED params)
list(APPEND params DEPENDS)
list(APPEND params ${i})
else(DEFINED params)
set(params DEPENDS ${i})
endif(DEFINED params)
endforeach(i ${tasmoutputs})
foreach(i ${tcoutputs})
if(DEFINED params)
list(APPEND params DEPENDS)
list(APPEND params ${i})
else(DEFINED params)
set(params DEPENDS ${i})
endif(DEFINED params)
endforeach(i ${tcoutputs})
list(APPEND params DEPENDS)
list(APPEND params "${CMAKE_CURRENT_BINARY_DIR}/${target}.dcpu16")
add_custom_target(${target} ALL ${params})
endfunction(add_dcpu_image target)