-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·81 lines (69 loc) · 3.06 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_COMPILER /usr/bin/g++)
# CHANGE YOUR PROJECT NAME
set(PROJECT_NAME c_string_tests)
project(${PROJECT_NAME} C CXX)
set(LIBN my_c_string)
#set(CMAKE_C_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
# Options
set(WARNINGS_AS_ERRORS ON)
set(ENABLE_PVS_STUDIO ON)
#! ENABLE_SANITIZERS is the option for the test builds!
# Definitely enable it while developing.
# Disable it for the production builds and before submitting for grading!
set(ENABLE_SANITIZERS ON)
# Only one of Memory(MSAN), Address(ASAN), or Thread(TSan) sanitizers is applicable at the time
set(ENABLE_UBSan ON)
#set(ASAN_OPTIONS allocator_may_return_null=1)
#message(${ASAN_OPTIONS})
set(ENABLE_ASAN ON)
set(ENABLE_TSan ON)
set(ENABLE_MSAN OFF)
# !Warnings as errors should be imported here.
# !Do not delete this line! switch it 'OFF' in case you don't need it.
include(cmake/defaults/CompilerWarnings.cmake)
#####################################################################################################
# 1) set up gtests. This block of code is taken from https://crascit.com/2015/07/25/cmake-gtest/
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download"
)
# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This adds the following targets:
# gtest, gtest_main, gmock and gmock_main
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
"${CMAKE_BINARY_DIR}/googletest-build"
)
#####################################################################################################
# 2) build my_str library
add_library(
${LIBN} SHARED
${CMAKE_SOURCE_DIR}/c_str_lib/c_string.h
${CMAKE_SOURCE_DIR}/c_str_lib/c_string.cpp
)
target_include_directories(${LIBN} PUBLIC ${CMAKE_SOURCE_DIR}/c_str_lib)
#####################################################################################################
# 3) build tests
add_executable(gtester ${CMAKE_SOURCE_DIR}/google_tests/main.cpp ${CMAKE_SOURCE_DIR}/google_tests/Tests/tests.cpp)
target_compile_definitions(gtester PUBLIC FILE_DIR="${CMAKE_SOURCE_DIR}/google_tests/test_files")
target_link_libraries(gtester ${LIBN} gtest gtest_main)
###################################
# set output directory (bin)
set_target_properties(${LIBN} gtester
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set_target_properties(${LIBN}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib_bin
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib_bin)
#####################################
# Define ALL_TARGETS variable to use in PVS and Sanitizers
set(ALL_TARGETS gtester)
include(cmake/config.cmake)