Skip to content

Commit 4dfd95d

Browse files
committed
Refactor CMakeLists.txt to improve logging level handling
Updated the logic for setting default log levels based on the build type. Removed redundant checks and streamlined the configuration for log levels, ensuring appropriate defaults are set for both Debug and Release builds. This enhances clarity and maintainability of the build configuration.
1 parent bf3e721 commit 4dfd95d

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ else()
4141
message(FATAL_ERROR "unsupported operating system ${CMAKE_SYSTEM_NAME}")
4242
endif()
4343

44-
if(NOT CMAKE_BUILD_TYPE)
45-
set(CMAKE_BUILD_TYPE Release)
46-
47-
if(LOG_LEVEL STREQUAL "NONE")
48-
set(LOG_LEVEL INFO)
49-
endif()
50-
elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug")
51-
if(LOG_LEVEL STREQUAL "NONE")
52-
set(LOG_LEVEL DEBUG)
53-
endif()
54-
else()
55-
set(LOG_LEVEL INFO)
56-
endif()
57-
5844
configure_file(libCacheSim/include/config.h.in libCacheSim/include/config.h)
5945

6046
if(SUPPORT_TTL)
@@ -67,7 +53,15 @@ endif()
6753

6854
string(TOLOWER "${LOG_LEVEL}" LOG_LEVEL_LOWER)
6955

70-
if(LOG_LEVEL_LOWER STREQUAL "verbose")
56+
if(LOG_LEVEL_LOWER STREQUAL "")
57+
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
58+
message(STATUS "LOG_LEVEL is not set, use DEBUG as default for debug build")
59+
add_compile_definitions(LOGLEVEL=6)
60+
else()
61+
message(STATUS "LOG_LEVEL is not set, use INFO as default for release build")
62+
add_compile_definitions(LOGLEVEL=7)
63+
endif()
64+
elseif(LOG_LEVEL_LOWER STREQUAL "verbose")
7165
add_compile_definitions(LOGLEVEL=5)
7266
elseif(LOG_LEVEL_LOWER STREQUAL "debug")
7367
add_compile_definitions(LOGLEVEL=6)
@@ -77,15 +71,18 @@ elseif(LOG_LEVEL_LOWER STREQUAL "warn")
7771
add_compile_definitions(LOGLEVEL=8)
7872
elseif(LOG_LEVEL_LOWER STREQUAL "error")
7973
add_compile_definitions(LOGLEVEL=9)
80-
81-
# default none is info
82-
elseif(LOG_LEVEL_LOWER STREQUAL "none")
83-
add_compile_definitions(LOGLEVEL=7)
8474
else()
8575
message(WARNING "unknown log level ${LOG_LEVEL}, use INFO as default")
8676
add_compile_definitions(LOGLEVEL=7)
8777
endif()
8878

79+
80+
if(NOT CMAKE_BUILD_TYPE)
81+
# we can also consider RelWithDebInfo, but it will be too slow for release build
82+
set(CMAKE_BUILD_TYPE Release)
83+
endif()
84+
85+
8986
# Define shared compiler flags for all targets
9087
set(LIBCACHESIM_C_FLAGS
9188
-Wall -Wextra -Werror

0 commit comments

Comments
 (0)