|
212 | 212 |
|
213 | 213 | See the polymorph example, which uses this technique.
|
214 | 214 |
|
| 215 | +\psubsection{Using Classdesc: Method 3, inlining with CMake}\label{cmake-method} |
| 216 | + |
| 217 | +Using Makefiles is ideal, as it is possible to generate Makefile |
| 218 | +dependencies automatically from the source code, and to create the |
| 219 | +generated .cd files automatically via a Makefile rule. |
| 220 | + |
| 221 | +When using other systems, eg CMake, you will need to explicitly list |
| 222 | +the header files that need to be generated by classdesc. An example |
| 223 | +CMake function that is useful for this purpose is: |
| 224 | + |
| 225 | +\begin{verbatim} |
| 226 | +function(classdesc) |
| 227 | + foreach(header ${ARGV}) |
| 228 | + get_filename_component(stem ${header} NAME_WLE) |
| 229 | + set(source ${CMAKE_CURRENT_SOURCE_DIR}/${stem}.h) |
| 230 | + set(dest ${stem}.cd) |
| 231 | + add_custom_command(OUTPUT ${dest} MAIN_DEPENDENCY ${source} COMMAND ${CLASSDESC} -respect_private -typeName -i ${source} ParserSerialise ParserDeserialise >${dest}) |
| 232 | + set(HEADERS ${HEADERS} ${stem}.cd) |
| 233 | + include_directories(SYSTEM ${CMAKE_CURRENT_BINARY_DIR}) |
| 234 | + endforeach() |
| 235 | +endfunction() |
| 236 | +include_directories(SYSTEM ${CMAKE_BINARY_DIR}) |
| 237 | +\end{verbatim} |
| 238 | + |
| 239 | +Within each project's CMakeLists.txt file, simply declare the header |
| 240 | +files needing to be processed via a CLASSDESC line, eg |
| 241 | +\begin{verbatim} |
| 242 | +CLASSDESC(foo.h bla.h) |
| 243 | +\end{verbatim} |
| 244 | + |
| 245 | +The .cd files are placed within the build directory, in a tree |
| 246 | +hierarchy corresponding to where the source header files. So if foo.h |
| 247 | +is found in \verb+include/somelib/foo.h+, the .cd is placed in the build |
| 248 | +directory (aka \verb+CMAKE_BINARY_DIR+) under |
| 249 | +\verb+include/somelib/foo.cd+. The last \verb+include_directories+ |
| 250 | +ensures that the cd file can be found via |
| 251 | +\begin{verbatim} |
| 252 | +#include "include/somelib/foo.cd" |
| 253 | +\end{verbatim} |
| 254 | + |
| 255 | +The above function, which is run at cmake time, creates a single rule |
| 256 | +dependency for every header file mentioned, such that alterations to |
| 257 | +the source header file will cause the .cd file to be rebuilt, a |
| 258 | +consequently the object file that includes it via being added the the |
| 259 | +\verb+HEADERS+ special variable. |
| 260 | + |
| 261 | +Classdesc has been used with other build systems too, such a Visual Studio. |
| 262 | +The strategy there is to create a separate project which all others |
| 263 | +in the solution depend on. Thus all .cd files are regenerated at the start |
| 264 | +of the run if any dependent header file is changed. This is a little |
| 265 | +wasteful, but the classdesc preprocessor is generally so quick that it |
| 266 | +doesn't impact compile times much. |
| 267 | + |
215 | 268 | \psubsection{Synopsis of classdesc}
|
216 | 269 |
|
217 | 270 | \begin{description}
|
|
0 commit comments