This directory contains the "shared" target which implements a static library shared by all example executable targets.
The "shared" target is an abstraction of the cefsimple project described in the CEF Tutorial. The cefsimple application has been restructured for these examples so that common implementations and functionality live in the "shared" target while example-specific implementations live in the example executable targets ("message_router", "minimal", etc). The concepts described in the CEF Tutorial excluding the "Getting Started" section still apply to these example targets.
Executables that depend on this target are implemented as follows:
- Define the target-specific CMake build configuration in the CMakeLists.txt file. See the "Configuration" section below for details.
- Call the shared entry point functions declared in main.h and process_helper_mac.h that initialize, run and shut down CEF.
- Linux implementation: main_linux.cc (single executable, all processes)
- macOS implementation: main_mac.mm (main executable, main process), process_helper_mac.cc (helper executable, sub-processes)
- Windows implementation: main_win.cc (single executable, all processes)
- Implement the
shared::Create*ProcessApp
functions declared in app_factory.h to create a CefApp instance appropriate to the process type. - Provide a concrete CefClient implementation to handle CefBrowser callbacks. A
shared::CreateBrowser
function is provided in browser_util.h for convenience and will usually be called from the target-specificCefBrowserProcessHandler::OnContextInitialized
implementation. - Windows: When using resources compiled into the binary implement the
shared::GetResourceId
method declared in resource_util.h to map resource paths to BINARY ID values.
See the minimal target for a minimal implementation example. See the resource_manager target for a resource loading example.
See the CEF Tutorial for an overview of the steps performed by the CMake build configuration.
To add a new example executable target:
- Create a new directory for the executable target inside the examples folder.
- Add source files in the new directory that implement the required functionality as described in the "Implementation Overview" section above, or reference existing implementations from the minimal target directory.
- Copy the
CMakeLists.txt
file from an existing executable target to the new directory. If the new target contains resources start with the resource_manager CMakeLists.txt configuration. Otherwise, start with the minimal CMakeLists.txt configuration.- Modify the "Source files" section to specify the correct source files.
- Modify the "Shared configuration" section to specify the correct target name.
- Add the new directory name to the "Example executable targets" section at the end of the examples CMakeLists.txt configuration.
- Add a description and link to the example in the examples README.md file.
- Run the
cmake
command as described in the top-level README.md file to regenerate the project files. Verify that the new example builds and runs as expected. - If you would like to upstream your changes create a Pull Request.
Follow the Setup and Build instructions in the top-level README.md file. When building from within Visual Studio or Xcode the example targets are placed inside the "examples" folder. When building from the command-line the target name matches the directory name and can be specified directly (e.g. "message_router", "minimal", etc.).