Skip to content

Commit 31f6a05

Browse files
authored
Added Warn level to cmake compile time log level settings. (#1918)
* Added Warn level to cmake compile time log level settings. * Added named constants to simplify the cmake interface. * Lint
1 parent 6dbd740 commit 31f6a05

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

CMakeLists.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,18 @@ set(
9393
"1"
9494
"2"
9595
"3"
96+
"4"
97+
"Off"
98+
"Error"
99+
"Warn"
100+
"Info"
101+
"Debug"
96102
)
97103
set(
98104
PCAPPP_LOG_LEVEL
99105
""
100106
CACHE STRING
101-
"Compile time log level (0 - Off, 1 - Error, 2 - Info, 3 - Debug) Default(empty): Debug"
107+
"Compile time log level (0 - Off, 1 - Error, 2 - Warn, 3 - Info, 4 - Debug) Default(empty): Debug"
102108
)
103109
set_property(CACHE PCAPPP_LOG_LEVEL PROPERTY STRINGS ${PCAPP_ALLOWED_LOG_LEVELS})
104110

@@ -107,7 +113,23 @@ if(NOT PCAPPP_LOG_LEVEL IN_LIST PCAPP_ALLOWED_LOG_LEVELS)
107113
endif()
108114

109115
if(PCAPPP_LOG_LEVEL)
110-
add_compile_definitions("PCPP_ACTIVE_LOG_LEVEL=${PCAPPP_LOG_LEVEL}")
116+
if(PCAPPP_LOG_LEVEL STREQUAL "0" OR PCAPPP_LOG_LEVEL STREQUAL "Off")
117+
set(PCAPPP_LOG_LEVEL_VALUE "PCPP_LOG_LEVEL_OFF")
118+
elseif(PCAPPP_LOG_LEVEL STREQUAL "1" OR PCAPPP_LOG_LEVEL STREQUAL "Error")
119+
set(PCAPPP_LOG_LEVEL_VALUE "PCPP_LOG_LEVEL_ERROR")
120+
elseif(PCAPPP_LOG_LEVEL STREQUAL "2" OR PCAPPP_LOG_LEVEL STREQUAL "Warn")
121+
set(PCAPPP_LOG_LEVEL_VALUE "PCPP_LOG_LEVEL_WARN")
122+
elseif(PCAPPP_LOG_LEVEL STREQUAL "3" OR PCAPPP_LOG_LEVEL STREQUAL "Info")
123+
set(PCAPPP_LOG_LEVEL_VALUE "PCPP_LOG_LEVEL_INFO")
124+
elseif(PCAPPP_LOG_LEVEL STREQUAL "4" OR PCAPPP_LOG_LEVEL STREQUAL "Debug")
125+
set(PCAPPP_LOG_LEVEL_VALUE "PCPP_LOG_LEVEL_DEBUG")
126+
endif()
127+
128+
message(
129+
STATUS
130+
"Compile time logging verbocity has been set to level \"${PCAPPP_LOG_LEVEL_VALUE}\". All messages below this level will be pruned."
131+
)
132+
add_compile_definitions("PCPP_ACTIVE_LOG_LEVEL=${PCAPPP_LOG_LEVEL_VALUE}")
111133
endif()
112134

113135
# Build options (Turn on Examples and Tests if it's the main project)

0 commit comments

Comments
 (0)