forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
211 lines (198 loc) · 8.15 KB
/
Copy pathCMakeLists.txt
File metadata and controls
211 lines (198 loc) · 8.15 KB
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
file(GLOB _all_cpp "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB _mml_cpp "${CMAKE_CURRENT_SOURCE_DIR}/main_message_loop/*.cpp")
if(APPLE)
file(GLOB _mm_files "${CMAKE_CURRENT_SOURCE_DIR}/*.mm")
list(APPEND _all_cpp ${_mm_files})
file(GLOB _mml_mm "${CMAKE_CURRENT_SOURCE_DIR}/main_message_loop/*.mm")
list(APPEND _mml_cpp ${_mml_mm})
endif()
# Helper: filter a list of source files for the current platform.
# Sets the result in the variable named by OUT_VAR.
function(filter_sources IN_LIST OUT_VAR)
set(_result "")
foreach(_f IN LISTS ${IN_LIST})
get_filename_component(_name "${_f}" NAME)
set(_skip FALSE)
if(_name MATCHES "_win\\.cpp$" AND NOT WIN32)
set(_skip TRUE)
endif()
if(_name MATCHES "_linux\\.cpp$" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
set(_skip TRUE)
endif()
if(_name MATCHES "_mac\\.(cpp|mm)$" AND NOT APPLE)
set(_skip TRUE)
endif()
if(_name MATCHES "^x11\\.cpp$" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
set(_skip TRUE)
endif()
if(_name MATCHES "gtk" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
set(_skip TRUE)
endif()
if(NOT _skip)
list(APPEND _result "${_f}")
endif()
endforeach()
set(${OUT_VAR} "${_result}" PARENT_SCOPE)
endfunction()
filter_sources(_all_cpp _filtered_all)
filter_sources(_mml_cpp _filtered_mml)
# ---- cefpython_app (browser-process static library) -------------------------
# All subprocess/*.cpp except main.cpp, plus main_message_loop/*.cpp
set(_app_sources "")
foreach(_f IN LISTS _filtered_all)
get_filename_component(_name "${_f}" NAME)
if(NOT _name STREQUAL "main.cpp")
list(APPEND _app_sources "${_f}")
endif()
endforeach()
list(APPEND _app_sources ${_filtered_mml})
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(GTK3_UNIXPRINT REQUIRED gtk+-unix-print-3.0)
endif()
add_library(cefpython_app STATIC ${_app_sources})
add_dependencies(cefpython_app cefpython_headers)
target_include_directories(cefpython_app PRIVATE
"${CEFPYTHON_SRC_DIR}"
"${CEFPYTHON_SRC_DIR}/common"
"${CEFPYTHON_PYX_STAGE_DIR}"
${Python_INCLUDE_DIRS}
)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_include_directories(cefpython_app PRIVATE
${GTK3_INCLUDE_DIRS}
${GTK3_UNIXPRINT_INCLUDE_DIRS}
)
endif()
if(WIN32)
target_compile_options(cefpython_app PRIVATE /EHsc /wd4190)
target_compile_definitions(cefpython_app PRIVATE
WIN32 _WIN32 _WINDOWS
NTDDI_VERSION=0x06010000 WINVER=0x0601 _WIN32_WINNT=0x0601
NDEBUG _NDEBUG _CRT_SECURE_NO_WARNINGS NOMINMAX
BROWSER_PROCESS
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h"
)
elseif(APPLE)
target_compile_options(cefpython_app PRIVATE -DNDEBUG -O3)
target_compile_definitions(cefpython_app PRIVATE
BROWSER_PROCESS
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h")
else()
target_compile_options(cefpython_app PRIVATE -DNDEBUG -O3)
target_compile_definitions(cefpython_app PRIVATE
BROWSER_PROCESS
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h")
endif()
# ---- subprocess executable (renderer-process) -------------------------------
# All subprocess/*.cpp except print_handler_gtk.cpp (already filtered above on non-Linux).
# Note: does NOT include main_message_loop sources — that is browser-process only.
set(_exe_sources "")
foreach(_f IN LISTS _filtered_all)
get_filename_component(_name "${_f}" NAME)
if(NOT _name MATCHES "print_handler_gtk")
list(APPEND _exe_sources "${_f}")
endif()
endforeach()
if(WIN32)
# Locate CEF's stock compatibility.manifest from the unpacked binary
# distribution. `tools/download_cef.py` extracts the distrib to
# build/cef_binary_<full-version>_windows64/; this is always present
# when a from-source build runs (automate.py --prebuilt-cef requires
# the same directory).
file(GLOB _cef_binary_candidates LIST_DIRECTORIES true
"${CMAKE_SOURCE_DIR}/build/cef_binary_*_windows64")
set(_cef_binary_distrib "")
foreach(_d IN LISTS _cef_binary_candidates)
if(IS_DIRECTORY "${_d}")
set(_cef_binary_distrib "${_d}")
break()
endif()
endforeach()
set(_cef_compat_manifest
"${_cef_binary_distrib}/tests/cefsimple/win/compatibility.manifest")
if(NOT EXISTS "${_cef_compat_manifest}")
message(FATAL_ERROR
"compatibility.manifest not found under build/cef_binary_*_windows64/.\n"
"Run `python tools/download_cef.py` to extract the CEF distribution.")
endif()
message(STATUS "Subprocess manifest input: ${_cef_compat_manifest}")
endif()
add_executable(cefpython_subprocess ${_exe_sources})
add_dependencies(cefpython_subprocess cefpython_headers)
set_target_properties(cefpython_subprocess PROPERTIES OUTPUT_NAME "subprocess")
target_include_directories(cefpython_subprocess PRIVATE
"${CEFPYTHON_SRC_DIR}"
"${CEFPYTHON_SRC_DIR}/common"
"${CEFPYTHON_PYX_STAGE_DIR}"
${Python_INCLUDE_DIRS}
)
if(WIN32)
# Static CRT (/MT) required for the subprocess executable
set_property(TARGET cefpython_subprocess PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
target_compile_options(cefpython_subprocess PRIVATE /std:c++20)
target_compile_definitions(cefpython_subprocess PRIVATE
WIN32 _WIN32 _WINDOWS
NTDDI_VERSION=0x06010000 WINVER=0x0601 _WIN32_WINNT=0x0601
NDEBUG _NDEBUG _CRT_SECURE_NO_WARNINGS
NOMINMAX UNICODE _UNICODE WIN32_LEAN_AND_MEAN
"_HAS_EXCEPTIONS=0"
RENDERER_PROCESS
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h"
)
target_link_libraries(cefpython_subprocess PRIVATE
"${CEFPYTHON_CEF_ROOT}/lib/libcef.lib"
"${CEFPYTHON_CEF_ROOT}/lib/VS2015/libcef_dll_wrapper_MT.lib"
)
# Embed CEF's compatibility.manifest as RT_MANIFEST so Chromium's
# ANGLE D3D11 GPU process init does not crash with STATUS_BREAKPOINT
# (exit_code=-2147483645). The linker merges /MANIFESTINPUT with its
# auto-generated trustInfo block and embeds the result as resource
# id 1, identical to a hand-written subprocess.rc but driven by CMake.
target_link_options(cefpython_subprocess PRIVATE
/MANIFEST:EMBED
"/MANIFESTINPUT:${_cef_compat_manifest}"
/LARGEADDRESSAWARE /SUBSYSTEM:WINDOWS
)
elseif(APPLE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
set(_macos_ver_min 11.0)
else()
set(_macos_ver_min 10.9)
endif()
target_compile_options(cefpython_subprocess PRIVATE -DNDEBUG -O3)
target_compile_definitions(cefpython_subprocess PRIVATE
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h")
target_link_options(cefpython_subprocess PRIVATE
-mmacosx-version-min=${_macos_ver_min}
-Wl,-search_paths_first
"-F${CEFPYTHON_CEF_ROOT}/bin"
"-framework" "Chromium Embedded Framework"
"-Wl,-rpath,@loader_path/"
# Embed Info.plist so CFBundleGetMainBundle() returns CFBundleIdentifier
# = "org.cefpython", matching the service name the browser process
# registers with MachPortRendezvousServer.
"-sectcreate" "__TEXT" "__info_plist"
"${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
)
target_link_libraries(cefpython_subprocess PRIVATE
"${CEFPYTHON_CEF_ROOT}/lib/libcef_dll_wrapper.a"
)
else()
target_compile_options(cefpython_subprocess PRIVATE -DNDEBUG -O3)
target_compile_definitions(cefpython_subprocess PRIVATE
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h")
target_link_libraries(cefpython_subprocess PRIVATE
"${CEFPYTHON_CEF_ROOT}/lib/libcef_dll_wrapper.a"
"${CEFPYTHON_CEF_ROOT}/bin/libcef.so"
)
# Use $ORIGIN so the installed subprocess finds libcef.so from its own
# directory (cefpython3/) instead of the build-time CEF path which
# contains chrome-sandbox — a setuid binary that can't work on nosuid
# filesystems (e.g. VMware HGFS).
set_target_properties(cefpython_subprocess PROPERTIES
BUILD_RPATH "$ORIGIN"
INSTALL_RPATH "$ORIGIN"
)
endif()