Skip to content

Commit a0e82e6

Browse files
committed
Add spdlog demo app example
1 parent 5cca6a9 commit a0e82e6

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

app/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include(FetchContent)
22

3+
34
FetchContent_Declare(
45
spdlog
56
URL https://github.com/gabime/spdlog/archive/refs/tags/v1.15.3.zip
@@ -8,9 +9,17 @@ FetchContent_Declare(
89

910
FetchContent_MakeAvailable(spdlog)
1011

11-
1212
add_executable(${PROJECT_NAME}_app main.cpp)
13-
target_link_libraries(${PROJECT_NAME}_app PRIVATE ${PROJECT_NAME}::library)
13+
14+
target_link_libraries(${PROJECT_NAME}_app
15+
PRIVATE ${PROJECT_NAME}::library spdlog::spdlog
16+
)
17+
18+
# mark spdlog headers as system includes to avoid warnings (-Werror)
19+
get_target_property(_spdlog_includes spdlog::spdlog INTERFACE_INCLUDE_DIRECTORIES)
20+
target_include_directories(${PROJECT_NAME}_app
21+
SYSTEM PRIVATE ${_spdlog_includes}
22+
)
1423

1524
enable_strict_warnings(${PROJECT_NAME}_app)
1625
enable_sanitizers(${PROJECT_NAME}_app)

app/main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1+
#include <spdlog/sinks/basic_file_sink.h>
2+
#include <spdlog/sinks/stdout_color_sinks.h>
3+
#include <spdlog/spdlog.h>
4+
15
#include <iostream>
26

37
#include "modern_cpp/library.hpp"
48

59
int main() {
10+
auto console = spdlog::stdout_color_mt("console");
11+
spdlog::set_level(spdlog::level::debug);
12+
613
const int left = 10;
714
const int right = 4;
815

9-
std::cout << "Add: " << modern_cpp::add(left, right) << '\n';
10-
std::cout << "Subtract: " << modern_cpp::subtract(left, right) << '\n';
16+
console->info("Calling add({}, {})", left, right);
17+
const int sum = modern_cpp::add(left, right);
18+
console->info("Result of add: {}", sum);
19+
20+
console->info("Calling subtract({}, {})", left, right);
21+
const int diff = modern_cpp::subtract(left, right);
22+
console->info("Result of subtract: {}", diff);
1123

1224
return 0;
1325
}

0 commit comments

Comments
 (0)