This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
301 lines (264 loc) · 8.78 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
cmake_minimum_required(VERSION 3.14)
project(XamlCpp VERSION 1.3.301 LANGUAGES C CXX)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
include(XamlCompilerHelper)
xaml_check_ipo()
# Options for target platforms.
option(BUILD_WINDOWS "Build for Windows with Windows API")
option(BUILD_COCOA "Build for Mac with Cocoa")
option(BUILD_GTK3 "Build with GTK3")
option(BUILD_QT5 "Build with QT5")
option(BUILD_QT6 "Build with QT6")
# Select a platform automatically.
if(NOT ${BUILD_WINDOWS} AND NOT ${BUILD_COCOA} AND NOT ${BUILD_GTK3} AND NOT ${BUILD_QT5} AND NOT ${BUILD_QT6})
if(WIN32 AND NOT MINGW)
set(BUILD_WINDOWS ON)
elseif(UNIX OR MINGW)
if(APPLE)
set(BUILD_COCOA ON)
else()
set(BUILD_GTK3 ON)
endif()
endif()
endif()
# Enable other languages.
if(${BUILD_COCOA})
enable_language(OBJC OBJCXX)
set(CMAKE_OBJC_STANDARD 11)
set(CMAKE_OBJC_EXTENSIONS ON)
set(CMAKE_OBJC_VISIBILITY_PRESET hidden)
set(CMAKE_OBJCXX_STANDARD 20)
set(CMAKE_OBJCXX_EXTENSIONS ON)
set(CMAKE_OBJCXX_VISIBILITY_PRESET hidden)
endif()
set(XAML_BUILD_DEFINITIONS "")
set(XAML_BUILD_INTERNAL_DEFINITIONS "")
set(XAML_COMPILE_OPTIONS "")
set(XAML_C_COMPILE_OPTIONS "")
set(XAML_CXX_COMPILE_OPTIONS "")
set(XAML_OBJC_COMPILE_OPTIONS "")
set(XAML_LINK_OPTIONS "")
if(WIN32)
list(APPEND XAML_BUILD_DEFINITIONS "XAML_WIN32")
if(MINGW)
list(APPEND XAML_BUILD_DEFINITIONS "XAML_MINGW")
endif()
elseif(UNIX)
list(APPEND XAML_BUILD_DEFINITIONS "XAML_UNIX")
if(APPLE)
list(APPEND XAML_BUILD_DEFINITIONS "XAML_APPLE")
endif()
endif()
# Universal definitions, independent of compilers.
if(${BUILD_WINDOWS})
list(APPEND XAML_BUILD_DEFINITIONS "UNICODE" "_UNICODE" "XAML_UI_WINDOWS")
list(APPEND XAML_BUILD_INTERNAL_DEFINITIONS "_WIN32_WINNT=_WIN32_WINNT_WIN7")
elseif(${BUILD_COCOA})
list(APPEND XAML_BUILD_DEFINITIONS "XAML_UI_COCOA")
list(APPEND XAML_OBJC_COMPILE_OPTIONS "-fobjc-arc")
elseif(${BUILD_GTK3})
list(APPEND XAML_BUILD_DEFINITIONS "XAML_UI_GTK3")
elseif(${BUILD_QT5})
list(APPEND XAML_BUILD_DEFINITIONS "XAML_UI_QT" "XAML_UI_QT5")
elseif(${BUILD_QT6})
list(APPEND XAML_BUILD_DEFINITIONS "XAML_UI_QT" "XAML_UI_QT6")
endif()
# Versions.
list(APPEND XAML_BUILD_DEFINITIONS
"XAML_VERSION=\"${CMAKE_PROJECT_VERSION}\""
"XAML_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR}"
"XAML_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR}"
"XAML_VERSION_PATCH=${CMAKE_PROJECT_VERSION_PATCH}"
)
# Big object for Windows.
if(MSVC)
list(APPEND XAML_COMPILE_OPTIONS "/bigobj")
endif()
# Enable visual style on Windows.
if(MSVC)
list(APPEND XAML_LINK_OPTIONS "/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'")
endif()
# Disable RTTI by default.
option(XAML_NO_RTTI "Disable RTTI." ON)
xaml_fix_rtti_flags()
if(${XAML_NO_RTTI})
if(MSVC)
list(APPEND XAML_CXX_COMPILE_OPTIONS "/GR-")
else()
list(APPEND XAML_CXX_COMPILE_OPTIONS "-fno-rtti")
endif()
endif()
# Use absolute path for __FILE__
if(MSVC)
list(APPEND XAML_COMPILE_OPTIONS "/FC")
endif()
# Disable char8_t
if(MSVC)
list(APPEND XAML_CXX_COMPILE_OPTIONS "/std:c++latest" "/Zc:char8_t-")
else()
list(APPEND XAML_CXX_COMPILE_OPTIONS "-fno-char8_t")
endif()
if(MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
list(APPEND XAML_COMPILE_OPTIONS "-Wno-incompatible-ms-struct")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
list(APPEND XAML_COMPILE_OPTIONS "-Wno-inconsistent-missing-override")
endif()
# Enable MSVC new preprocessor
xaml_fix_msvc_preprocessor()
# MSVC warnings
xaml_fix_warning_flags()
if(MSVC)
list(APPEND XAML_COMPILE_OPTIONS "/W4" "/wd4458" "/wd5054")
endif()
option(BUILD_SHARED_LIBS "Build shared libs" ON)
if(NOT ${BUILD_SHARED_LIBS})
list(APPEND XAML_BUILD_DEFINITIONS "XAML_STATIC_DEFINE")
if(MSVC)
# Set static library prefix to lib;
# It is not recommanded to build static libraries.
set(CMAKE_STATIC_LIBRARY_PREFIX_CXX lib)
endif()
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(XAML_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(XAML_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(XAML_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
if(${BUILD_WINDOWS})
find_package(WIL REQUIRED)
elseif(${BUILD_GTK3})
find_package(GTK3 REQUIRED)
elseif(${BUILD_QT5})
find_package(Qt5 COMPONENTS Core Gui Widgets OPTIONAL_COMPONENTS WebEngineWidgets WebKitWidgets)
elseif(${BUILD_QT6})
find_package(Qt6 COMPONENTS Core Gui Widgets)
endif()
option(BUILD_TESTS "Build tests." OFF)
option(INSTALL_RAPIDXML_HEADERS "Install (modified) rapidxml headers." OFF)
option(USE_FUNCTION2 "Use function2." ON)
option(SUPPORT_FUNCTION2 "Export function2 support APIs." OFF)
option(BUILD_PARSER "Build XAML parser." ON)
option(BUILD_WEBVIEW "Build webview." ON)
option(BUILD_CANVAS "Build canvas." ON)
option(BUILD_CONTROLS "Build controls." ON)
option(BUILD_CMDLINE "Build command line helpers." ON)
option(BUILD_DETECTOR "Build detector." ON)
option(BUILD_RESOURCE_COMPILER "Build resource compiler." ON)
unset(_XAML_BOOST_COMPONENTS)
if(APPLE)
if(${BUILD_PARSER})
set(_XAML_BOOST_COMPONENTS container)
endif()
endif()
if(_XAML_BOOST_COMPONENTS OR ${BUILD_CMDLINE})
if(_XAML_BOOST_COMPONENTS)
find_package(Boost REQUIRED COMPONENTS ${_XAML_BOOST_COMPONENTS})
else()
find_package(Boost REQUIRED)
endif()
endif()
set(_XAML_TARGETS
xaml_global
xaml_meta xaml_markup
xaml_ui xaml_ui_appmain
)
option(XAML_INSTALL "Install XamlCpp components" ON)
add_subdirectory(StreamFormat)
list(APPEND _XAML_TARGETS stream_format)
add_subdirectory(nowide)
list(APPEND _XAML_TARGETS nowide)
if(${USE_FUNCTION2})
add_subdirectory(function2)
list(APPEND XAML_BUILD_DEFINITIONS "XAML_FUNCTION2")
if(${SUPPORT_FUNCTION2})
list(APPEND XAML_BUILD_DEFINITIONS "XAML_SUPPORT_FUNCTION2")
endif()
else()
set(SUPPORT_FUNCTION2 OFF)
endif()
if(${BUILD_PARSER})
add_subdirectory(rapidxml)
list(APPEND _XAML_TARGETS xaml_rapidxml)
endif()
xaml_fix_char8_t_flags()
add_subdirectory(global)
add_subdirectory(helpers)
add_subdirectory(meta)
add_subdirectory(markup)
add_subdirectory(ui)
if(${BUILD_PARSER})
add_subdirectory(parser)
list(APPEND _XAML_TARGETS xaml_parser)
endif()
if(${BUILD_CONTROLS})
add_subdirectory(ui_controls)
list(APPEND _XAML_TARGETS xaml_ui_controls)
endif()
if(${BUILD_CANVAS})
add_subdirectory(ui_canvas)
list(APPEND _XAML_TARGETS xaml_ui_canvas)
endif()
if(${BUILD_WEBVIEW})
if(${BUILD_GTK3})
if(NOT(UNIX AND NOT APPLE))
set(BUILD_WEBVIEW OFF)
message(WARNING "webview won't be built because of unsupported platform.")
else()
find_package(WEBKIT4)
if(NOT ${WEBKIT4_FOUND})
set(BUILD_WEBVIEW OFF)
message(WARNING "Could NOT find webkit2gtk.")
endif()
endif()
elseif(${BUILD_QT5})
if((NOT Qt5WebEngineWidgets_FOUND) AND (NOT Qt5WebKitWidgets_FOUND))
set(BUILD_WEBVIEW OFF)
endif()
elseif(${BUILD_QT6})
set(BUILD_WEBVIEW OFF)
endif()
endif()
if(${BUILD_WEBVIEW})
add_subdirectory(ui_webview)
list(APPEND _XAML_TARGETS xaml_ui_webview)
endif()
if(${BUILD_CMDLINE})
add_subdirectory(cmdline)
list(APPEND _XAML_TARGETS xaml_cmdline)
endif()
if(${BUILD_DETECTOR} OR ${BUILD_RESOURCE_COMPILER})
add_subdirectory(cmdline_helper)
list(APPEND _XAML_TARGETS xaml_cmdline_helper)
endif()
if(${BUILD_DETECTOR})
add_subdirectory(detector)
list(APPEND _XAML_TARGETS xamld)
endif()
if(${BUILD_RESOURCE_COMPILER})
add_subdirectory(resource)
add_subdirectory(resource_compiler)
list(APPEND _XAML_TARGETS xamlrc)
endif()
if(${XAML_INSTALL})
install(
TARGETS ${_XAML_TARGETS}
EXPORT xaml-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(EXPORT xaml-targets DESTINATION lib/cmake/xaml)
configure_file(cmake/xaml-config.cmake.in ${PROJECT_BINARY_DIR}/xaml-config.cmake @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/xaml-config.cmake DESTINATION lib/cmake/xaml)
endif()