Skip to content

Commit

Permalink
Merge pull request #58 from rpaciorek/build_fix
Browse files Browse the repository at this point in the history
Fix finding libcef.so on Linux and other build fixes
  • Loading branch information
Lecrapouille authored Jun 1, 2024
2 parents 84a533b + f2941c0 commit 601bbf1
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 82 deletions.
6 changes: 0 additions & 6 deletions addons/gdcef/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ describing the given demos.
var browser = $CEF.create_browser("https://github.com/Lecrapouille/gdcef", $TextureRect, {})
browser.get_name("hello")
```
- In Linux, you will have to write something like:
```
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/path/gdcef/examples/build
```

to make your system finds shared libraries such as `libcef.so`.

- You should obtain a minimal CEF browser not reacting to your mouse and key
binding. See the 2D and 3D demos to make your browser tab reacts to your input events.
Expand Down
30 changes: 20 additions & 10 deletions addons/gdcef/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
CEF_BUILD_FOLDER_NAME = "build"
# When we are compiling demos we are creating a folder holding CEF build artifacts.
# But, in the aim to save space on your hard disk the folder is a pointer to folder
# CEF_ARTIFACTS_BUILD_PATH. If you modify this variable, do not forget to also change
# Godot .gdns and .gdnlib files inside the libs folders in GDCEF_EXAMPLES_PATH the
# demos folder.
# CEF_ARTIFACTS_BUILD_PATH.
CEF_ARTIFACTS_FOLDER_NAME = "cef_artifacts"
# Use OpenMP for using CPU parallelim (i.e. for copying textures)
CEF_USE_CPU_PARALLELISM = "yes" # or "no"
Expand Down Expand Up @@ -427,6 +425,15 @@ def compile_gdnative_cef(path):
else:
fatal("Unknown archi " + OSTYPE + ": I dunno how to compile CEF module primary process")

###############################################################################
### Compile Godot CEF module named GDCef and its subprocess
def create_gdextension_file():
info("Create Godot .gdextension file")
with open(os.path.join(GDCEF_PATH, "gdcef.gdextension.in"), "r") as f:
extension = f.read().replace("CEF_ARTIFACTS_FOLDER_NAME", CEF_ARTIFACTS_FOLDER_NAME)
with open(os.path.join(CEF_ARTIFACTS_BUILD_PATH, "gdcef.gdextension"), "w") as f:
f.write(extension)

###############################################################################
### Check if compilers are present (Windows)
def check_compiler():
Expand Down Expand Up @@ -484,7 +491,9 @@ def prepare_godot_examples():
path = os.path.join(GDCEF_EXAMPLES_PATH, filename)
if os.path.isdir(path) and os.path.isfile(os.path.join(path, "project.godot")):
info(" - Demo " + path)
symlink(CEF_ARTIFACTS_BUILD_PATH, os.path.join(path, CEF_ARTIFACTS_FOLDER_NAME))
artifacts_path = os.path.join(path, CEF_ARTIFACTS_FOLDER_NAME)
mkdir(os.path.dirname(artifacts_path))
symlink(CEF_ARTIFACTS_BUILD_PATH, artifacts_path)

###############################################################################
### Run Godot example
Expand All @@ -493,12 +502,12 @@ def run_godot_example():
" into '" + CEF_ARTIFACTS_BUILD_PATH + "' and can be used for your Godot"
" project. Do not forget to add .gdns and .gdnlib files refering to libgdcef.so/dll.\n")
if OSTYPE == "Linux":
info("For Unix systems you have to make your system know where to find shared"
" libraries needed for CEF. Save the following command in your environment"
" (~/.bashrc i.e.):\n\n"
" export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:" + CEF_ARTIFACTS_BUILD_PATH + "\n"
" export LD_PRELOAD=" + CEF_ARTIFACTS_BUILD_PATH + "/libcef.so\n")
info("Once done, you can run your Godot editor " + GODOT_VERSION + " and try"
info("`" + CEF_ARTIFACTS_FOLDER_NAME + "` path is used to find shared libraries"
" needed for CEF. Put `" + CEF_ARTIFACTS_BUILD_PATH + "` as `" +
CEF_ARTIFACTS_FOLDER_NAME + "` into your project to avoid having to set"
" LD_LIBRARY_PATH environment variable. If you want use other folder name,"
" edit value of CEF_ARTIFACTS_FOLDER_NAME in build.py and rebuild project.\n")
info("You can run your Godot editor " + GODOT_VERSION + " and try"
" one of the demos located in '" + GDCEF_EXAMPLES_PATH + "'.\n\nHave fun!")

###############################################################################
Expand All @@ -514,5 +523,6 @@ def run_godot_example():
install_cef_assets()
compile_gdnative_cef(GDCEF_PATH)
compile_gdnative_cef(GDCEF_PROCESSES_PATH)
create_gdextension_file()
prepare_godot_examples()
run_godot_example()
2 changes: 0 additions & 2 deletions addons/gdcef/demos/2D/CEF.gd
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ func _ready():
# artifacts: allows path such as "build" or "res://cef_artifacts/". Note that "res://"
# will use ProjectSettings.globalize_path but exported projects don't support globalize_path:
# https://docs.godotengine.org/en/3.5/classes/class_projectsettings.html#class-projectsettings-method-globalize-path
var resource_path = "res://cef_artifacts/"
if !$CEF.initialize({
"artifacts":resource_path,
"incognito":true,
"locale":"en-US",
"enable_media_stream": true
Expand Down
17 changes: 0 additions & 17 deletions addons/gdcef/demos/2D/libs/gdcef.gdextension

This file was deleted.

3 changes: 1 addition & 2 deletions addons/gdcef/demos/3D/GUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ func _ready():
# artifacts: allows path such as "build" or "res://cef_artifacts/". Note that "res://"
# will use ProjectSettings.globalize_path but exported projects don't support globalize_path:
# https://docs.godotengine.org/en/3.5/classes/class_projectsettings.html#class-projectsettings-method-globalize-path
var resource_path = "res://cef_artifacts/"
if !$CEF.initialize({"artifacts":resource_path, "incognito":true, "locale":"en-US"}):
if !$CEF.initialize({"incognito":true, "locale":"en-US"}):
push_error($CEF.get_error())
get_tree().quit()
return
Expand Down
17 changes: 0 additions & 17 deletions addons/gdcef/demos/3D/libs/gdcef.gdextension

This file was deleted.

3 changes: 1 addition & 2 deletions addons/gdcef/demos/HelloCEF/Control.gd
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ func _ready():
# artifacts: allows path such as "build" or "res://cef_artifacts/". Note that "res://"
# will use ProjectSettings.globalize_path but exported projects don't support globalize_path:
# https://docs.godotengine.org/en/3.5/classes/class_projectsettings.html#class-projectsettings-method-globalize-path
var resource_path = "res://cef_artifacts/"
if !$CEF.initialize({"artifacts":resource_path, "incognito":true, "locale":"en-US"}):
if !$CEF.initialize({"incognito":true, "locale":"en-US"}):
push_error("Failed initializing CEF")
get_tree().quit()
else:
Expand Down
17 changes: 0 additions & 17 deletions addons/gdcef/demos/HelloCEF/libs/gdcef.gdextension

This file was deleted.

9 changes: 0 additions & 9 deletions addons/gdcef/demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ No command line is needed. This script will:
**Workaround For Windows:** You need **x64 Native Tools Command Prompt for VS 2022**, with
**Administrator** privilege!

**Workaround For Linux:** for the moment, the `libcef.so` and other shared libraries,
as artifcats, are not found by the systeme (even if indicated in the `.gdnlib` file.
So for the moment, you have to store the path of the `build` in your `LD_LIBRARY_PATH`
(for example in your `~/.bashrc` file).

```
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/path/gdcef/examples/build
```

**Note concerning the build folder**:

CEF artifcats are searched inside the `build` folder at the root of your Godot project.
Expand Down
4 changes: 4 additions & 0 deletions addons/gdcef/gdcef/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ env.Append(LIBS = [libcef, 'libcef_dll_wrapper'],
# Pathes header files of our module
env.Append(CPPPATH=['src/'])

# Add artifacts folder to (embedded into output binary file) list of paths to search for shared libraries
# [2:-2] because we need value of cef_artifacts_folder without protected quotation marks
env.Append(RPATH=[env['cef_artifacts_folder'][2:-2]])

# Compile the library
sources = ['src/helper_files.cpp', 'src/browser_io.cpp', 'src/gdcef.cpp', 'src/gdbrowser.cpp', 'src/register_types.cpp']
# sources = Glob('src/*.cpp')
Expand Down
17 changes: 17 additions & 0 deletions addons/gdcef/gdcef/gdcef.gdextension.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[configuration]
entry_symbol = "gdcef_library_init"
compatibility_minimum = 4.1

[libraries]
linux.x86_64.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so"
linux.x86_64.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so"
linux.x86_32.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so"
linux.x86_32.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so"

windows.x86_64.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll"
windows.x86_64.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll"
windows.x86_32.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll"
windows.x86_32.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll"

macos.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib"
macos.release = "res://CEF_ARTIFACTS_FOLDER_NAME/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib"
5 changes: 5 additions & 0 deletions addons/gdcef/subprocess/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ opts.Add(EnumVariable('arch', 'Platform architecture', 'x86_64', ['x86_64', 'arm
opts.Add(BoolVariable('use_llvm', 'Use the LLVM / Clang compiler', 'no'))
opts.Add(PathVariable('api_path', 'Godot C++ API', ''))
opts.Add(PathVariable('build_path', 'Build path', ''))
opts.Add(PathVariable('cef_artifacts_folder', 'CEF artifacts folder', '', PathVariable.PathAccept))

# Updates the environment with the option variables.
opts.Update(env)
Expand Down Expand Up @@ -204,6 +205,10 @@ env.Append(LIBS = [libcef, 'libcef_dll_wrapper'],
# Pathes header files of our module
env.Append(CPPPATH=['src/'])

# Add artifacts folder to (embedded into output binary file) list of paths to search for shared libraries
# [2:-2] because we need value of cef_artifacts_folder without protected quotation marks
env.Append(RPATH=[env['cef_artifacts_folder'][2:-2]])

# Compile the application
sources = Glob('src/*.cpp')
application = env.Program(target=target_path + '/' + target_binary, source=sources)
Expand Down

0 comments on commit 601bbf1

Please sign in to comment.