Skip to content

Commit 6464b3d

Browse files
committed
update cmakelists.txt (add coverage support, switch to a modern cmake, add cmake flags, etc.)
1 parent fca8ce1 commit 6464b3d

1 file changed

Lines changed: 62 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 2.8.12)
1+
cmake_minimum_required(VERSION 3.14)
22

33
# if (MSVC)
44
# set(CMAKE_VS_GLOBALS "EnableASAN=true")
@@ -7,9 +7,19 @@ cmake_minimum_required(VERSION 2.8.12)
77
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
88

99
set(PROJ_NAME SlotMapTest)
10-
project(${PROJ_NAME})
10+
project(${PROJ_NAME}
11+
VERSION 1.0.0
12+
LANGUAGES CXX
13+
DESCRIPTION "Slot map data structure implementation and tests"
14+
)
1115

1216
set (CMAKE_CXX_STANDARD 17)
17+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
18+
19+
# Set default build type for performance
20+
if(NOT CMAKE_BUILD_TYPE)
21+
set(CMAKE_BUILD_TYPE Release)
22+
endif()
1323

1424
set(TEST_SOURCES
1525
SlotMapTest01.cpp
@@ -21,10 +31,20 @@ set(TEST_SOURCES
2131
add_executable(${PROJ_NAME} ${TEST_SOURCES})
2232

2333
if(MSVC)
24-
target_compile_options(${PROJ_NAME} PRIVATE /W4 /WX)
34+
target_compile_options(${PROJ_NAME} PRIVATE /W4 /WX /permissive- /EHsc)
2535
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
36+
37+
# Enable iterator debugging in debug builds
38+
target_compile_definitions(${PROJ_NAME} PRIVATE
39+
$<$<CONFIG:Debug>:_ITERATOR_DEBUG_LEVEL=2>
40+
)
2641
else()
2742
target_compile_options(${PROJ_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
43+
44+
# Enable debug flags for debug builds
45+
target_compile_options(${PROJ_NAME} PRIVATE
46+
$<$<CONFIG:Debug>:-g -O0 -DDEBUG>
47+
)
2848
endif()
2949

3050
# add slot_map
@@ -36,4 +56,43 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
3656
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/googletest" "extern/googletest")
3757
target_link_libraries(${PROJ_NAME} gtest_main)
3858

59+
# Coverage support - this is crucial for codecov.io
60+
option(ENABLE_COVERAGE "Enable code coverage" OFF)
61+
if(ENABLE_COVERAGE AND NOT MSVC)
62+
target_compile_options(${PROJ_NAME} PRIVATE --coverage -O0)
63+
target_link_options(${PROJ_NAME} PRIVATE --coverage)
64+
endif()
65+
66+
# Optional: Add address sanitizer support
67+
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
68+
if(ENABLE_ASAN AND NOT MSVC)
69+
target_compile_options(${PROJ_NAME} PRIVATE -fsanitize=address -fno-omit-frame-pointer)
70+
target_link_options(${PROJ_NAME} PRIVATE -fsanitize=address)
71+
endif()
72+
73+
# Optional: Add thread sanitizer support
74+
option(ENABLE_TSAN "Enable ThreadSanitizer" OFF)
75+
if(ENABLE_TSAN AND NOT MSVC)
76+
target_compile_options(${PROJ_NAME} PRIVATE -fsanitize=thread)
77+
target_link_options(${PROJ_NAME} PRIVATE -fsanitize=thread)
78+
endif()
79+
80+
# Optional: Add memory sanitizer support
81+
option(ENABLE_MSAN "Enable MemorySanitizer" OFF)
82+
if(ENABLE_MSAN AND NOT MSVC)
83+
target_compile_options(${PROJ_NAME} PRIVATE -fsanitize=memory -fno-omit-frame-pointer)
84+
target_link_options(${PROJ_NAME} PRIVATE -fsanitize=memory)
85+
endif()
86+
87+
# Print configuration info
88+
message(STATUS "SlotMapTest Configuration:")
89+
message(STATUS " Version: ${PROJECT_VERSION}")
90+
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
91+
message(STATUS " C++ standard: ${CMAKE_CXX_STANDARD}")
92+
message(STATUS " Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
93+
message(STATUS " Address Sanitizer: ${ENABLE_ASAN}")
94+
message(STATUS " Thread Sanitizer: ${ENABLE_TSAN}")
95+
message(STATUS " Memory Sanitizer: ${ENABLE_MSAN}")
96+
message(STATUS " Coverage: ${ENABLE_COVERAGE}")
97+
3998

0 commit comments

Comments
 (0)