-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
168 lines (153 loc) · 7.64 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
cmake_minimum_required(VERSION 3.25)
project(CommonItemsTests)
# Include directories
include_directories(.)
if (PLATFORM STREQUAL "Linux")
include_directories(/usr/include)
link_directories(/usr/lib)
endif (PLATFORM STREQUAL "Linux")
# Set the compiler options
set(CMAKE_CXX_STANDARD 23)
set (UNICODE_DEFAULT OFF)
if (PLATFORM STREQUAL "Windows")
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
elseif (PLATFORM STREQUAL "Linux")
#set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*)
if (COVERAGE STREQUAL true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
else (COVERAGE STREQUAL true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall")
endif (COVERAGE STREQUAL true)
endif (PLATFORM STREQUAL "Windows")
# Create OBJECT_DIR variable
set(OBJECT_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir)
message("-- Object files will be output to: ${OBJECT_DIR}")
include_directories(../external/googletest/googletest/include/gtest)
include_directories(../external/googletest/googlemock/include/gmock)
add_subdirectory("external/googletest" "googletest")
################################################################################
# Source groups
################################################################################
set(COMMON_SOURCES ${COMMON_SOURCES} "Color.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Color.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "CommonFunctions.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "CommonFunctions.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "CommonRegexes.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConvenientParser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConvenientParser.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConverterVersion.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConverterVersion.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Date.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Date.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "GameVersion.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "GameVersion.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "iconvlite.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "iconvlite.h")
if (PLATFORM STREQUAL "Windows")
set(COMMON_SOURCES ${COMMON_SOURCES} "WinUtils.cpp")
elseif (PLATFORM STREQUAL "Linux")
set(COMMON_SOURCES ${COMMON_SOURCES} "LinuxUtils.cpp")
endif (PLATFORM STREQUAL "Windows")
set(COMMON_SOURCES ${COMMON_SOURCES} "Log.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Log.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationBlock.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationBlock.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationDatabase.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationDatabase.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationLambdas.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/Mod.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModFilesystem.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModFilesystem.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModLoader.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModLoader.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModParser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModParser.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "OSCommonLayer.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "OSCompatibilityLayer.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Parser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Parser.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ParserHelpers.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ParserHelpers.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "StringUtils.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "StringUtils.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "external/zip/src/zip.c")
add_library(commonLib
${COMMON_SOURCES}
)
set(tests
"tests/test_main.cpp"
"tests/ColorTests.cpp"
"tests/CommonFunctionsTests.cpp"
"tests/CommonRegexesTests.cpp"
"tests/ConvenientParserTests.cpp"
"tests/ConverterVersionTests.cpp"
"tests/DateTests.cpp"
"tests/GameVersionTests.cpp"
"tests/iconvliteTests.cpp"
"tests/Localization/LocalizationBlockTests.cpp"
"tests/Localization/LocalizationDatabaseTests.cpp"
"tests/LogTests.cpp"
"tests/ModFilesystemTests.cpp"
"tests/ModLoaderTests.cpp"
"tests/ModParserTests.cpp"
"tests/OSCompatibilityLayerTests.cpp"
"tests/ParserHelperTests.cpp"
"tests/ParserTests.cpp"
"tests/StringUtilsTests.cpp"
)
source_group("tests" FILES ${tests})
################################################################################
# Target
################################################################################
add_executable(${PROJECT_NAME} ${tests})
target_link_libraries(${PROJECT_NAME} commonLib)
################################################################################
# Test Files
################################################################################
file(COPY "tests/TestFiles/" DESTINATION "./")
################################
# Coverage
################################
if (COVERAGE STREQUAL true)
add_custom_target(lcov
COMMAND mkdir -p lcoverage
)
add_custom_command(TARGET lcov
COMMAND echo "=================== LCOV ===================="
COMMAND echo "-- Passing lcov tool under code coverage"
COMMAND lcov --c --d CMakeFiles/commonLib.dir --o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/bits/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/ext/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/x86_64-linux-gnu/c++/11/bits/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/bits/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/ext/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "/usr/include/x86_64-linux-gnu/c++/12/bits/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googlemock/include/gmock/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googlemock/include/gmock/internal/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googletest/include/gtest/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googletest/include/gtest/internal/*" -o lcoverage/coverage.info
COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/json/single_include/nlohmann/*" -o lcoverage/coverage.info
COMMAND echo "-- Generating HTML output files"
COMMAND genhtml lcoverage/coverage.info --output-directory lcoverage
)
# Make sure to clean up the coverage folder
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES gcoverage)
# Create the clean target. This cleans the build as well as generated
# .gcda and .gcno files.
add_custom_target(init
COMMAND ${CMAKE_MAKE_PROGRAM} clean
COMMAND rm -f ${TEST_OUTPUT_DIRECTORY}/*.gcno
COMMAND rm -f ${TEST_OUTPUT_DIRECTORY}/*.gcda
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif (COVERAGE STREQUAL true)
################################
# Unit Tests
################################
enable_testing()
# Link test executable against gtest & gtest_main
target_link_libraries(${PROJECT_NAME} gtest gtest_main gmock )
add_test( runUnitTests ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} )