Skip to content

Commit 0e8dc56

Browse files
committedNov 23, 2021
Proper cmake patching
1 parent 16d14bf commit 0e8dc56

7 files changed

+91
-328
lines changed
 

‎CMakeLists.txt

-322
This file was deleted.

‎DockerfileLinux

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ COPY out/linux* /prebuild
1818
#Copy additional natives
1919
COPY natives /natives
2020

21+
#Copy cmake patching script
22+
COPY scripts/patch_cmake.py .
23+
COPY patch/CMakeLists.txt.patch .
24+
2125
#Copy and launch run script
2226
COPY scripts/run_linux.sh .
2327
RUN chmod +x run_linux.sh

‎DockerfileWindows

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ FROM friwidev/jcefdocker:windows-latest
22

33
WORKDIR C:/
44

5+
#Copy cmake patching script
6+
COPY scripts/patch_cmake.py .
7+
COPY patch/CMakeLists.txt.patch .
8+
59
#Copy and launch run script
610
COPY scripts/run_windows.bat .
711
ENTRYPOINT ["run_windows.bat"]

‎patch/CMakeLists.txt.patch

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Determine the platform.
2+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
3+
if("${PROJECT_ARCH}" STREQUAL "arm64")
4+
set(CEF_PLATFORM "macosarm64")
5+
else()
6+
set(CEF_PLATFORM "macosx64")
7+
endif()
8+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
9+
if("${PROJECT_ARCH}" STREQUAL "amd64")
10+
set(CEF_PLATFORM "linux64")
11+
elseif("${PROJECT_ARCH}" STREQUAL "arm64")
12+
set(CEF_PLATFORM "linuxarm64")
13+
elseif("${PROJECT_ARCH}" STREQUAL "arm/v6")
14+
set(CEF_PLATFORM "linuxarm")
15+
else()
16+
set(CEF_PLATFORM "linux32")
17+
endif()
18+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
19+
#Stolen from Jetbrains jcef repository for the arm64 windows build
20+
if(MSVC)
21+
include(CheckSymbolExists)
22+
23+
# MSVC predefines _M_ARM64 for compilations that target ARM64
24+
# and _M_AMD64 for compilations that target x86_64.
25+
check_symbol_exists("_M_ARM64" "" CEF_PLATFORM_WINARM64)
26+
check_symbol_exists("_M_AMD64" "" CEF_PLATFORM_WIN64)
27+
28+
# We also should set PROJECT_ARCH explicitly because FindCEF.cmake deduces it incorrectly for
29+
# cross-compilation cases.
30+
if(CEF_PLATFORM_WINARM64)
31+
set(CEF_PLATFORM "windowsarm64")
32+
set(PROJECT_ARCH "arm64")
33+
elseif(CEF_PLATFORM_WIN64)
34+
set(CEF_PLATFORM "windows64")
35+
set(PROJECT_ARCH "x86_64")
36+
else()
37+
set(CEF_PLATFORM "windows32")
38+
set(PROJECT_ARCH "x86")
39+
endif()
40+
else()
41+
message(FATAL_ERROR "Building JCEF for Windows using non-MSVC compiler is not supported.")
42+
endif()
43+
endif()
44+

‎scripts/patch_cmake.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Small script to patch CMakeLists.txt files with custom build options
2+
#Will replace file contents between two markers ("Determine the platform"
3+
#and "Add this project's cmake")
4+
#Usage: python patch_cmake.py <input> <patch>
5+
6+
import sys
7+
8+
input = sys.argv[1]
9+
patch = sys.argv[2]
10+
11+
print("Patching "+input+" to accept further build architectures...")
12+
13+
f = open(input, "r")
14+
p = open(patch, "r")
15+
result = ""
16+
inpatch = False
17+
for x in f:
18+
if x.startswith("# Determine the platform"):
19+
inpatch = True
20+
for y in p:
21+
result += y
22+
elif x.startswith("# Add this project's cmake"):
23+
inpatch = False
24+
if inpatch == False:
25+
result += x
26+
27+
f.close()
28+
p.close()
29+
30+
f = open(input, "w")
31+
f.write(result)
32+
f.close()
33+
34+
print("Done.")

‎scripts/run_linux.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ if [ ! -f "/jcef/README.md" ]; then
2323
git clone ${REPO} /jcef
2424
cd /jcef
2525
git checkout ${REF}
26-
#Temporary CMakeLists patching - beautify in the future
27-
rm CMakeLists.txt
28-
curl -o CMakeLists.txt https://raw.githubusercontent.com/jcefmaven/jcefbuild/master/CMakeLists.txt
2926
else
3027
echo "Found existing files to build"
3128
cd /jcef
3229
fi
3330

31+
#CMakeLists patching
32+
python3 /builder/patch_cmake.py CMakeLists.txt /builder/CMakeLists.txt.patch
33+
3434
# Create and enter the `jcef_build` directory.
3535
# The `jcef_build` directory name is required by other JCEF tooling
3636
# and should not be changed.

‎scripts/run_windows.bat

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ if exist "jcef\README.md" (echo "Found existing files to build" && cd jcef) ^
1212
else (echo "Did not find files to build - cloning..." && GOTO :CLONE)
1313

1414
:BUILD
15-
:: Temporary CMakeLists patching - beautify in the future
16-
del /f CMakeLists.txt
17-
curl -o CMakeLists.txt https://raw.githubusercontent.com/jcefmaven/jcefbuild/master/CMakeLists.txt
15+
:: CMakeLists patching
16+
python3 C:/patch_cmake.py CMakeLists.txt C:/CMakeLists.txt.patch
1817

1918
:: Prepare build dir
2019
mkdir jcef_build && cd jcef_build

0 commit comments

Comments
 (0)
Please sign in to comment.