@@ -22,6 +22,16 @@ endif()
22
22
23
23
message ("CMAKE_CXX_COMPILER_VERSION: " ${CMAKE_CXX_COMPILER_VERSION} )
24
24
25
+ option (ENABLE_JSON "enable the json example with nlohmann library" OFF )
26
+ option (ENABLE_CSV "enable the csv example with fast-cpp-csv-parser library" ON )
27
+ option (ENABLE_YAML "enable the yaml example with yaml-cpp" ON )
28
+ option (ENABLE_BENCHMARKING "enable the code benchmarking with Goolge benchmarking" OFF )
29
+ option (ENABLE_TRACY "enable the code profiling with tracy" OFF )
30
+ option (ENABLE_XML "enable the xml example with tinyxml2" ON )
31
+ option (ENABLE_TESTING "Enable testing" OFF )
32
+ option (ENABLE_SANITIZE "Add sanitizer flags" OFF )
33
+
34
+
25
35
add_executable (pointers src/pointers/pointers.cpp)
26
36
27
37
add_executable (string src/string .cpp )
@@ -218,10 +228,6 @@ add_executable(forward src/forward.cpp)
218
228
219
229
add_executable (virtual_destructor_virtual_constructor src/class/virtual_destructor_virtual_constructor.cpp)
220
230
221
- #add_executable(csv_reading_example src/third_party_tools/csv/fast-cpp-csv-parser/csv_reading_example.cpp)
222
-
223
- add_executable (json_example src/third_party_tools/jason/nlohmann/json_example.cpp)
224
-
225
231
add_executable (header_guard src/class/header_guard/main.cpp)
226
232
227
233
add_executable (optimizing_cpp src/optimizing_cpp/index.cpp)
@@ -253,6 +259,11 @@ add_executable(heap_and_stack_memory_layout_of_C_programs src/heap_and_stack_mem
253
259
254
260
# target_compile_options(heap_and_stack_memory_layout_of_C_programs PRIVATE -Wall -Wextra -g -O0)
255
261
262
+
263
+ if (ENABLED_SANITIZE)
264
+ set (CMAKE_CXX_FLAGS "-fsanitize=address ${CMAKE_CXX_FLAGS} " )
265
+ set (CMAKE_CXX_FLAGS "-fno-omit-frame-pointer ${CMAKE_CXX_FLAGS} " )
266
+ endif ()
256
267
# set(CMAKE_CXX_FLAGS "-fsanitize=address ${CMAKE_CXX_FLAGS}")
257
268
# set(CMAKE_CXX_FLAGS "-fno-omit-frame-pointer ${CMAKE_CXX_FLAGS}")
258
269
add_executable (memory_checking src/memory_checking.cpp)
@@ -294,24 +305,13 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND ${CMAKE_CXX_COMPILER_VERSION} G
294
305
add_executable (printing_with_format src/printing_with_format.cpp)
295
306
endif ()
296
307
297
- find_package (PkgConfig)
298
308
299
- if (EXISTS "$ENV{HOME} /usr/lib/pkgconfig" )
300
- set (ENV{PKG_CONFIG_PATH} "$ENV{HOME} /usr/lib/pkgconfig:" $ENV{PKG_CONFIG_PATH} )
301
- endif ()
302
309
303
- message ("PKG_CONFIG_PATH:" $ENV{PKG_CONFIG_PATH} )
304
310
305
311
306
- option (TESTING "Enable testing" OFF )
307
312
308
- if (testing_enabled)
309
- add_subdirectory (tests)
310
- endif ()
311
313
312
314
313
- option (SANITIZE "Add sanitizer flags" OFF )
314
-
315
315
316
316
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
317
317
add_library (add SHARED src/add.cpp)
@@ -328,10 +328,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
328
328
329
329
endif ()
330
330
331
- if (SANITIZE)
332
- set (CMAKE_CXX_FLAGS "-fsanitize=address ${CMAKE_CXX_FLAGS} " )
333
- set (CMAKE_CXX_FLAGS "-fno-omit-frame-pointer ${CMAKE_CXX_FLAGS} " )
334
- endif (SANITIZE)
331
+
335
332
336
333
337
334
@@ -350,148 +347,190 @@ endif()
350
347
351
348
352
349
353
- message ("\n ########################################## tinyxml2 ##########################################\n " )
354
350
355
- #pkg_check_modules(TINYXML2 tinyxml2)
356
- ##find_package(TinyXML2 )
357
-
358
- include (FetchContent)
359
- FetchContent_Declare (tinyxml2
360
- GIT_REPOSITORY https://github.com/leethomason/tinyxml2
361
- GIT_TAG master
362
- GIT_SHALLOW TRUE
363
- GIT_PROGRESS TRUE )
351
+ if (ENABLED_TESTING)
352
+ add_subdirectory (tests)
353
+ else ()
354
+ message ("testing is not enabled" )
355
+ endif ()
364
356
365
- FetchContent_MakeAvailable(tinyxml2)
357
+ if (ENABLE_XML)
358
+ message ("\n ########################################## tinyxml2 ##########################################\n " )
359
+
360
+ include (FetchContent)
361
+
362
+ FetchContent_Declare(
363
+ tinyxml2
364
+ GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
365
+ GIT_TAG master
366
+ GIT_SHALLOW TRUE
367
+ GIT_PROGRESS TRUE
368
+ )
369
+
370
+ FetchContent_MakeAvailable(tinyxml2)
366
371
372
+ message ("TINYXML2_FOUND: ${TINYXML2_FOUND} " )
373
+ message ("TINYXML2_VERSION: ${TINYXML2_VERSION} " )
374
+ message ("TINYXML2_LIBRARIES: ${TINYXML2_LIBRARIES} " )
375
+ message ("TINYXML2_INCLUDE_DIRS: ${TINYXML2_INCLUDE_DIRS} " )
376
+ message ("TINYXML2_LIBRARY_DIRS: ${TINYXML2_LIBRARY_DIRS} " )
367
377
368
- if (${TINYXML2_FOUND} )
369
- message ("TINYXML2_FOUND:" ${TINYXML2_FOUND} )
370
- message ("TINYXML2_VERSION:" ${TINYXML2_VERSION} )
371
- message ("TINYXML2_LIBRARIES:" ${TINYXML2_LIBRARIES} )
372
- message ("TINYXML2_INCLUDE_DIRS:" ${TINYXML2_INCLUDE_DIRS} )
373
- message ("TINYXML2_LIBRARY_DIRS:" ${TINYXML2_LIBRARY_DIRS} )
374
378
include_directories (${TINYXML2_INCLUDE_DIRS} )
375
379
link_directories (${TINYXML2_LIBRARY_DIRS} )
376
- add_executable (tinyxml2_demo src/third_party_tools/xml/tinyxml2/tinyxml2_demo.cpp)
377
- target_link_libraries (tinyxml2_demo ${TINYXML2_LIBRARIES} )
380
+
381
+ add_executable (tinyxml2_demo src/tinyxml2_demo.cpp)
382
+ target_link_libraries (tinyxml2_demo tinyxml2)
383
+
378
384
else ()
379
- message ("tinyxml2 not found " )
385
+ message ("XML is not enabled " )
380
386
endif ()
381
387
382
- message ("\n ########################################## yaml-cpp ##########################################\n " )
383
-
384
388
385
- FetchContent_Declare(
386
- yaml-cpp
387
- GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
388
- GIT_TAG master # Can be a tag (yaml-cpp-x.x.x), a commit hash, or a branch name (master)
389
- )
390
- FetchContent_GetProperties(yaml-cpp)
389
+ if (ENABLE_YAML)
390
+ message ("\n ########################################## yaml-cpp ##########################################\n " )
391
391
392
- if (NOT yaml-cpp_POPULATED)
393
- message (STATUS "Fetching yaml-cpp..." )
394
- FetchContent_Populate(yaml-cpp)
395
- add_subdirectory (${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR })
396
- endif ()
392
+ FetchContent_Declare(
393
+ yaml-cpp
394
+ GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
395
+ GIT_TAG master # Can be a tag (yaml-cpp-x.x.x), a commit hash, or a branch name (master)
396
+ )
397
+ FetchContent_GetProperties(yaml-cpp)
397
398
398
- FetchContent_MakeAvailable(yaml-cpp)
399
+ if (NOT yaml-cpp_POPULATED)
400
+ message (STATUS "Fetching yaml-cpp..." )
401
+ FetchContent_Populate(yaml-cpp)
402
+ add_subdirectory (${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR })
403
+ endif ()
399
404
405
+ FetchContent_MakeAvailable(yaml-cpp)
406
+ FetchContent_GetProperties(yaml-cpp)
400
407
401
- # set(yaml-cpp_DIR "$ENV{HOME}/usr/share/cmake/yaml-cpp")
402
- # find_package(yaml-cpp)
403
408
404
- if (${yaml-cpp_FOUND})
405
409
message ("yaml-cpp_FOUND:" ${yaml-cpp_FOUND})
406
410
message ("yaml-cpp_VERSION:" ${yaml-cpp_VERSION})
407
- add_executable (yaml-cpp_example src/third_party_tools/yaml/yaml-cpp/ yaml-cpp_example.cpp)
411
+ add_executable (yaml-cpp_example src/yaml-cpp_example.cpp)
408
412
target_link_libraries (yaml-cpp_example yaml-cpp)
413
+ else ()
414
+ message ("yaml is not enabled" )
409
415
endif ()
410
416
411
417
412
- message ("\n ########################################## Google benchmark ##########################################\n " )
413
-
414
418
419
+ if (ENABLE_BENCHMARKING)
420
+ message ("\n ########################################## Google benchmark ##########################################\n " )
415
421
416
- FetchContent_Declare(
417
- benchmark
418
- GIT_REPOSITORY https://github.com/google/benchmark
419
- GIT_TAG main # Can be a tag (yaml-cpp-x.x.x), a commit hash, or a branch name (master)
420
- )
421
- set (BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
422
+ FetchContent_Declare(
423
+ benchmark
424
+ GIT_REPOSITORY https://github.com/google/benchmark
425
+ GIT_TAG main # Can be a tag (yaml-cpp-x.x.x), a commit hash, or a branch name (master)
426
+ )
427
+ set (BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
428
+ FetchContent_GetProperties(benchmark)
422
429
430
+ if (NOT benchmark_POPULATED)
431
+ message (STATUS "Fetching benchmark..." )
432
+ FetchContent_Populate(benchmark)
433
+ add_subdirectory (${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} )
434
+ endif ()
423
435
424
- FetchContent_GetProperties(benchmark)
425
-
426
- if (NOT benchmark_POPULATED)
427
- message (STATUS "Fetching benchmark..." )
428
- FetchContent_Populate(benchmark)
429
- add_subdirectory (${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} )
430
- endif ()
431
-
432
- FetchContent_MakeAvailable(benchmark)
433
-
434
- #pkg_check_modules(BENCHMARK benchmark)
435
-
436
- if (${BENCHMARK_FOUND} )
437
436
message ("BENCHMARK_FOUND:" ${BENCHMARK_FOUND} )
438
437
message ("BENCHMARK_VERSION:" ${BENCHMARK_VERSION} )
439
438
message ("BENCHMARK_LIBRARIES:" ${BENCHMARK_LIBRARIES} )
440
439
message ("BENCHMARK_INCLUDE_DIRS:" ${BENCHMARK_INCLUDE_DIRS} )
441
440
message ("BENCHMARK_LIBRARY_DIRS:" ${BENCHMARK_LIBRARY_DIRS} )
442
- include_directories (${TINYXML2_INCLUDE_DIRS} )
443
- link_directories (${TINYXML2_LIBRARY_DIRS} )
444
- #add_executable(benchmark_demo src/third_party_tools/benchmark/benchmark_demo.cpp)
445
- #target_link_libraries(benchmark_demo ${BENCHMARK_LIBRARIES} pthread)
441
+
442
+ include_directories (${BENCHMARK_INCLUDE_DIRS} ) # Corrected to use benchmark include directories
443
+ link_directories (${BENCHMARK_LIBRARY_DIRS} ) # Corrected to use benchmark library directories
444
+ add_executable (benchmark_demo src/benchmark_demo.cpp)
445
+ target_link_libraries (benchmark_demo ${BENCHMARK_LIBRARIES} pthread)
446
+ else ()
447
+ message ("Benchmarking is not enabled" )
446
448
endif ()
447
449
448
450
449
451
450
- message ("\n ########################################## json ##########################################\n " )
452
+ if (ENABLE_JSON)
453
+ message ("\n ########################################## json ##########################################\n " )
451
454
455
+ FetchContent_Declare(
456
+ json
457
+ GIT_REPOSITORY https://github.com/nlohmann/json
458
+ GIT_TAG master
459
+ GIT_SHALLOW TRUE
460
+ GIT_PROGRESS TRUE
461
+ )
452
462
463
+ FetchContent_MakeAvailable(json)
453
464
454
- include (FetchContent)
455
- FetchContent_Declare (json
456
- GIT_REPOSITORY https://github.com/nlohmann/json
457
- GIT_TAG master
458
- GIT_SHALLOW TRUE
459
- GIT_PROGRESS TRUE )
465
+ add_executable (json_example src/json_example.cpp)
466
+
467
+ # Define a macro CMAKE_CURRENT_SOURCE_DIR with the value of CMAKE_CURRENT_SOURCE_DIR
468
+ target_compile_definitions (json_example PRIVATE CMAKE_CURRENT_SOURCE_DIR ="${CMAKE_CURRENT_SOURCE_DIR} " )
469
+
470
+ # Include the nlohmann/json directory
471
+ target_include_directories (json_example PRIVATE ${json_SOURCE_DIR} )
460
472
461
- FetchContent_MakeAvailable(json)
462
473
474
+ else ()
475
+ message ("json is not enabled" )
476
+ endif ()
463
477
464
- message ("\n ########################################## tracy ##########################################\n " )
465
478
466
479
467
480
468
- include (FetchContent)
469
- FetchContent_Declare (tracy
470
- GIT_REPOSITORY https://github.com/wolfpld/tracy.git
471
- GIT_TAG v0.11.0
472
- GIT_SHALLOW TRUE
473
- GIT_PROGRESS TRUE )
474
481
475
- FetchContent_MakeAvailable(tracy)
482
+
483
+ if (ENABLE_TRACY)
484
+ message ("\n ########################################## tracy ##########################################\n " )
485
+ include (FetchContent)
486
+ FetchContent_Declare (tracy
487
+ GIT_REPOSITORY https://github.com/wolfpld/tracy.git
488
+ GIT_TAG v0.11.0
489
+ GIT_SHALLOW TRUE
490
+ GIT_PROGRESS TRUE )
491
+
492
+ FetchContent_MakeAvailable(tracy)
493
+
476
494
477
495
496
+ FetchContent_GetProperties(tracy)
497
+ # if(NOT tracy_POPULATED)
498
+ # # FetchContent_Populate(tracy)
499
+ # # add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
500
+ # message("-------------------")
501
+ # else()
502
+ # message("++++++++++++++++")
503
+ # endif()
478
504
479
- FetchContent_GetProperties(tracy)
480
- if (NOT tracy_POPULATED)
481
- # FetchContent_Populate(tracy)
482
- # add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
483
505
484
- message ("-------------------" )
506
+ add_executable (tracy_profile src/tracy_profile.cpp)
507
+ target_link_libraries ( tracy_profile PUBLIC TracyClient )
508
+
485
509
else ()
486
- message ("++++++++++++++++ " )
510
+ message ("tracy is not enabled " )
487
511
endif ()
488
512
489
513
514
+ if (ENABLE_CSV)
515
+ message ("\n ########################################## fast-cpp-csv-parser ##########################################\n " )
516
+ include (FetchContent)
517
+ FetchContent_Declare (fast-cpp-csv-parser
518
+ GIT_REPOSITORY https://github.com/ben-strasser/fast-cpp-csv-parser
519
+ GIT_TAG master
520
+ GIT_SHALLOW TRUE
521
+ GIT_PROGRESS TRUE )
522
+
523
+ FetchContent_MakeAvailable(fast-cpp-csv-parser)
524
+ FetchContent_GetProperties(fast-cpp-csv-parser)
490
525
491
- add_executable (tracy_profile src/tracy_profile.cpp)
492
- target_link_libraries ( tracy_profile PUBLIC TracyClient )
526
+ add_executable (csv_reading_example src/csv_reading_example.cpp)
527
+ target_compile_definitions (csv_reading_example PRIVATE CMAKE_CURRENT_SOURCE_DIR ="${CMAKE_CURRENT_SOURCE_DIR} " )
528
+ target_include_directories (csv_reading_example PRIVATE ${fast-cpp-csv-parser_SOURCE_DIR})
493
529
530
+ else ()
531
+ message ("fast-cpp-csv-parser is not enabled" )
494
532
533
+ endif ()
495
534
496
535
497
536
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /src/main.cpp" )
0 commit comments