forked from LunaticAwesome/bimap-task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
60 lines (50 loc) · 2.13 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.21)
project(bimap)
set(CMAKE_CXX_STANDARD 20)
find_package(GTest REQUIRED)
file(GLOB SRC src/*.cpp)
file(GLOB TEST_SRC test/*.cpp)
add_executable(tests ${SRC} ${TEST_SRC})
target_include_directories(tests PRIVATE src test)
if(MSVC)
target_compile_options(tests PRIVATE /W4 /permissive-)
if(TREAT_WARNINGS_AS_ERRORS)
target_compile_options(tests PRIVATE /WX)
endif()
else()
target_compile_options(tests PRIVATE -Wall -pedantic -Wextra -Wno-sign-compare)
target_compile_options(tests PRIVATE -Wold-style-cast -Wextra-semi -Woverloaded-virtual -Wzero-as-null-pointer-constant)
if(TREAT_WARNINGS_AS_ERRORS)
target_compile_options(tests PRIVATE -Werror -pedantic-errors)
endif()
target_compile_options(tests PRIVATE -Wno-self-move)
endif()
# Compiler specific warnings
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(tests PRIVATE -Wshadow=compatible-local)
target_compile_options(tests PRIVATE -Wduplicated-branches)
target_compile_options(tests PRIVATE -Wduplicated-cond)
# Disabled due to GCC bug
# target_compile_options(tests PRIVATE -Wnull-dereference)
target_compile_options(tests PRIVATE -Wno-array-bounds)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(tests PRIVATE -Wshadow-uncaptured-local)
target_compile_options(tests PRIVATE -Wloop-analysis)
target_compile_options(tests PRIVATE -Wno-self-assign-overloaded)
endif()
option(USE_SANITIZERS "Enable to build with undefined,leak and address sanitizers" OFF)
if(USE_SANITIZERS)
message(STATUS "Enabling sanitizers...")
target_compile_options(tests PUBLIC -fsanitize=address,undefined,leak -fno-sanitize-recover=all)
target_link_options(tests PUBLIC -fsanitize=address,undefined,leak)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Enabling libc++...")
target_compile_options(tests PUBLIC -stdlib=libc++)
target_link_options(tests PUBLIC -stdlib=libc++)
endif()
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Enabling _GLIBCXX_DEBUG...")
target_compile_options(tests PUBLIC -D_GLIBCXX_DEBUG)
endif()
target_link_libraries(tests GTest::gtest GTest::gtest_main)