-
Notifications
You must be signed in to change notification settings - Fork 148
/
CMakeLists.txt
255 lines (219 loc) · 7.65 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
#
# The main config file for QCefView
#
cmake_minimum_required(VERSION 3.18)
project(QCefView)
# arguments:
# CEF_SDK_VERSION:
# - specify the CEF version to be used,
# - refer to: cmake\CefViewCoreConfig.cmake
#
# QT_SDK_DIR:
# - specify the Qt SDK path
# - refer to: cmake\QtConfig.cmake
#
# options
option(BUILD_DEMO
"Build the demo"
OFF
)
option(BUILD_STATIC
"Build QCefView as static library"
OFF
)
option(STATIC_CRT
"Use MultiThreaded linkage for MSVC"
OFF
)
option(USE_SANDBOX
"Enable CEF Sandbox"
OFF
)
# Only works for Windows & Linux, always enabled on macOS
# If enable then:
# CefSettings.multi_threaded_message_loop = false && CefSettings.external_message_pump = true
# else:
# CefSettings.multi_threaded_message_loop = true && CefSettings.external_message_pump = false
option(USE_QT_EVENT_LOOP
"Enable the integration of CEF message loop thread into Qt event loop"
OFF
)
# append cmake config module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Only generate Debug and Release configuration types.
set(CMAKE_CONFIGURATION_TYPES Debug Release)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Use folders in the resulting project files.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# C standard
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
# C++ standard
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
add_definitions(-D_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING=1)
# Determine the project architecture.
if(NOT DEFINED PROJECT_ARCH)
if(OS_WINDOWS AND "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "arm64")
set(PROJECT_ARCH "arm64")
elseif(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(PROJECT_ARCH "x86_64")
else()
set(PROJECT_ARCH "x86")
endif()
endif()
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(OS_MACOS 1)
set(OS_POSIX 1)
add_definitions(-DOS_MACOS=1 -DOS_POSIX=1)
add_compile_options(
"-g"
"$<$<CONFIG:DEBUG>:-O0>"
"$<$<CONFIG:RELEASE>:-O3>"
)
# Target architecture.
if(PROJECT_ARCH STREQUAL "x86_64")
set(CMAKE_OSX_ARCHITECTURES "x86_64")
elseif(PROJECT_ARCH STREQUAL "arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64")
else()
set(CMAKE_OSX_ARCHITECTURES "i386")
endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(OS_LINUX 1)
set(OS_POSIX 1)
add_definitions(-DOS_LINUX=1 -DOS_POSIX=1)
add_compile_options(
"-g"
"$<$<CONFIG:DEBUG>:-O0>"
"$<$<CONFIG:RELEASE>:-O3>"
)
# Target architecture.
if(PROJECT_ARCH STREQUAL "x86_64")
# x86 64-bit architecture.
add_compile_options(-m64 -march=x86-64)
add_link_options(-m64)
elseif(PROJECT_ARCH STREQUAL "x86")
# x86 32-bit architecture.
add_compile_options(-m32)
add_link_options(-m32)
endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(OS_WINDOWS 1)
# Disable the sandbox on Windows, because the sandbox.lib is MT which is conflict with Qt
set(USE_SANDBOX OFF CACHE BOOL "Disable sandbox on Windows" FORCE)
add_definitions(-DOS_WINDOWS=1)
add_compile_options("/M$<IF:$<BOOL:${STATIC_CRT}>,T,D>$<$<CONFIG:Debug>:d>")
add_link_options(/DEBUG)
endif()
if(BUILD_STATIC)
set(QCEFVIEW_LIB_TYPE STATIC)
add_definitions(-DQCEFVIEW_STATIC=1)
else()
set(QCEFVIEW_LIB_TYPE SHARED)
endif()
# detect whether we are in sub folder
get_directory_property(QCefView_HAS_PARENT_DIRECTORY PARENT_DIRECTORY)
if(NOT QCefView_HAS_PARENT_DIRECTORY)
message(STATUS "QCefView is not in subdirectory, put all output together")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>/lib)
endif()
# Config the QT package
# ##############################################################
set(QT_SDK_DIR "" CACHE PATH "Qt build toolchain path")
include(QtConfig)
set(Qt_VERSION ${Qt${QT_VERSION_MAJOR}Core_VERSION})
# ##############################################################
# Config the CEF
# ##############################################################
# Fetch CefViewCore
include(CefViewCoreConfig)
# read CEF version from cef_version.h
# set need configure QCefView_global to false
set(NEED_CONFIGURE_QCefView_global FALSE)
message(STATUS "${CefViewCore_CEF_INCLUDE_DIR}/cef_version.h")
file(READ "${CefViewCore_CEF_INCLUDE_DIR}/cef_version.h" cef_version_content)
string(REGEX MATCH "#define CEF_VERSION_MAJOR ([0-9]+)" _ ${cef_version_content})
# check CEF_VERSION_MAJOR
if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CEF_VERSION_MAJOR}")
set(CEF_VERSION_MAJOR ${CMAKE_MATCH_1} CACHE STRING "CEF Major Version" FORCE)
set(NEED_CONFIGURE_QCefView_global TRUE)
message(STATUS "CEF_VERSION_MAJOR: ${CEF_VERSION_MAJOR} - Updated!")
else()
message(STATUS "CEF_VERSION_MAJOR: ${CEF_VERSION_MAJOR} - No Change!")
endif()
# check CEF_VERSION_MAJOR
string(REGEX MATCH "#define CEF_VERSION_MINOR ([0-9]+)" _ ${cef_version_content})
if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CEF_VERSION_MINOR}")
set(CEF_VERSION_MINOR ${CMAKE_MATCH_1} CACHE STRING "CEF Minor Version" FORCE)
set(NEED_CONFIGURE_QCefView_global TRUE)
message(STATUS "CEF_VERSION_MINOR: ${CEF_VERSION_MINOR} - Updated!")
else()
message(STATUS "CEF_VERSION_MINOR: ${CEF_VERSION_MINOR} - No Change!")
endif()
string(REGEX MATCH "#define CEF_VERSION_PATCH ([0-9]+)" _ ${cef_version_content})
if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CEF_VERSION_PATCH}")
set(CEF_VERSION_PATCH ${CMAKE_MATCH_1} CACHE STRING "CEF Patch Version" FORCE)
set(NEED_CONFIGURE_QCefView_global TRUE)
message(STATUS "CEF_VERSION_PATCH: ${CEF_VERSION_PATCH} - Updated!")
else()
message(STATUS "CEF_VERSION_PATCH: ${CEF_VERSION_PATCH} - No Change!")
endif()
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/QCefView_global.h")
set(NEED_CONFIGURE_QCefView_global TRUE)
endif()
if(${NEED_CONFIGURE_QCefView_global})
message(STATUS "Need to configure QCefView_global.h file")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/include/QCefView_global.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/include/QCefView_global.h"
@ONLY
NEWLINE_STYLE UNIX
)
else()
message(STATUS "No need to configure QCefView_global.h file")
endif()
if(OS_MACOS)
# detect minimum deployment target by Qt
if(${Qt_VERSION} VERSION_GREATER_EQUAL 6.5)
set(QT_MIN_DEPLOYMENT_TARGET 11.0)
elseif(${Qt_VERSION} VERSION_GREATER_EQUAL 6.2)
set(QT_MIN_DEPLOYMENT_TARGET 10.14)
elseif(${Qt_VERSION} VERSION_GREATER_EQUAL 5.14)
set(QT_MIN_DEPLOYMENT_TARGET 10.13)
elseif(${Qt_VERSION} VERSION_GREATER_EQUAL 5.13)
set(QT_MIN_DEPLOYMENT_TARGET 10.12)
elseif(${Qt_VERSION} VERSION_GREATER_EQUAL 5.10)
set(QT_MIN_DEPLOYMENT_TARGET 10.11)
else()
set(QT_MIN_DEPLOYMENT_TARGET 10.10)
endif()
# detect minimum deployment target by CEF
# plese refere to: https://bitbucket.org/chromiumembedded/cef/wiki/BranchesAndBuilding.md
if(${CEF_VERSION_MAJOR} VERSION_GREATER_EQUAL 117)
set(CEF_MIN_DEPLOYMENT_TARGET 10.15)
elseif(${CEF_VERSION_MAJOR} VERSION_GREATER_EQUAL 104)
set(CEF_MIN_DEPLOYMENT_TARGET 10.13)
else()
set(CEF_MIN_DEPLOYMENT_TARGET 10.11)
endif()
# use the greater one as the minimum deployment target
if(${QT_MIN_DEPLOYMENT_TARGET} VERSION_LESS ${CEF_MIN_DEPLOYMENT_TARGET})
set(CMAKE_OSX_DEPLOYMENT_TARGET ${CEF_MIN_DEPLOYMENT_TARGET})
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET ${QT_MIN_DEPLOYMENT_TARGET})
endif()
endif()
# Config QCefView target
# ##############################################################
add_subdirectory(src)
# Config the Demo project
# ##############################################################
if(BUILD_DEMO)
add_subdirectory(example/QCefViewTest)
endif()
# ##############################################################