-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
141 lines (112 loc) · 7.48 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
cmake_minimum_required(VERSION 3.14)
if(TARGET CppOverride)
return()
endif()
set (CMAKE_CXX_STANDARD 11)
# For Clang to do parsing
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# set the project name
project(CppOverrideProject)
# ==========================================================
# Variables
# ==========================================================
set(CPP_OVERRIDE_BUILD_EXAMPLE "ON" CACHE BOOL "Build tests for CppOverride")
set(CPP_OVERRIDE_BUILD_TEST "OFF" CACHE BOOL "Build tests for CppOverride")
set(CPP_OVERRIDE_BUILD_TEST_ASAN "OFF" CACHE BOOL "Build tests with asan for CppOverride")
set(CPP_OVERRIDE_USE_SINGLE_HEADER "ON" CACHE BOOL "Use single header version instead")
add_library(CppOverride INTERFACE)
if(CPP_OVERRIDE_USE_SINGLE_HEADER)
target_include_directories(CppOverride INTERFACE "${CMAKE_CURRENT_LIST_DIR}/Include_SingleHeader")
else()
target_include_directories(CppOverride INTERFACE "${CMAKE_CURRENT_LIST_DIR}/Include_MultiHeaders")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(STANDARD_COMPILE_FLAGS "/utf-8;/W1")
set(STANDARD_LINK_FLAGS "")
else()
set(STANDARD_COMPILE_FLAGS "-Wall"
"-Wno-return-local-addr"
"-Wno-sign-compare"
"-Wno-switch"
"-Wno-gnu-zero-variadic-macro-arguments"
"-Wextra"
"-pedantic"
"-Werror")
set(STANDARD_LINK_FLAGS "")
if(CPP_OVERRIDE_BUILD_TEST_ASAN)
set (STANDARD_COMPILE_FLAGS "${STANDARD_COMPILE_FLAGS};-fstack-protector-all;-fsanitize=address")
set(STANDARD_LINK_FLAGS "${STANDARD_LINK_FLAGS};-fsanitize=address")
endif()
endif()
add_executable(GenerateSingleHeader "${CMAKE_CURRENT_LIST_DIR}/Scripts/GenerateSingleHeader.cpp")
target_compile_options(GenerateSingleHeader PRIVATE "${STANDARD_COMPILE_FLAGS}")
add_executable(GenerateMockClass "${CMAKE_CURRENT_LIST_DIR}/Scripts/GenerateMockClass.cpp")
target_compile_options(GenerateMockClass PRIVATE "${STANDARD_COMPILE_FLAGS}")
if(CPP_OVERRIDE_BUILD_TEST)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/ssTest" "${CMAKE_CURRENT_BINARY_DIR}/ssTest")
add_executable(ModifyReturnsTests "${CMAKE_CURRENT_LIST_DIR}/Tests/ModifyReturnsTests.cpp")
target_link_libraries(ModifyReturnsTests PUBLIC CppOverride ssTest)
target_compile_options(ModifyReturnsTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(ModifyReturnsTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(ModifyArgsTests "${CMAKE_CURRENT_LIST_DIR}/Tests/ModifyArgsTests.cpp")
target_link_libraries(ModifyArgsTests PUBLIC CppOverride ssTest)
target_compile_options(ModifyArgsTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(ModifyArgsTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(WhenCalledWithTests "${CMAKE_CURRENT_LIST_DIR}/Tests/WhenCalledWithTests.cpp")
target_link_libraries(WhenCalledWithTests PUBLIC CppOverride ssTest)
target_compile_options(WhenCalledWithTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(WhenCalledWithTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(TimesTests "${CMAKE_CURRENT_LIST_DIR}/Tests/TimesTests.cpp")
target_link_libraries(TimesTests PUBLIC CppOverride ssTest)
target_compile_options(TimesTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(TimesTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(IfTests "${CMAKE_CURRENT_LIST_DIR}/Tests/IfTests.cpp")
target_link_libraries(IfTests PUBLIC CppOverride ssTest)
target_compile_options(IfTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(IfTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(Otherwise_DoTests "${CMAKE_CURRENT_LIST_DIR}/Tests/Otherwise_DoTests.cpp")
target_link_libraries(Otherwise_DoTests PUBLIC CppOverride ssTest)
target_compile_options(Otherwise_DoTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(Otherwise_DoTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(WhenCalledExpectedly_DoTests "${CMAKE_CURRENT_LIST_DIR}/Tests/WhenCalledExpectedly_DoTests.cpp")
target_link_libraries(WhenCalledExpectedly_DoTests PUBLIC CppOverride ssTest)
target_compile_options(WhenCalledExpectedly_DoTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(WhenCalledExpectedly_DoTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(MixedModifyArgsAndReturnsTest "${CMAKE_CURRENT_LIST_DIR}/Tests/MixedModifyArgsAndReturnsTest.cpp")
target_link_libraries(MixedModifyArgsAndReturnsTest PUBLIC CppOverride ssTest)
target_compile_options(MixedModifyArgsAndReturnsTest PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(MixedModifyArgsAndReturnsTest PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(MockShapesTests "${CMAKE_CURRENT_LIST_DIR}/Tests/MockShapesTests.cpp")
target_link_libraries(MockShapesTests PUBLIC CppOverride ssTest)
target_compile_options(MockShapesTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(MockShapesTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(GlobalInstanceMockShapesTests "${CMAKE_CURRENT_LIST_DIR}/Tests/GlobalInstanceMockShapesTests.cpp")
target_link_libraries(GlobalInstanceMockShapesTests PUBLIC CppOverride ssTest)
target_compile_options(GlobalInstanceMockShapesTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(GlobalInstanceMockShapesTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(FreeFunctionTests "${CMAKE_CURRENT_LIST_DIR}/Tests/FreeFunctionTests.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Tests/Components/FreeFunctions.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Tests/Components/MockFreeFunctions.cpp")
target_link_libraries(FreeFunctionTests PUBLIC CppOverride ssTest)
target_compile_options(FreeFunctionTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(FreeFunctionTests PUBLIC "${STANDARD_LINK_FLAGS}")
add_executable(ArrayParamTests "${CMAKE_CURRENT_LIST_DIR}/Tests/ArrayParamTests.cpp")
target_link_libraries(ArrayParamTests PUBLIC CppOverride ssTest)
target_compile_options(ArrayParamTests PUBLIC "${STANDARD_COMPILE_FLAGS}")
target_link_options(ArrayParamTests PUBLIC "${STANDARD_LINK_FLAGS}")
if(WIN32)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/Tests/RunAllTests.bat"
"${CMAKE_CURRENT_BINARY_DIR}")
else()
file( CHMOD "${CMAKE_CURRENT_LIST_DIR}/Tests/RunAllTests.sh"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_LIST_DIR}/Tests/RunAllTests.sh"
"${CMAKE_CURRENT_BINARY_DIR}/RunAllTests.sh")
endif()
endif()
if(CPP_OVERRIDE_BUILD_EXAMPLE)
add_executable(CppOverrideExample "${CMAKE_CURRENT_LIST_DIR}/Example.cpp")
target_compile_options(CppOverrideExample PUBLIC ${STANDARD_COMPILE_FLAGS})
target_link_libraries(CppOverrideExample PUBLIC CppOverride)
target_link_options(CppOverrideExample PUBLIC "${STANDARD_LINK_FLAGS}")
endif()