Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 88efee0

Browse files
Add CMake option for Cortex code quality assurance (#2085)
Co-authored-by: vansangpfiev <vansangpfiev@gmail.com>
1 parent ae5bfa8 commit 88efee0

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

engine/CMakeLists.txt

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ set(CMAKE_CXX_EXTENSIONS OFF)
2222
set(OPENSSL_USE_STATIC_LIBS TRUE)
2323
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
2424

25+
# Add CORTEX_CQA option
26+
# Enabling this option will currently break the build.
27+
# Only for debugging
28+
option(CORTEX_CQA "Enable Cortex Code Quality Assurance(DO NOT TURN THIS ON unless you know what you are doing)" OFF)
29+
30+
if(CORTEX_CQA)
31+
message(STATUS "CORTEX_CQA is ON: Enabling debug symbols, ASan, All Warnings, and treating Warnings as Errors")
32+
33+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
34+
add_compile_options(-fsanitize=address -Wall -Wextra -Wpedantic -Werror -g)
35+
add_link_options(-fsanitize=address)
36+
elseif(MSVC)
37+
# TODO: Sang, test on Windows and setup MSVC accordingly
38+
add_compile_options(/INFERASAN /Wall /WX /Zi)
39+
add_link_options(/DEBUG)
40+
message(WARNING "Address Sanitizer might require additional setup on MSVC. Please refer to MSVC documentation for ASan.")
41+
else()
42+
message(WARNING "Address Sanitizer and warning flags are not automatically configured for this compiler. Please configure them manually if supported.")
43+
endif()
44+
else()
45+
message(STATUS "CORTEX_CQA is OFF.")
46+
endif()
47+
2548
if(MSVC)
2649
add_compile_options(
2750
$<$<CONFIG:>:/MT> #---------|
@@ -56,7 +79,7 @@ endif()
5679
if(NOT DEFINED CORTEX_CPP_VERSION)
5780
set(CORTEX_CPP_VERSION "default_version")
5881
endif()
59-
82+
6083
add_compile_definitions(CORTEX_VARIANT="${CORTEX_VARIANT}")
6184
add_compile_definitions(CORTEX_CPP_VERSION="${CORTEX_CPP_VERSION}")
6285
add_compile_definitions(CORTEX_CONFIG_FILE_PATH="${CORTEX_CONFIG_FILE_PATH}")
@@ -101,24 +124,24 @@ set(CHUNK_INDEX 0)
101124

102125
while(${OFFSET} LESS ${CONTENT_LENGTH})
103126
math(EXPR REMAINING "${CONTENT_LENGTH} - ${OFFSET}")
104-
127+
105128
if(${REMAINING} LESS ${CHUNK_SIZE})
106129
string(SUBSTRING "${JSON_CONTENT}" ${OFFSET} ${REMAINING} CHUNK_CONTENT)
107130
math(EXPR OFFSET "${OFFSET} + ${REMAINING}")
108131
else()
109132
string(SUBSTRING "${JSON_CONTENT}" ${OFFSET} ${CHUNK_SIZE} CHUNK_CONTENT)
110133
math(EXPR OFFSET "${OFFSET} + ${CHUNK_SIZE}")
111134
endif()
112-
135+
113136
# Escape special characters
114137
string(REPLACE "\\" "\\\\" CHUNK_CONTENT "${CHUNK_CONTENT}")
115138
string(REPLACE "\"" "\\\"" CHUNK_CONTENT "${CHUNK_CONTENT}")
116139
string(REPLACE "\n" "\\n" CHUNK_CONTENT "${CHUNK_CONTENT}")
117-
140+
118141
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/cortex_openapi.h"
119142
" inline std::string const json_part_${CHUNK_INDEX} = \"${CHUNK_CONTENT}\";\n"
120143
)
121-
144+
122145
math(EXPR CHUNK_INDEX "${CHUNK_INDEX} + 1")
123146
endwhile()
124147

@@ -192,7 +215,7 @@ aux_source_directory(database DB_SRC)
192215
aux_source_directory(extensions EX_SRC)
193216
aux_source_directory(migrations MIGR_SRC)
194217
aux_source_directory(utils UTILS_SRC)
195-
218+
196219
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} )
197220

198221
target_sources(${TARGET_NAME} PRIVATE ${UTILS_SRC} ${CONFIG_SRC} ${CTL_SRC} ${COMMON_SRC} ${SERVICES_SRC} ${DB_SRC} ${EX_SRC} ${MIGR_SRC} ${REPO_SRC})

0 commit comments

Comments
 (0)