-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRoqAutogen.cmake
218 lines (212 loc) · 7.77 KB
/
RoqAutogen.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
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
# what: roq_gitignore
function(roq_gitignore)
set(options DUMMY_OPTION)
set(one_value OUTPUT)
set(multi_value SOURCES)
cmake_parse_arguments(SELF "${options}" "${one_value}" "${multi_value}" ${ARGN})
set(gitignore "${CMAKE_CURRENT_SOURCE_DIR}/${SELF_OUTPUT}")
message(STATUS "gitignore=${gitignore}")
file(WRITE "${gitignore}" "")
file(APPEND "${gitignore}" "!!! THIS FILE HAS BEEN AUTO-GENERATED !!!\n")
foreach(source ${SELF_SOURCES})
get_filename_component(name ${source} NAME)
file(APPEND "${gitignore}" "${name}\n")
endforeach()
endfunction()
# what: roq_autogen_[...]
#
# required variables: ROQ_AUTOGEN CLANG_FORMAT
#
# note! cmake doesn't allow argument forwarding => lots of duplication in the following
function(roq_autogen_hpp)
set(SELF_LANGUAGE "cpp")
set(SELF_FILE_TYPE "hpp")
set(options DUMMY_OPTION)
set(one_value OUTPUT NAMESPACE SCHEMA_DIR SCHEMA_LINK_DIR TEMPLATE_DIR TEMPLATE_TYPE)
set(multi_value SOURCES DEPENDS)
cmake_parse_arguments(SELF "${options}" "${one_value}" "${multi_value}" ${ARGN})
if(NOT DEFINED SELF_SCHEMA_DIR)
if(DEFINED ENV{CONDA_PREFIX})
set(SELF_SCHEMA_DIR $ENV{CONDA_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
else()
set(SELF_SCHEMA_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
endif()
endif()
unset(result)
foreach(filename ${SELF_SOURCES})
get_filename_component(dir ${filename} DIRECTORY)
get_filename_component(name ${filename} NAME_WE)
if(DEFINED SELF_SCHEMA_LINK_DIR)
set(path "${SELF_SCHEMA_LINK_DIR}/${SELF_NAMESPACE}/${filename}")
else()
set(path "${filename}")
endif()
set(target "${CMAKE_CURRENT_BINARY_DIR}/${dir}/${name}.${SELF_FILE_TYPE}")
if(DEFINED SELF_SCHEMA_DIR)
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${path})
endif()
set(depends ${ROQ_AUTOGEN})
if(SELF_DEPENDS)
list(APPEND depends ${SELF_DEPENDS})
endif(SELF_DEPENDS)
add_custom_command(
OUTPUT ${target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${ROQ_AUTOGEN} --schema_dir ${SELF_SCHEMA_DIR} --template_dir ${SELF_TEMPLATE_DIR} --input_path ${path}
--language ${SELF_LANGUAGE} --template_type ${SELF_TEMPLATE_TYPE} --file_type ${SELF_FILE_TYPE} > ${target}
COMMAND ${CLANG_FORMAT} -i ${target}
VERBATIM
DEPENDS ${depends} ${path})
list(APPEND result "${target}")
endforeach()
set(${SELF_OUTPUT}
${result}
PARENT_SCOPE)
endfunction()
function(roq_autogen_cpp)
set(SELF_LANGUAGE "cpp")
set(SELF_FILE_TYPE "cpp")
set(options DUMMY_OPTION)
set(one_value OUTPUT NAMESPACE SCHEMA_DIR SCHEMA_LINK_DIR TEMPLATE_DIR TEMPLATE_TYPE)
set(multi_value SOURCES DEPENDS)
cmake_parse_arguments(SELF "${options}" "${one_value}" "${multi_value}" ${ARGN})
if(NOT DEFINED SELF_SCHEMA_DIR)
if(DEFINED ENV{CONDA_PREFIX})
set(SELF_SCHEMA_DIR $ENV{CONDA_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
else()
set(SELF_SCHEMA_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
endif()
endif()
unset(result)
foreach(filename ${SELF_SOURCES})
get_filename_component(dir ${filename} DIRECTORY)
get_filename_component(name ${filename} NAME_WE)
if(DEFINED SELF_SCHEMA_LINK_DIR)
set(path "${SELF_SCHEMA_LINK_DIR}/${SELF_NAMESPACE}/${filename}")
else()
set(path "${filename}")
endif()
set(target "${CMAKE_CURRENT_BINARY_DIR}/${dir}/${name}.${SELF_FILE_TYPE}")
if(DEFINED SELF_SCHEMA_DIR)
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${path})
endif()
set(depends ${ROQ_AUTOGEN})
if(SELF_DEPENDS)
list(APPEND depends ${SELF_DEPENDS})
endif()
add_custom_command(
OUTPUT ${target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${ROQ_AUTOGEN} --schema_dir ${SELF_SCHEMA_DIR} --template_dir ${SELF_TEMPLATE_DIR} --input_path ${path}
--language ${SELF_LANGUAGE} --template_type ${SELF_TEMPLATE_TYPE} --file_type ${SELF_FILE_TYPE} > ${target}
COMMAND ${CLANG_FORMAT} -i ${target}
VERBATIM
DEPENDS ${depends} ${path})
list(APPEND result "${target}")
endforeach()
set(${SELF_OUTPUT}
${result}
PARENT_SCOPE)
endfunction()
function(roq_autogen_java)
set(SELF_LANGUAGE "java")
set(SELF_FILE_TYPE "java")
set(options DUMMY_OPTION)
set(one_value OUTPUT NAMESPACE SCHEMA_DIR SCHEMA_LINK_DIR TEMPLATE_DIR TEMPLATE_TYPE)
set(multi_value SOURCES DEPENDS)
cmake_parse_arguments(SELF "${options}" "${one_value}" "${multi_value}" ${ARGN})
if(NOT DEFINED SELF_SCHEMA_DIR)
if(DEFINED ENV{CONDA_PREFIX})
set(SELF_SCHEMA_DIR $ENV{CONDA_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
else()
set(SELF_SCHEMA_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
endif()
endif()
unset(result)
foreach(filename ${SELF_SOURCES})
get_filename_component(dir ${filename} DIRECTORY)
get_filename_component(name ${filename} NAME_WE)
if(DEFINED SELF_SCHEMA_LINK_DIR)
set(path "${SELF_SCHEMA_LINK_DIR}/${SELF_NAMESPACE}/${filename}")
else()
set(path "${filename}")
endif()
set(target "${CMAKE_CURRENT_BINARY_DIR}/${dir}/${name}.${SELF_FILE_TYPE}")
if(DEFINED SELF_SCHEMA_DIR)
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${path})
endif()
set(depends ${ROQ_AUTOGEN})
if(SELF_DEPENDS)
list(APPEND depends ${SELF_DEPENDS})
endif(SELF_DEPENDS)
add_custom_command(
OUTPUT ${target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${ROQ_AUTOGEN} --schema_dir ${SELF_SCHEMA_DIR} --template_dir ${SELF_TEMPLATE_DIR} --input_path ${path}
--language ${SELF_LANGUAGE} --template_type ${SELF_TEMPLATE_TYPE} --file_type ${SELF_FILE_TYPE} > ${target}
COMMAND ${CLANG_FORMAT} -i ${target}
VERBATIM
DEPENDS ${depends} ${path})
list(APPEND result "${target}")
endforeach()
set(${SELF_OUTPUT}
${result}
PARENT_SCOPE)
endfunction()
function(roq_autogen_rst)
set(SELF_LANGUAGE "cpp")
set(SELF_FILE_TYPE "rstinc")
set(options DUMMY_OPTION)
set(one_value OUTPUT NAMESPACE SCHEMA_DIR SCHEMA_LINK_DIR TEMPLATE_DIR TEMPLATE_TYPE)
set(multi_value SOURCES DEPENDS)
cmake_parse_arguments(SELF "${options}" "${one_value}" "${multi_value}" ${ARGN})
if(NOT DEFINED SELF_SCHEMA_DIR)
if(DEFINED ENV{CONDA_PREFIX})
set(SELF_SCHEMA_DIR $ENV{CONDA_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
else()
set(SELF_SCHEMA_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/roq/schema)
endif()
endif()
unset(result)
foreach(filename ${SELF_SOURCES})
get_filename_component(dir ${filename} DIRECTORY)
get_filename_component(name ${filename} NAME_WE)
if(DEFINED SELF_SCHEMA_LINK_DIR)
set(path "${SELF_SCHEMA_LINK_DIR}/${SELF_NAMESPACE}/${filename}")
else()
set(path "${filename}")
endif()
set(target "${CMAKE_CURRENT_BINARY_DIR}/${dir}/${name}.${SELF_FILE_TYPE}")
if(DEFINED SELF_SCHEMA_DIR)
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${path})
endif()
set(depends ${ROQ_AUTOGEN})
if(SELF_DEPENDS)
list(APPEND depends ${SELF_DEPENDS})
endif(SELF_DEPENDS)
# note! not using clang-format
add_custom_command(
OUTPUT ${target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${ROQ_AUTOGEN} --schema_dir ${SELF_SCHEMA_DIR} --template_dir ${SELF_TEMPLATE_DIR} --input_path ${path}
--language ${SELF_LANGUAGE} --template_type ${SELF_TEMPLATE_TYPE} --file_type ${SELF_FILE_TYPE} > ${target}
VERBATIM
DEPENDS ${depends} ${path})
list(APPEND result "${target}")
endforeach()
set(${SELF_OUTPUT}
${result}
PARENT_SCOPE)
endfunction()