Skip to content

Commit 63620c8

Browse files
authored
Adds CMake variable to configure compile time log levels. (#1733)
* Adds cmake variable PCAPPP_LOG_LEVEL to determine compile time log level through cmake. * Added checks for log level input. * Lint?
1 parent a78cdc6 commit 63620c8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ if(PCAPPP_USE_SANITIZER)
8585
endif()
8686
endif()
8787

88+
# Build options (Compile time log level)
89+
set(
90+
PCAPP_ALLOWED_LOG_LEVELS
91+
""
92+
"0"
93+
"1"
94+
"2"
95+
"3"
96+
)
97+
set(
98+
PCAPPP_LOG_LEVEL
99+
""
100+
CACHE STRING
101+
"Compile time log level (0 - Off, 1 - Error, 2 - Info, 3 - Debug) Default(empty): Debug"
102+
)
103+
set_property(CACHE PCAPPP_LOG_LEVEL PROPERTY STRINGS ${PCAPP_ALLOWED_LOG_LEVELS})
104+
105+
if(NOT PCAPPP_LOG_LEVEL IN_LIST PCAPP_ALLOWED_LOG_LEVELS)
106+
message(FATAL_ERROR "PCAPPP_LOG_LEVEL must be one of ${PCAPP_ALLOWED_LOG_LEVELS}")
107+
endif()
108+
109+
if(PCAPPP_LOG_LEVEL)
110+
add_compile_definitions("PCPP_ACTIVE_LOG_LEVEL=${PCAPPP_LOG_LEVEL}")
111+
endif()
112+
88113
# Build options (Turn on Examples and Tests if it's the main project)
89114
option(PCAPPP_BUILD_EXAMPLES "Build Examples" ${PCAPPP_MAIN_PROJECT})
90115
cmake_dependent_option(

0 commit comments

Comments
 (0)