Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
65 lines (52 loc) · 1.93 KB
/
Copy pathCMakeLists.txt
File metadata and controls
65 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
cmake_minimum_required(VERSION 3.20)
project(cpplings LANGUAGES CXX)
find_package(Git QUIET)
set(DOCTEST_DIR "${CMAKE_SOURCE_DIR}/submodules/doctest")
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.gitmodules")
file(GLOB DOCTEST_CONTENTS "${DOCTEST_DIR}/*")
if(NOT DOCTEST_CONTENTS)
message(STATUS "submodules/doctest is empty, updating submodules...")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT
)
if(NOT GIT_SUBMOD_RESULT EQUAL 0)
message(FATAL_ERROR "git submodule update failed: ${GIT_SUBMOD_RESULT}")
endif()
endif()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
endif()
if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU"))
message(FATAL_ERROR "Only Clang and GCC are supported.")
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64|i[3-6]86)$")
set(SAN_FLAGS "-fsanitize=address,undefined,leak")
else()
set(SAN_FLAGS "-fsanitize=address,undefined")
endif()
file(GLOB_RECURSE EXERCISE_FILES CONFIGURE_DEPENDS
"${CMAKE_SOURCE_DIR}/exercises/*.cpp"
)
enable_testing()
foreach(ex_file ${EXERCISE_FILES})
get_filename_component(ex_name ${ex_file} NAME_WE)
add_executable(${ex_name} ${ex_file})
target_compile_features(${ex_name} PUBLIC cxx_std_23)
target_compile_options(
${ex_name}
PUBLIC ${SAN_FLAGS}
PRIVATE -Wall -Wextra -Wpedantic -g3
)
target_include_directories(
${ex_name}
PUBLIC ${CMAKE_SOURCE_DIR}/submodules/doctest
PRIVATE ${CMAKE_SOURCE_DIR}/include
)
target_compile_definitions(${ex_name} PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
target_link_options(${ex_name} PUBLIC ${SAN_FLAGS})
add_test(NAME ${ex_name} COMMAND ${ex_name})
endforeach()