forked from texus/TGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
243 lines (219 loc) · 9.34 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
####################################################################################################
# TGUI - Texus' Graphical User Interface
# Copyright (C) 2012-2024 Bruno Van de Velde ([email protected])
#
# This software is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it freely,
# subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented;
# you must not claim that you wrote the original software.
# If you use this software in a product, an acknowledgment
# in the product documentation would be appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such,
# and must not be misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source distribution.
####################################################################################################
if(NOT TGUI_DEFAULT_BACKEND)
message(WARNING "Warning: Skipping building tests. The TGUI_BUILD_TESTS option was TRUE but no backend was selected")
return()
endif()
set(TEST_SOURCES
Tests.cpp
CompareFiles.cpp
AbsoluteOrRelativeValue.cpp
Animation.cpp
Clipboard.cpp
Clipping.cpp
Color.cpp
Container.cpp
Duration.cpp
Filesystem.cpp
Focus.cpp
Font.cpp
Layouts.cpp
MouseCursors.cpp
Outline.cpp
Sprite.cpp
Signal.cpp
SignalManager.cpp
String.cpp
SvgImage.cpp
Text.cpp
Texture.cpp
TextureManager.cpp
Timer.cpp
ToolTip.cpp
Vector2.cpp
Widget.cpp
Loading/DataIO.cpp
Loading/Serializer.cpp
Loading/Deserializer.cpp
Loading/Theme.cpp
Loading/ThemeLoader.cpp
Widgets/BitmapButton.cpp
Widgets/Button.cpp
Widgets/ChatBox.cpp
Widgets/CheckBox.cpp
Widgets/ChildWindow.cpp
Widgets/ClickableWidget.cpp
Widgets/ColorPicker.cpp
Widgets/ComboBox.cpp
Widgets/EditBox.cpp
Widgets/EditBoxSlider.cpp
Widgets/FileDialog.cpp
Widgets/Group.cpp
Widgets/Grid.cpp
Widgets/HorizontalLayout.cpp
Widgets/HorizontalWrap.cpp
Widgets/Knob.cpp
Widgets/Label.cpp
Widgets/ListBox.cpp
Widgets/ListView.cpp
Widgets/MenuBar.cpp
Widgets/MessageBox.cpp
Widgets/Panel.cpp
Widgets/PanelListBox.cpp
Widgets/Picture.cpp
Widgets/ProgressBar.cpp
Widgets/RadioButton.cpp
Widgets/RadioButtonGroup.cpp
Widgets/RangeSlider.cpp
Widgets/RichTextLabel.cpp
Widgets/ScrollablePanel.cpp
Widgets/Scrollbar.cpp
Widgets/SeparatorLine.cpp
Widgets/Slider.cpp
Widgets/SpinButton.cpp
Widgets/SpinControl.cpp
Widgets/SplitContainer.cpp
Widgets/Tabs.cpp
Widgets/TabContainer.cpp
Widgets/TextArea.cpp
Widgets/ToggleButton.cpp
Widgets/TreeView.cpp
Widgets/VerticalLayout.cpp
)
# Bundle multiple files together when performing a unity build (useful for CI to speed up compilation).
# Note that this creates new source files which causes CMake to no longer detect changed to the original source files,
# so this should only be enabled in places where the TGUI is build only once.
# For CMake 3.18 and newer, TGUI supports the CMAKE_UNITY_BUILD option and this code should no longer be used.
if (TGUI_OPTIMIZE_SINGLE_BUILD)
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.18")
# The only reason this code still exists is so that the CI can continue to do unity builds with an
# older CMake version. Once the CMake version is updated, we should fail here to prevent keeping the old code.
message(FATAL_ERROR "TGUI_OPTIMIZE_SINGLE_BUILD has been replaced with CMAKE_UNITY_BUILD")
endif()
list(LENGTH TEST_SOURCES fileCount)
if (TGUI_OPTIMIZE_SINGLE_BUILD_THREADS)
set(threads ${TGUI_OPTIMIZE_SINGLE_BUILD_THREADS})
else()
include(ProcessorCount)
ProcessorCount(threads)
endif()
if (${threads} LESS ${fileCount})
math(EXPR threads "(${threads} / 2) + 1")
math(EXPR fileCountMinusOne "${fileCount} - 1")
math(EXPR threadsMinusOne "${threads} - 1")
set(NEW_TEST_SOURCES "")
foreach(i RANGE 0 ${threadsMinusOne})
set(OutputFile "${CMAKE_CURRENT_SOURCE_DIR}/CombinedSources-Tests-${i}.cpp")
file(WRITE "${OutputFile}" "")
foreach(j RANGE ${i} ${fileCountMinusOne} ${threads})
list(GET TEST_SOURCES ${j} inputFile)
file(READ ${inputFile} CONTENTS)
file(APPEND "${OutputFile}" "${CONTENTS}")
list(APPEND NEW_TEST_SOURCES "${OutputFile}")
endforeach()
endforeach()
set(TEST_SOURCES ${NEW_TEST_SOURCES})
endif()
endif()
# Add some files last that shouldn't be part of the unity build as they may include different backends
list(APPEND TEST_SOURCES Widgets/Canvas.cpp)
list(APPEND TEST_SOURCES BackendEvents.cpp)
list(APPEND TEST_SOURCES main.cpp)
add_executable(tests ${TEST_SOURCES})
target_include_directories(tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(tests PRIVATE tgui tgui-console-app-interface)
if(NOT TGUI_BUILD_AS_CXX_MODULE)
# Enable unity build by default
if (NOT DEFINED CMAKE_UNITY_BUILD AND NOT DEFINED TGUI_OPTIMIZE_SINGLE_BUILD)
set_target_properties(tests PROPERTIES UNITY_BUILD ON)
endif()
endif()
tgui_set_global_compile_flags(tests)
tgui_set_stdlib(tests)
# Disable warnings about deprecated code, so that we can keep our tests for deprecated functionality
if (TGUI_COMPILER_MSVC)
target_compile_options(tests PRIVATE /wd4996)
else()
target_compile_options(tests PRIVATE -Wno-deprecated-declarations)
endif()
if(TGUI_OPTIMIZE_SINGLE_BUILD AND TGUI_COMPILER_MSVC)
# We don't need this for the new UNITY_BUILD, only for the deprecated TGUI_OPTIMIZE_SINGLE_BUILD option,
# because the new batching doesn't result in such huge object files.
target_compile_options(tests PRIVATE /bigobj)
endif()
if(TGUI_ENABLE_DRAW_TESTS)
target_compile_definitions(tests PRIVATE TGUI_ENABLE_DRAW_TESTS)
endif()
if(NOT TGUI_BUILD_AS_CXX_MODULE)
# Use a precompiled header to speed up compilation.
# We must exclude the main file since it contains the implementation of Catch.
target_precompile_headers(tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Tests.hpp")
set_source_files_properties(main.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
# Mark some files that shouldn't be part of the unity build as they may include different backends
set_source_files_properties(main.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
set_source_files_properties(BackendEvents.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
set_source_files_properties(Widgets/Canvas.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
# Copy the resources folder to the build directory to execute the tests without installing them
add_custom_command(TARGET tests
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/tests/expected" "$<TARGET_FILE_DIR:tests>/expected"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/tests/resources" "$<TARGET_FILE_DIR:tests>/resources"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/themes" "$<TARGET_FILE_DIR:tests>/resources"
VERBATIM)
set(target_install_dir "${TGUI_MISC_INSTALL_PREFIX}/tests")
copy_dlls_to_exe("$<TARGET_FILE_DIR:tests>" "${target_install_dir}" tests)
# Set the RPATH of the executable on Linux (and BSD)
if(TGUI_SHARED_LIBS AND TGUI_OS_LINUX)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
cmake_path(SET lib_dir NORMALIZE "${CMAKE_INSTALL_PREFIX}")
cmake_path(APPEND lib_dir "${CMAKE_INSTALL_LIBDIR}")
cmake_path(SET exe_dir NORMALIZE "${CMAKE_INSTALL_PREFIX}")
cmake_path(APPEND exe_dir "${target_install_dir}")
set(rel_lib_dir "${lib_dir}")
cmake_path(RELATIVE_PATH rel_lib_dir BASE_DIRECTORY "${exe_dir}")
else()
# This code for CMake < 3.20 only works if CMAKE_INSTALL_PREFIX is an absolute path
file(RELATIVE_PATH rel_lib_dir
"${CMAKE_INSTALL_PREFIX}/${target_install_dir}"
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
set_target_properties(tests PROPERTIES
INSTALL_RPATH "$ORIGIN/${rel_lib_dir}" # RPATH will contain relative path to where we installed our own library
INSTALL_RPATH_USE_LINK_PATH TRUE) # RPATH will contain paths to our dependencies
endif()
if (TGUI_INSTALL)
# Add the install rule for the executable
install(TARGETS tests
RUNTIME DESTINATION ${target_install_dir} COMPONENT tests
BUNDLE DESTINATION ${target_install_dir} COMPONENT tests)
# Install the resources next to the test executable
install(DIRECTORY "${PROJECT_SOURCE_DIR}/tests/resources"
DESTINATION "${target_install_dir}"
COMPONENT tests)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/tests/expected"
DESTINATION "${target_install_dir}"
COMPONENT tests)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/themes/"
DESTINATION "${target_install_dir}/resources"
COMPONENT tests)
endif()