@@ -28,6 +28,10 @@ Key points:
28
28
- [ 20+ Manipulators to change the display style] ( #20-manipulators-to-change-the-display-style )
29
29
- [ Requirement] ( #requirement )
30
30
- [ Installation] ( #installation )
31
+ - [ Simplest solution] ( #simplest-solution )
32
+ - [ With CMake] ( #with-cmake )
33
+ - [ Run ` cmake --install ` to copy the headers to ` /usr/local/include/ ` or equivalent] ( #run-cmake---install-to-copy-the-headers-to-usrlocalinclude-or-equivalent )
34
+ - [ Use ` FetchContent ` ] ( #use-fetchcontent )
31
35
- [ Configuration (as needed)] ( #configuration-as-needed )
32
36
- [ Configuration options] ( #configuration-options )
33
37
- [ ` max_line_width ` ] ( #max_line_width )
@@ -225,53 +229,107 @@ See [Formatting with manipulators](#formatting-with-manipulators) for details.
225
229
226
230
## Installation
227
231
232
+ ### Simplest solution
233
+
228
234
```shell
229
235
git clone https://github.com/philip82148/cpp-dump
230
236
```
231
237
232
238
Then
233
239
234
240
``` cpp
235
- #include " path/to/cpp-dump/dump.hpp"
241
+ #include " path/to/cpp-dump/cpp-dump.hpp"
242
+ ```
243
+
244
+ ### With CMake
245
+
246
+ #### Run ` cmake --install ` to copy the headers to ` /usr/local/include/ ` or equivalent
247
+
248
+ ``` shell
249
+ git clone https://github.com/philip82148/cpp-dump
250
+ cd cpp-dump
251
+ cmake -S . -B build # No configuration is needed because the library is header-only.
252
+ sudo cmake --install build
253
+ # (The 'cpp-dump' folder can be removed after this.)
254
+ ```
255
+
256
+ Then
257
+
258
+ ``` cpp
259
+ #include < cpp-dump.hpp>
260
+ ```
261
+
262
+ #### Use ` FetchContent `
263
+
264
+ ` CMakeLists.txt `
265
+
266
+ ``` cmake
267
+ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json (optional)
268
+
269
+ include(FetchContent)
270
+
271
+ # Fetch cpp-dump
272
+ FetchContent_Declare(cpp-dump
273
+ GIT_REPOSITORY https://github.com/philip82148/cpp-dump
274
+ GIT_TAG main
275
+ )
276
+ FetchContent_MakeAvailable(cpp-dump)
277
+
278
+ # Link cpp-dump to your app
279
+ target_link_libraries(MyApp PRIVATE cpp-dump)
280
+ ```
281
+
282
+ Then
283
+
284
+ ``` cpp
285
+ #include < cpp-dump.hpp>
236
286
```
237
287
238
288
## Configuration (as needed)
239
289
240
- If you want to customize the library, use the ` CPP_DUMP_SET_OPTION_GLOBAL() ` macro:
290
+ If you want to customize the library, you can write the configuration code as follows:
291
+
292
+ ` custom-cpp-dump.hpp `
241
293
242
294
``` cpp
243
- // You can also write this in a header file -----------------------------------
244
295
#ifdef DEBUGGING
245
- #include "path/to/cpp-dump/dump.hpp"
296
+ #include "path/to/cpp-dump/cpp- dump.hpp"
246
297
namespace cp = cpp_dump;
298
+ // You can use this in both a header file and a source file,
299
+ // but make sure not to use it more than once for the same option.
247
300
CPP_DUMP_SET_OPTION_GLOBAL(max_line_width, 100);
301
+
302
+ // To ensure proper instantiation of templates,
303
+ // include these in at least one translation unit where cpp_dump(...) prints each type.
304
+ // One way is to write them in a header file and then include it wherever needed.
305
+ CPP_DUMP_DEFINE_EXPORT_ENUM(my_enum, my_enum::a, my_enum::b, my_enum::c);
306
+ CPP_DUMP_DEFINE_EXPORT_OBJECT(my_class, member1, member2());
307
+ CPP_DUMP_DEFINE_EXPORT_OBJECT_GENERIC(member3, member4());
248
308
#else
249
309
#define cpp_dump(...)
310
+ #define CPP_DUMP_SET_OPTION(...)
250
311
#endif
251
- // You can also write this in a header file -----------------------------------
312
+ ```
313
+
314
+ ` main.cpp `
315
+
316
+ ``` cpp
317
+ #include " path/to/custom-cpp-dump.hpp"
252
318
253
319
int main () {
254
- // To be continued...
320
+ cpp_dump (vec | cp::back());
255
321
}
256
322
```
257
323
258
324
If you want to configure the library within a function, use ` CPP_DUMP_SET_OPTION() ` instead.
259
325
260
326
``` cpp
261
- // You can also write this in a header file -----------------------------------
262
- #ifdef DEBUGGING
263
- #include "path/to/cpp-dump/dump.hpp"
264
- namespace cp = cpp_dump;
265
- #else
266
- #define cpp_dump(...)
267
- #define CPP_DUMP_SET_OPTION(...)
268
- #endif
269
- // You can also write this in a header file -----------------------------------
327
+ #include " path/to/custom-cpp-dump.hpp"
270
328
271
- int main () {
272
- CPP_DUMP_SET_OPTION (max_line_width, 100 );
273
-
274
- // To be continued...
329
+ void func () {
330
+ CPP_DUMP_SET_OPTION (print_expr, false );
331
+ cpp_dump (vec | cp::back());
332
+ CPP_DUMP_SET_OPTION (print_expr, true);
275
333
}
276
334
```
277
335
@@ -1003,7 +1061,7 @@ inline void cpp_dump::write_log(std::string_view output) {
1003
1061
1004
1062
```cpp
1005
1063
#ifdef DEFINED_ONLY_IN_LOCAL
1006
- #include "./cpp-dump/dump.hpp"
1064
+ #include "./cpp-dump/cpp- dump.hpp"
1007
1065
#define dump(...) cpp_dump(__VA_ARGS__)
1008
1066
namespace cp = cpp_dump;
1009
1067
CPP_DUMP_SET_OPTION_GLOBAL(max_line_width, 80);
0 commit comments