Skip to content

Conversation

@enetheru
Copy link
Collaborator

@lechaosx identified an issue with compiling for web using cmake in issue #1830

This led me to discover that there was a mising flag (-sUSE_PTHREADS=1) during the link stage that prevented godot from loading the library if threads were enabled.

This PR adds the missing flag, and adds a tiny change which brings it inline with scons.

  • add -sUSE_PTHREADS=1 to link flags
  • add =1 to sSIDE_MODULE=1 in compile flags to match scons.

The other proposed changes to cache the values of the emsdkHack.cmake are not going to solve the inclusion problem, as the special case for emscripten is that the values need to be injected as part of the project instantiation. This unfortunatley makes it that any project added for emscripten needs the include injection variable set prior to its definion.

set(CMAKE_PROJECT_<my project name goes here>_INCLUDE ${godot-cpp_SOURCE_DIR}/cmake/emsdkHack.cmake)

@enetheru enetheru requested a review from a team as a code owner October 19, 2025 05:24
Copy link
Collaborator

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

These changes make sense to me. I tested, and the command line shown via --verbose looks good.

However, could you change the commit message to specifically refer to what this does rather than the Godot issue? Like, "CMake: Fix missing -sUSE_PTHREADS=1 in web build" or something like that

This unfortunatley makes it that any project added for emscripten needs the include injection variable set prior to its definion.

set(CMAKE_PROJECT_<my project name goes here>_INCLUDE ${godot-cpp_SOURCE_DIR}/cmake/emsdkHack.cmake)

So, are you saying this is something we'll need to document that developers need to add to their projects?

- add -sUSE_PTHREADS=1 to link flags
- add =1 to sSIDE_MODULE=1 in compile flags to match scons.
@enetheru
Copy link
Collaborator Author

updated the commit message.

So, are you saying this is something we'll need to document that developers need to add to their projects?

Yes, this is the case, and it's entirely unavoidable due to the way cmake works. If it were something I could fix I would eliminate it as a problem. I feel like a guide for consumers is necessary at this point, though I don't know where I would put it.

@dsnopek dsnopek changed the title CMake: Fix web export issue #1830 CMake: Fix missing -sUSE_PTHREADS=1 in web build Oct 20, 2025
@dsnopek dsnopek added cherrypick:4.4 cherrypick:4.5 bug This has been identified as a bug labels Oct 20, 2025
@dsnopek dsnopek added this to the 4.x milestone Oct 20, 2025
@dsnopek
Copy link
Collaborator

dsnopek commented Oct 20, 2025

Thanks!

I feel like a guide for consumers is necessary at this point, though I don't know where I would put it.

We have a section in the docs for Emscripten with CMake - we could document it there?

@enetheru
Copy link
Collaborator Author

We have a section in the docs for Emscripten with CMake - we could document it there?

Yeah I guess, that whole document is written from the perspective of us godot-cpp devs compiling godot-cpp, not a consumer setting up cmake for thier project, hence my hesitation.

@dsnopek
Copy link
Collaborator

dsnopek commented Oct 20, 2025

Yeah I guess, that whole document is written from the perspective of us godot-cpp devs compiling godot-cpp, not a consumer setting up cmake for thier project, hence my hesitation.

Hm, I always thought of that documentation as being for consumers using the CMake configuration in their project, with a few notes for godot-cpp contributors (for example, how to build the tests). We should probably revamp it to actually be that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This has been identified as a bug cherrypick:4.4 cherrypick:4.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants