blob: d08772021ea7981f14f8c75fc84a925d43b1a417 [file] [log] [blame]
Marshall Greenblatt15bf0202016-06-14 16:28:05 -04001# Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights
Marshall Greenblatta1e06a42015-09-24 18:38:18 +03002# reserved. Use of this source code is governed by a BSD-style license that
3# can be found in the LICENSE file.
4
5# OVERVIEW
6#
7# CMake is a cross-platform open-source build system that can generate project
8# files in many different formats. It can be downloaded from
9# http://www.cmake.org or installed via a platform package manager.
10#
11# CMake-generated project formats that have been tested with JCEF include:
12#
Marshall Greenblatt544024e2021-12-13 12:47:00 -050013# Linux: Ninja, GCC 7.5.0+, Unix Makefiles
14# MacOS: Ninja, Xcode 12.2 to 13.0
15# Windows: Ninja, Visual Studio 2019+
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030016#
17# Ninja is a cross-platform open-source tool for running fast builds using
18# pre-installed platform toolchains (GNU, clang, Xcode or MSVC). It can be
19# downloaded from http://martine.github.io/ninja/ or installed via a platform
20# package manager.
21#
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030022# BUILD REQUIREMENTS
23#
Marshall Greenblatt15bf0202016-06-14 16:28:05 -040024# The below requirements must be met to build JCEF.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030025#
Marshall Greenblatt544024e2021-12-13 12:47:00 -050026# - CMake version 3.19 or newer.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030027#
28# - Linux requirements:
Marshall Greenblatt544024e2021-12-13 12:47:00 -050029# Currently supported distributions include Debian 10 (Buster), Ubuntu 18
30# (Bionic Beaver), and related. Ubuntu 18.04 64-bit with GCC 7.5.0+ is
31# recommended. Newer versions will likely also work but may not have been
32# tested.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030033# Required packages include:
34# build-essential
Marshall Greenblatt544024e2021-12-13 12:47:00 -050035# libgtk3.0-dev (required by the cefclient target only)
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030036#
Marshall Greenblatt0e666a62020-12-30 13:35:47 -050037# - MacOS requirements:
Marshall Greenblatt544024e2021-12-13 12:47:00 -050038# Xcode 12.2 to 13.0 building on MacOS 10.15.4 (Catalina) or newer. Only
39# 64-bit builds are supported. The Xcode command-line tools must also be
40# installed. Newer Xcode versions may not have been been tested and are not
41# recommended.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030042#
43# - Windows requirements:
Marshall Greenblatt544024e2021-12-13 12:47:00 -050044# Visual Studio 2019 or newer building on Windows 7 or newer. Windows 10
45# 64-bit is recommended. Newer versions will likely also work but may not have
46# been tested.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030047#
48# BUILD EXAMPLES
49#
50# The below commands will generate project files and create a Debug build of all
51# JCEF native targets using CMake and the platform toolchain.
52#
53# Start by creating and entering the CMake build output directory. The
54#`jcef_build` directory name is required by other JCEF tooling (specifically the
55# tools/make_distrib.[bat|sh] and tools/run.[bat|sh] scripts) and should not be
56# changed.
57# > cd path/to/java-cef/src
58# > mkdir jcef_build && cd jcef_build
59#
60# To perform a Linux build using a 32-bit CEF binary distribution on a 32-bit
61# Linux platform or a 64-bit CEF binary distribution on a 64-bit Linux platform:
62# Using Unix Makefiles:
63# > cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
64# > make -j4
65#
66# Using Ninja:
67# > cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug ..
68# > ninja
69#
Marshall Greenblatt0e666a62020-12-30 13:35:47 -050070# To perform a MacOS build using a 64-bit CEF binary distribution:
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030071# Using the Xcode IDE:
72# > cmake -G "Xcode" -DPROJECT_ARCH="x86_64" ..
Marshall Greenblattd68c6132015-09-27 15:11:57 +030073# Open jcef.xcodeproj in Xcode and select Product > Build.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030074#
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030075# Using Ninja:
76# > cmake -G "Ninja" -DPROJECT_ARCH="x86_64" -DCMAKE_BUILD_TYPE=Debug ..
77# > ninja
78#
Marshall Greenblatt0e666a62020-12-30 13:35:47 -050079# To perform a MacOS build using an ARM64 CEF binary distribution:
80# Using the Xcode IDE:
81# > cmake -G "Xcode" -DPROJECT_ARCH="arm64" ..
82# Open jcef.xcodeproj in Xcode and select Product > Build.
83#
84# Using Ninja:
85# > cmake -G "Ninja" -DPROJECT_ARCH="arm64" -DCMAKE_BUILD_TYPE=Debug ..
86# > ninja
87#
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030088# To perform a Windows build using a 32-bit CEF binary distribution:
Marshall Greenblatt0e666a62020-12-30 13:35:47 -050089# Using the Visual Studio 2019 IDE:
90# > cmake -G "Visual Studio 16" -A Win32 ..
Marshall Greenblattd68c6132015-09-27 15:11:57 +030091# Open jcef.sln in Visual Studio and select Build > Build Solution.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030092#
Marshall Greenblatt0e666a62020-12-30 13:35:47 -050093# Using Ninja with Visual Studio 2019 command-line tools:
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030094# (this path may be different depending on your Visual Studio installation)
Marshall Greenblatt0e666a62020-12-30 13:35:47 -050095# > "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars32.bat"
Marshall Greenblatta1e06a42015-09-24 18:38:18 +030096# > cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug ..
97# > ninja
98#
99# To perform a Windows build using a 64-bit CEF binary distribution:
Marshall Greenblatt0e666a62020-12-30 13:35:47 -0500100# Using the Visual Studio 2019 IDE:
101# > cmake -G "Visual Studio 16" -A x64 ..
Marshall Greenblattd68c6132015-09-27 15:11:57 +0300102# Open jcef.sln in Visual Studio and select Build > Build Solution.
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300103#
Marshall Greenblatt0e666a62020-12-30 13:35:47 -0500104# Using Ninja with Visual Studio 2019 command-line tools:
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300105# (this path may be different depending on your Visual Studio installation)
Marshall Greenblatt0e666a62020-12-30 13:35:47 -0500106# > "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300107# > cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug ..
108# > ninja
109
110#
111# Shared configuration.
112#
113
Marshall Greenblatt544024e2021-12-13 12:47:00 -0500114# For VS2019 and Xcode 12+ support.
115cmake_minimum_required(VERSION 3.19)
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300116
117# Only generate Debug and Release configuration types.
118set(CMAKE_CONFIGURATION_TYPES Debug Release)
119
120# Project name.
121project(jcef)
122
123# Use folders in the resulting project files.
124set_property(GLOBAL PROPERTY OS_FOLDERS ON)
125
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400126
127#
128# CEF configuration.
129#
130
131# Specify the CEF distribution version.
Rene Schneider9f354b62019-04-24 15:02:05 +0000132if(NOT DEFINED CEF_VERSION)
Artem Bochkarev2aa0df12023-03-06 20:40:19 +0700133 set(CEF_VERSION "111.2.1+g870da30+chromium-111.0.5563.64")
Rene Schneider9f354b62019-04-24 15:02:05 +0000134endif()
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400135
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300136# Determine the platform.
137if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
Marshall Greenblatt0e666a62020-12-30 13:35:47 -0500138 if("${PROJECT_ARCH}" STREQUAL "arm64")
139 set(CEF_PLATFORM "macosarm64")
Marshall Greenblatt6a2f6c02022-10-03 14:46:43 -0400140 elseif("${PROJECT_ARCH}" STREQUAL "x86_64")
141 set(CEF_PLATFORM "macosx64")
142 elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "arm64")
143 set(PROJECT_ARCH "arm64")
144 set(CEF_PLATFORM "macosarm64")
Marshall Greenblatt0e666a62020-12-30 13:35:47 -0500145 else()
Marshall Greenblatt6a2f6c02022-10-03 14:46:43 -0400146 set(PROJECT_ARCH "x86_64")
Marshall Greenblatt0e666a62020-12-30 13:35:47 -0500147 set(CEF_PLATFORM "macosx64")
148 endif()
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300149elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
Vladislav Rassokhin3172dc12022-04-22 21:04:12 +0300150 if("${PROJECT_ARCH}" STREQUAL "x86_64")
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400151 set(CEF_PLATFORM "linux64")
Vladislav Rassokhin3172dc12022-04-22 21:04:12 +0300152 elseif("${PROJECT_ARCH}" STREQUAL "arm64")
153 set(CEF_PLATFORM "linuxarm64")
154 elseif("${PROJECT_ARCH}" STREQUAL "arm/v6")
155 set(CEF_PLATFORM "linuxarm")
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300156 else()
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400157 set(CEF_PLATFORM "linux32")
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300158 endif()
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400159elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
Nikita Provotorov2ac786c2021-07-28 23:33:06 +0700160 if(MSVC)
161 include(CheckSymbolExists)
162
163 # MSVC predefines _M_ARM64 for compilations that target ARM64
164 # and _M_AMD64 for compilations that target x86_64.
165 check_symbol_exists("_M_ARM64" "" CEF_PLATFORM_WINARM64)
166 check_symbol_exists("_M_AMD64" "" CEF_PLATFORM_WIN64)
167
168 # We also should set PROJECT_ARCH explicitly because FindCEF.cmake deduces it incorrectly for
169 # cross-compilation cases.
170 if(CEF_PLATFORM_WINARM64)
171 set(CEF_PLATFORM "windowsarm64")
172 set(PROJECT_ARCH "arm64")
173 elseif(CEF_PLATFORM_WIN64)
174 set(CEF_PLATFORM "windows64")
175 set(PROJECT_ARCH "x86_64")
176 else()
177 set(CEF_PLATFORM "windows32")
178 set(PROJECT_ARCH "x86")
179 endif()
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400180 else()
Nikita Provotorov2ac786c2021-07-28 23:33:06 +0700181 message(FATAL_ERROR "Building JCEF for Windows using non-MSVC compiler is not supported.")
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300182 endif()
183endif()
184
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400185# Add this project's cmake/ directory to the module path.
186set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300187
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400188# Download and extract the CEF binary distribution (executes DownloadCEF.cmake).
189include(DownloadCEF)
190DownloadCEF("${CEF_PLATFORM}" "${CEF_VERSION}" "${CMAKE_SOURCE_DIR}/third_party/cef")
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300191
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400192# Add the CEF binary distribution's cmake/ directory to the module path.
193set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300194
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400195# Load the CEF configuration (executes FindCEF.cmake).
196find_package(CEF REQUIRED)
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300197
198
199#
Marshall Greenblattd68c6132015-09-27 15:11:57 +0300200# Python configuration.
201#
202
203# Support specification of the Python executable path via the command-line.
204if(DEFINED ENV{PYTHON_EXECUTABLE})
205 file(TO_CMAKE_PATH "$ENV{PYTHON_EXECUTABLE}" PYTHON_EXECUTABLE)
206endif()
207
208if(NOT PYTHON_EXECUTABLE)
209 unset(PYTHON_EXECUTABLE)
210
211 # Find the python interpreter.
212 find_package(PythonInterp)
213
214 if(NOT ${PYTHONINTERP_FOUND})
215 message(FATAL_ERROR "A Python installation is required. Set the "
216 "PYTHON_EXECUTABLE environment variable to explicitly "
217 "specify the Python executable path.")
218 endif()
219endif()
220
Marshall Greenblatt6d7ad9d2020-01-14 15:29:42 +0100221message(STATUS "Using Python: ${PYTHON_EXECUTABLE}")
222
Marshall Greenblattd68c6132015-09-27 15:11:57 +0300223
224#
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300225# Java configuration.
226#
227
228# Minimum required Java version.
229set(JDK_MIN_VERSION 1.7)
230
231set(JAVA_FATAL_ERROR "A Java installation is required. Set the JAVA_HOME "
232 "environment variable to explicitly specify the Java "
233 "installation directory.")
234
235# Find the Java Native Interface (JNI) installation.
236find_package(JNI ${JDK_MIN_VERSION})
237if(NOT ${JNI_FOUND})
238 message(FATAL_ERROR ${JAVA_FATAL_ERROR})
239endif()
240
241if(OS_MACOSX)
242 # OS X stores the Java binaries separately from the JNI includes/libraries.
243 # Find the Java development installation.
244 find_package(Java ${JDK_MIN_VERSION} COMPONENTS Development)
245
246 if(NOT ${Java_FOUND})
247 message(FATAL_ERROR ${JAVA_FATAL_ERROR})
248 endif()
249
250 # Determine the root path for the Java installation.
251 # Remove "bin/javac" from the path.
252 get_filename_component(JAVA_DIR ${Java_JAVAC_EXECUTABLE} DIRECTORY)
253 get_filename_component(JAVA_DIR ${JAVA_DIR} DIRECTORY)
254else()
255 # Determine the root path for the Java installation.
256 # Remove "include" from the path.
257 get_filename_component(JAVA_DIR ${JAVA_INCLUDE_PATH} DIRECTORY)
258endif()
259
260
261#
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300262# Post-configuration actions.
263#
264
Marshall Greenblattd68c6132015-09-27 15:11:57 +0300265# Generate the JCEF version header.
266message(STATUS "Generating native/jcef_version.h file...")
267execute_process(
268 COMMAND "${PYTHON_EXECUTABLE}"
269 "tools/make_version_header.py"
270 "--header"
271 "native/jcef_version.h"
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400272 "--cef-path"
273 "${CEF_ROOT}"
Marshall Greenblattd68c6132015-09-27 15:11:57 +0300274 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
275 RESULT_VARIABLE EXECUTE_RV
276 )
277if(NOT EXECUTE_RV STREQUAL "0")
278 message(FATAL_ERROR "Execution failed with unexpected result: ${EXECUTE_RV}")
279endif()
280
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400281# Copy the CEF README.txt file to the cmake build directory for use by the
282# make_readme.py script.
283file(COPY "${CEF_ROOT}/README.txt" DESTINATION "${CMAKE_BINARY_DIR}")
284
Marshall Greenblatt99931b22017-05-18 14:50:10 +0200285# Download clang-format from Google Storage.
286if(OS_WINDOWS)
287 set(GS_PLATFORM "win32")
288 set(GS_HASHPATH "win/clang-format.exe.sha1")
Marshall Greenblatt6a2f6c02022-10-03 14:46:43 -0400289 set(GS_OUTPATH "win/clang-format.exe")
Marshall Greenblatt99931b22017-05-18 14:50:10 +0200290elseif(OS_MACOSX)
291 set(GS_PLATFORM "darwin")
Marshall Greenblatt6a2f6c02022-10-03 14:46:43 -0400292 if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "arm64")
293 set(GS_HASHPATH "mac/clang-format.arm64.sha1")
294 else()
295 set(GS_HASHPATH "mac/clang-format.x64.sha1")
296 endif()
297 set(GS_OUTPATH "mac/clang-format")
Marshall Greenblatt99931b22017-05-18 14:50:10 +0200298elseif(OS_LINUX)
299 set(GS_PLATFORM "linux*")
300 set(GS_HASHPATH "linux64/clang-format.sha1")
Marshall Greenblatt6a2f6c02022-10-03 14:46:43 -0400301 set(GS_OUTPATH "linux64/clang-format")
Marshall Greenblatt99931b22017-05-18 14:50:10 +0200302endif()
303
304message(STATUS "Downloading clang-format from Google Storage...")
305execute_process(
306 COMMAND "${PYTHON_EXECUTABLE}"
307 "tools/buildtools/download_from_google_storage.py"
308 "--no_resume"
309 "--platform=${GS_PLATFORM}"
310 "--no_auth"
311 "--bucket" "chromium-clang-format"
312 "-s" "tools/buildtools/${GS_HASHPATH}"
Marshall Greenblatt6a2f6c02022-10-03 14:46:43 -0400313 "-o" "tools/buildtools/${GS_OUTPATH}"
Marshall Greenblatt99931b22017-05-18 14:50:10 +0200314 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
315 RESULT_VARIABLE EXECUTE_RV
316 )
317if(NOT EXECUTE_RV STREQUAL "0")
318 message(FATAL_ERROR "Execution failed with unexpected result: ${EXECUTE_RV}")
319endif()
320
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300321
322#
323# Include target subdirectories.
324#
325
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400326add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper)
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300327add_subdirectory(native)
328
329
330#
331# Display configuration settings.
332#
333
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400334PRINT_CEF_CONFIG()
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300335
Marshall Greenblatt15bf0202016-06-14 16:28:05 -0400336message(STATUS "*** JCEF CONFIGURATION SETTINGS ***")
Marshall Greenblattd68c6132015-09-27 15:11:57 +0300337message(STATUS "Python executable: ${PYTHON_EXECUTABLE}")
Marshall Greenblatta1e06a42015-09-24 18:38:18 +0300338message(STATUS "Java directory: ${JAVA_DIR}")
339message(STATUS "JNI libraries: ${JNI_LIBRARIES}")
340message(STATUS "JNI include directories: ${JNI_INCLUDE_DIRS}")