godotengine / godotengine/godot-cpp

emsdkHack.cmake variables not propagated outside the godot-cpp library

Open
#1,830 9 comments 0 reactions 1 assignee Claimed by @enetheru View on GitHub
bug cmake confirmed platform:web
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

### Godot version

v4.4.1.stable.nixpkgs [49a5bc7b6]

### godot-cpp version

godot-4.4.1-stable

### System information

NixOS 25.05.20250721.92c2e04 (Warbler)

### Issue description

I'm unable to properly compile GDExtension project for web with CMake. It seems that the variables from `emsdkHack.cmake` should enable compilation of shared libraries with emscripten, but the variables are set to the `godot-cpp` project directory scope, not at the top-level GDExtension project scope where it's needed and expected. The only thing that is properly set is the `TARGET_SUPPORTS_SHARED_LIBS` global property as global properties do not follow directory scopes. This way, the project compiles with warning
```
em++: warning: linking a library with `-shared` will emit a static object file. This is a form of emulation to support existing build systems. If you want to build a runtime shared library use the SIDE_MODULE setting. [-Wemcc]
```
and the output library is unusable with godot. If I manually include the `emsdkHack.cmake` file after my top level `project` call, the compilation passes without a problem. Even with library generated this way, the `Remote Deploy -> Run in Browser` is not loading and returning `Uncaught (in promise) undefined` in Firefox console. This might be unrelated issue or result of invalid compilation.

### Steps to reproduce

0. Either enter dev environment via `nix develop` or have prerequisites defined in `flake.nix` in your `PATH` via your favourite approach.

To reproduce the failing build:
1. `emcmake cmake --preset default -B build-emscripten`
2. `cmake --build build-emscripten`
3. Uncomment the `include` in top level `CMakeLists.txt` and compile again for successful build

To try the extension in the editor, also compile it natively:
4. `cmake --preset default`
5. `cmake --build build`
6. Open the editor and run the main scene, or alternatively `Remote Deploy -> Run in Browser`

### Minimal reproduction project

[gdextension-emscripten-cmake-repro.zip](https://github.com/user-attachments/files/21779583/gdextension-emscripten-cmake-repro.zip)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.