-
Notifications
You must be signed in to change notification settings - Fork 392
/
DDRSetStub.cmake.in
299 lines (256 loc) · 10.3 KB
/
DDRSetStub.cmake.in
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
###############################################################################
# Copyright IBM Corp. and others 2019
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
# or the Apache License, Version 2.0 which accompanies this distribution
# and is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the
# Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
# version 2 with the GNU Classpath Exception [1] and GNU General Public
# License, version 2 with the OpenJDK Assembly Exception [2].
#
# [1] https://www.gnu.org/software/classpath/license.html
# [2] https://openjdk.org/legal/assembly-exception.html
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
#############################################################################
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
set(OMR_EXE_LAUNCHER "@OMR_EXE_LAUNCHER@")
set(OMR_MODULES_DIR "@OMR_MODULES_DIR@")
set(DDR_SUPPORT_DIR "@OMR_MODULES_DIR@/ddr")
set(DDR_INFO_DIR "@DDR_INFO_DIR@")
set(DDR_EXCLUDES "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,EXCLUDES>")
set(DDR_OVERRIDES_FILE "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,OVERRIDES_FILE>")
set(DDR_BLOB "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,BLOB>")
set(DDR_SUPERSET "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,SUPERSET>")
set(DDR_MACRO_LIST "${DDR_INFO_DIR}/sets/@DDR_TARGET_NAME@.macros")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${OMR_MODULES_DIR})
set(OBJECT_SEARCH_ROOT "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,DDR_OBJECT_SEARCH_ROOT>")
set(DDR_TARGETS
$<JOIN:$<TARGET_PROPERTY:@DDR_TARGET_NAME@,DDR_TARGETS>,
>
)
set(DDR_SUBSETS
$<JOIN:$<TARGET_PROPERTY:@DDR_TARGET_NAME@,DDR_SUBSETS>,
>
)
set(OBJECT_EXCLUDE_REGEX "^$<JOIN:$<TARGET_PROPERTY:@DDR_TARGET_NAME@,DDR_OBJECT_EXCLUDES>,|^>")
project(@DDR_TARGET_NAME@ LANGUAGES NONE)
include("@DDR_TOOLS_EXPORT@")
include(OmrUtility)
# Given a var, make the path specified absolute,
# assuming paths are relative to the ddr set source directory.
macro(make_absolute var_name)
if(${var_name})
get_filename_component(${var_name} "${${var_name}}"
ABSOLUTE
BASE_DIR "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,SOURCE_DIR>")
endif()
endmacro()
make_absolute(DDR_BLOB)
make_absolute(DDR_EXCLUDES)
make_absolute(DDR_OVERRIDES_FILE)
make_absolute(DDR_SUPERSET)
function(get_relative_path output filename base)
get_filename_component(temp "${filename}" ABSOLUTE BASE_DIR "${base}")
file(RELATIVE_PATH temp "${temp}" "${base}")
set("${output}" "${temp}" PARENT_SCOPE)
endfunction()
function(add_filename_extension output filename prefix)
get_filename_component(extension "${filename}" EXT)
string(LENGTH "${extension}" ext_length)
if(ext_length EQUAL 0)
message(SEND_ERROR "No file extension found")
endif()
string(REGEX REPLACE "${extension}$" "${prefix}${extension}" temp "${filename}")
set("${output}" "${temp}" PARENT_SCOPE)
endfunction()
function(process_source_files src_files)
set(options "")
set(one_value "SOURCE_DIR" "TARGET" "OUTPUT_STUBS" "OUTPUT_ANNOTATED")
set(multi_value "INCLUDE_DIRS" "DEFINES" "INCLUDE_FILES" "PREINCLUDES")
cmake_parse_arguments("OPT" "${options}" "${one_value}" "${multi_value}" ${ARGV})
set(stub_files)
set(annotated_files)
# Build up the command line to the preprocessor.
set(BASE_ARGS)
if("@CMAKE_C_COMPILER_ID@" STREQUAL "MSVC")
list(APPEND BASE_ARGS "-nologo")
endif()
foreach(incdir IN LISTS OPT_INCLUDE_DIRS)
list(APPEND BASE_ARGS "-I${incdir}")
endforeach()
foreach(def IN LISTS OPT_DEFINES)
list(APPEND BASE_ARGS "-D${def}")
endforeach()
foreach(source_file IN LISTS OPT_UNPARSED_ARGUMENTS)
get_filename_component(extension "${source_file}" EXT)
# If source_file isn't a C/C++ file, ignore it.
if(NOT extension MATCHES "\.[ch](pp)?$")
continue()
endif()
get_filename_component(abs_file "${source_file}" ABSOLUTE BASE_DIR "${OPT_SOURCE_DIR}")
file(RELATIVE_PATH output_file "${OPT_SOURCE_DIR}" "${abs_file}")
string(REGEX REPLACE "\\.\\.(/|$)" "__\\1" output_file "${output_file}")
set(output_file "${OPT_TARGET}/${output_file}")
get_filename_component(output_dir "${output_file}" DIRECTORY)
file(MAKE_DIRECTORY "${output_dir}")
add_filename_extension(stub_file "${output_file}" ".stub")
add_filename_extension(annt_file "${output_file}" ".annt")
list(APPEND stub_files "${stub_file}")
list(APPEND annotated_files "${annt_file}")
add_custom_command(
OUTPUT "${stub_file}"
DEPENDS
${abs_file}
${DDR_SUPPORT_DIR}/cmake_ddr.awk
${DDR_SUPPORT_DIR}/GenerateStub.cmake
COMMAND ${CMAKE_COMMAND}
-DAWK_SCRIPT=${DDR_SUPPORT_DIR}/cmake_ddr.awk
-DUSE_PATH_TOOL=@USE_PATH_TOOL@
-Dinput_file=${abs_file}
-Doutput_file=${stub_file}
-P ${DDR_SUPPORT_DIR}/GenerateStub.cmake
COMMENT ""
VERBATIM
)
set(pp_command "@CMAKE_C_COMPILER@")
if("@CMAKE_C_COMPILER_IS_XLCLANG@")
# XLClang seems to have trouble with *.h and *.hpp files here, claiming:
# "error: invalid argument '-std=gnu++0x' not allowed with 'C/ObjC'"
# Adding this option to the command alleviates this issue.
list(APPEND pp_command "-xc++")
endif()
if("@OMR_OS_ZOS@" AND "@OMR_ENV_DATA64@")
# We need to set 64 bit code generation to ensure that limits.h macros are set correctly.
list(APPEND pp_command "-Wc,lp64")
endif()
if("@OMR_OS_WINDOWS@" AND extension MATCHES "\.hpp$")
# Visual Studio needs to be told that .hpp files are C++ code.
list(APPEND pp_command "/TP")
endif()
list(APPEND pp_command ${BASE_ARGS} "-E" "${stub_file}")
add_custom_command(
OUTPUT "${annt_file}"
DEPENDS "${stub_file}"
COMMAND ${pp_command} | awk "/^DDRFILE_BEGIN /,/^DDRFILE_END / { gsub(/[\\t\\r ]*$/, \"\"); if (NF != 0) { print \"@\" $0 } }" > ${annt_file}
COMMENT ""
VERBATIM
)
endforeach()
if(OPT_OUTPUT_STUBS)
set("${OPT_OUTPUT_STUBS}" "${stub_files}" PARENT_SCOPE)
endif()
if(OPT_OUTPUT_ANNOTATED)
set("${OPT_OUTPUT_ANNOTATED}" "${annotated_files}" PARENT_SCOPE)
endif()
endfunction(process_source_files)
set(stubannotated_files "")
set(target_files "")
function(process_target target)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${target}")
set(target_info_file "${DDR_INFO_DIR}/targets/${target}.txt")
# Make cmake configuration depend on input file.
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${target_info_file}")
file(STRINGS "${target_info_file}" target_config)
cmake_parse_arguments("OPT" "" "SOURCE_DIR;OUTPUT_FILE" "INCLUDE_PATH;DEFINES;SOURCES;HEADERS;PREINCLUDES" ${target_config})
if(OPT_OUTPUT_FILE)
set(target_files ${target_files} "${OPT_OUTPUT_FILE}" PARENT_SCOPE)
endif()
process_source_files(
${OPT_SOURCES}
TARGET "${target}"
SOURCE_DIR "${OPT_SOURCE_DIR}"
OUTPUT_ANNOTATED project_annt_src
INCLUDE_DIRS ${OPT_INCLUDE_PATH}
DEFINES ${OPT_DEFINES}
)
list(APPEND annotated_files ${project_annt_src})
# The only difference between source files and header files, is that header files may need
# other headers pre-included so that preprocessor macros work properly.
process_source_files(
${OPT_HEADERS}
TARGET "${target}"
SOURCE_DIR "${OPT_SOURCE_DIR}"
OUTPUT_ANNOTATED project_annt_hdr
INCLUDE_DIRS ${OPT_INCLUDE_PATH}
DEFINES ${OPT_DEFINES}
# TODO need to add pre-include files
)
list(APPEND annotated_files ${project_annt_hdr})
# Bump changes up to parent scope.
set(annotated_files "${annotated_files}" PARENT_SCOPE)
endfunction(process_target)
foreach(target IN LISTS DDR_TARGETS)
process_target("${target}")
endforeach()
set(subset_macro_lists "")
foreach(subset IN LISTS DDR_SUBSETS)
list(APPEND subset_macro_lists "${DDR_INFO_DIR}/sets/${subset}.macros")
endforeach()
add_custom_command(
OUTPUT ${DDR_MACRO_LIST}
DEPENDS ${annotated_files} ${subset_macro_lists}
COMMAND cat ${annotated_files} ${subset_macro_lists} > ${DDR_MACRO_LIST}
)
set(EXTRA_DDRGEN_OPTIONS "")
if(DDR_EXCLUDES)
list(APPEND EXTRA_DDRGEN_OPTIONS "--excludes" "${DDR_EXCLUDES}")
endif()
if(DDR_BLOB)
list(APPEND EXTRA_DDRGEN_OPTIONS "--blob" "${DDR_BLOB}")
endif()
if(DDR_SUPERSET)
list(APPEND EXTRA_DDRGEN_OPTIONS "--superset" "${DDR_SUPERSET}")
endif()
if(DDR_OVERRIDES_FILE)
# Because ddr overrides files specify relative paths, we need to run ddrgen
# in the same directory as the overrides files.
get_filename_component(override_file_dir "${DDR_OVERRIDES_FILE}" DIRECTORY)
list(APPEND EXTRA_DDRGEN_OPTIONS "--overrides" "${DDR_OVERRIDES_FILE}" WORKING_DIRECTORY "${override_file_dir}")
endif()
set(subset_binaries)
foreach(subset IN LISTS DDR_SUBSETS)
# The name of the file which subset generates, listing all of the input binaries.
set(binaries_list_file "${DDR_INFO_DIR}/sets/${subset}.binaries")
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${binaries_list_file}")
file(STRINGS "${binaries_list_file}" binaries)
list(APPEND subset_binaries ${binaries})
endforeach()
if(ZOS)
# On z/OS, we have to glob for the individual .dbg files.
set(target_files)
if(OBJECT_EXCLUDE_REGEX STREQUAL "^")
# Empty exclude regex, just include everything.
file(GLOB_RECURSE target_files "${OBJECT_SEARCH_ROOT}/*.dbg")
else()
file(GLOB_RECURSE dbg_files RELATIVE "${OBJECT_SEARCH_ROOT}" "${OBJECT_SEARCH_ROOT}/*.dbg")
foreach(item IN LISTS dbg_files)
if(NOT "${item}" MATCHES "${OBJECT_EXCLUDE_REGEX}")
list(APPEND target_files "${OBJECT_SEARCH_ROOT}/${item}")
endif()
endforeach()
endif()
endif()
# Now we generate our own list of binaries, so that they can be parsed if we are a subset.
omr_join("\n" binaries_list
${target_files}
${subset_binaries}
)
file(WRITE "${DDR_INFO_DIR}/sets/@DDR_TARGET_NAME@.binaries" "${binaries_list}")
if(DDR_BLOB OR DDR_SUPERSET)
add_custom_command(
OUTPUT ${DDR_BLOB} ${DDR_SUPERSET}
DEPENDS ${DDR_MACRO_LIST} ${target_files} ${subset_binaries} omr_ddrgen
COMMAND ${OMR_EXE_LAUNCHER} $<TARGET_FILE:omr_ddrgen>
${target_files} ${subset_binaries}
--show-empty
--macrolist ${DDR_MACRO_LIST}
${EXTRA_DDRGEN_OPTIONS}
)
endif()
add_custom_target(@DDR_TARGET_NAME@ ALL DEPENDS ${DDR_BLOB} ${DDR_MACRO_LIST})