-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMacros.cmake
183 lines (164 loc) · 6.91 KB
/
Macros.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# General Cmake settings
cmake_minimum_required(VERSION 3.9.0)
SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE ) # allow more human readable "if then else" constructs
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Try to find an external Sparrow executable
find_program(SPARROW_EXECUTABLE_EXT NAMES SparrowCompiler DOC "path to the SparrowCompiler executable (external)")
# Try to find an external llc executable
find_program(LLC_EXECUTABLE_EXT NAMES spr-llc "${LLVM_TOOLS_BINARY_DIR}/llc" DOC "path to the llc executable (external)")
# Try to find an external opt executable
find_program(OPT_EXECUTABLE_EXT NAMES spr-opt "${LLVM_TOOLS_BINARY_DIR}/opt" DOC "path to the opt executable (external)")
MACRO(GROUP_NAME_FROM_PATH filePath resultVar)
IF(MSVC OR APPLE)
GET_FILENAME_COMPONENT(dir ${filePath} PATH)
IF(dir STREQUAL "")
SET(dir "\\")
ENDIF()
STRING(REPLACE "/" "\\" ${resultVar} "${dir}")
#MESSAGE(STATUS "File folder: ${${resultVar}} - ${f}")
ENDIF()
ENDMACRO(GROUP_NAME_FROM_PATH)
MACRO(ADD_SOURCES_TO_GROUPS sourcesVar)
IF(MSVC OR APPLE)
FOREACH(f ${${sourcesVar}})
GROUP_NAME_FROM_PATH(${f} dirR)
SOURCE_GROUP(${dirR} FILES ${f})
ENDFOREACH()
ENDIF()
ENDMACRO(ADD_SOURCES_TO_GROUPS)
macro(SPARROW_TARGET Name Input Output)
set(SPARROW_TARGET_outputs "${Output}")
set(SPARROW_EXECUTABLE_opts "")
set(SPARROW_TARGET_PARAM_OPTIONS)
set(SPARROW_TARGET_PARAM_ONE_VALUE_KEYWORDS
COMPILE_FLAGS
)
set(SPARROW_TARGET_MULTI_VALUE_KEYWORDS
DEPENDS
)
cmake_parse_arguments(
SPARROW_TARGET_ARG
"${SPARROW_TARGET_PARAM_OPTIONS}"
"${SPARROW_TARGET_PARAM_ONE_VALUE_KEYWORDS}"
"${SPARROW_TARGET_MULTI_VALUE_KEYWORDS}"
${ARGN}
)
set(SPARROW_TARGET_usage "SPARROW_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>] [DEPENDS <files>]")
if(NOT "${SPARROW_TARGET_ARG_UNPARSED_ARGUMENTS}" STREQUAL "")
message(SEND_ERROR ${SPARROW_TARGET_usage})
else()
if(NOT "${SPARROW_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "")
set(SPARROW_EXECUTABLE_opts "${SPARROW_TARGET_ARG_COMPILE_FLAGS}")
separate_arguments(SPARROW_EXECUTABLE_opts)
endif()
add_custom_command(OUTPUT ${SPARROW_TARGET_outputs}
COMMAND ${SPARROW_EXECUTABLE_EXT} ${SPARROW_EXECUTABLE_opts} -o ${Output} ${Input}
VERBATIM
DEPENDS ${Input} ${SPARROW_TARGET_ARG_DEPENDS}
COMMENT "[SPARROW][${Name}] Building Sparrow object ${Output}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(${Name}_DEFINED TRUE)
set(${Name}_OUTPUTS ${Output})
set(${Name}_INPUT ${Input})
set(${Name}_COMPILE_FLAGS ${SPARROW_EXECUTABLE_opts})
endif()
endmacro()
macro(LLVMASM_TARGET Name Input Output)
set(LLVMASM_TARGET_outputs "${Output}")
set(LLVMASM_EXECUTABLE_opts "")
set(LLVMASM_TARGET_PARAM_OPTIONS)
set(LLVMASM_TARGET_PARAM_ONE_VALUE_KEYWORDS
COMPILE_FLAGS
)
set(LLVMASM_TARGET_MULTI_VALUE_KEYWORDS
DEPENDS
)
cmake_parse_arguments(
LLVMASM_TARGET_ARG
"${LLVMASM_TARGET_PARAM_OPTIONS}"
"${LLVMASM_TARGET_PARAM_ONE_VALUE_KEYWORDS}"
"${LLVMASM_TARGET_MULTI_VALUE_KEYWORDS}"
${ARGN}
)
set(LLVMASM_TARGET_usage "LLVMASM_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>] [DEPENDS <files>]")
if(NOT "${LLVMASM_TARGET_ARG_UNPARSED_ARGUMENTS}" STREQUAL "")
message(SEND_ERROR ${LLVMASM_TARGET_usage})
else()
if(NOT "${LLVMASM_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "")
set(LLVMASM_EXECUTABLE_opts "${LLVMASM_TARGET_ARG_COMPILE_FLAGS}")
separate_arguments(LLVMASM_EXECUTABLE_opts)
endif()
add_custom_command(OUTPUT ${LLVMASM_TARGET_outputs}
COMMAND ${OPT_EXECUTABLE_EXT} -O2 ${Input} | ${LLC_EXECUTABLE_EXT} --filetype=obj ${LLVMASM_EXECUTABLE_opts} -o ${Output}
VERBATIM
DEPENDS ${Input} ${LLVMASM_TARGET_ARG_DEPENDS}
COMMENT "[LLVM][${Name}] Building object ${Output}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(${Name}_DEFINED TRUE)
set(${Name}_OUTPUTS ${Output})
set(${Name}_INPUT ${Input})
set(${Name}_COMPILE_FLAGS ${LLVMASM_EXECUTABLE_opts})
endif()
endmacro()
# MACRO(BISON_GENERATOR inputGrammarFile generatedSourcesVar)
# IF(BISON_EXECUTABLE)
# # Get the running directory - the directory of the bison executable
# GET_FILENAME_COMPONENT(runDir ${BISON_EXECUTABLE} PATH)
#
# # The absolute path of the input
# GET_FILENAME_COMPONENT(inputGrammarFileAbs ${inputGrammarFile} ABSOLUTE)
#
# # The outputs
# SET(outHeader ${CMAKE_CURRENT_BINARY_DIR}/${inputGrammarFile}.h)
# SET(outCpp ${CMAKE_CURRENT_BINARY_DIR}/${inputGrammarFile}.cpp)
# SET(${generatedSourcesVar} ${outCpp} ${outHeader})
#
# # Add a custom command to invoke bison
# ADD_CUSTOM_COMMAND(
# OUTPUT ${${generatedSourcesVar}}
# DEPENDS ${inputGrammarFile}
# COMMAND ${BISON_EXECUTABLE}
# ARGS -o"${outCpp}" --defines="${outHeader}" ${inputGrammarFileAbs}
# WORKING_DIRECTORY ${runDir}
# COMMENT "Generating parser with bison for '${inputGrammarFile}'"
# )
#
# # Set the right properties for the generated files
# SET_SOURCE_FILES_PROPERTIES( ${${generatedSourcesVar}} GENERATED)
# GROUP_NAME_FROM_PATH(${inputGrammarFile} groupName)
# SOURCE_GROUP(${groupName} FILES ${${generatedSourcesVar}})
# ELSE(BISON_EXECUTABLE)
# MESSAGE(SEND_ERROR "Can't find bison program; please define BISON_EXECUTABLE")
# ENDIF(BISON_EXECUTABLE)
# ENDMACRO(BISON_GENERATOR)
#
# MACRO(FLEX_GENERATOR inputGrammarFile generatedSourcesVar)
# IF(FLEX_EXECUTABLE)
# # Get the running directory - the directory of the bison executable
# GET_FILENAME_COMPONENT(runDir ${FLEX_EXECUTABLE} PATH)
#
# # The absolute path of the input
# GET_FILENAME_COMPONENT(inputGrammarFileAbs ${inputGrammarFile} ABSOLUTE)
#
# # The outputs
# SET(outCpp ${CMAKE_CURRENT_BINARY_DIR}/${inputGrammarFile}.cpp)
# SET(${generatedSourcesVar} ${outCpp})
#
# # Add a custom command to invoke bison
# ADD_CUSTOM_COMMAND(
# OUTPUT ${${generatedSourcesVar}}
# DEPENDS ${inputGrammarFile}
# COMMAND ${FLEX_EXECUTABLE}
# ARGS -o"${outCpp}" ${inputGrammarFileAbs}
# WORKING_DIRECTORY ${runDir}
# COMMENT "Generating scanner with flex for '${inputGrammarFile}'"
# )
#
# # Set the right properties for the generated files
# SET_SOURCE_FILES_PROPERTIES( ${${generatedSourcesVar}} GENERATED)
# GROUP_NAME_FROM_PATH(${inputGrammarFile} groupName)
# SOURCE_GROUP(${groupName} FILES ${${generatedSourcesVar}})
# ELSE(FLEX_EXECUTABLE)
# MESSAGE(SEND_ERROR "Can't find flex program; please define FLEX_EXECUTABLE")
# ENDIF(FLEX_EXECUTABLE)
# ENDMACRO(FLEX_GENERATOR)