Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CMake: Implement 'threads' Option #1698

Merged
merged 1 commit into from
Feb 7, 2025
Merged

Conversation

enetheru
Copy link
Contributor

@enetheru enetheru commented Feb 1, 2025

Add the GODOT_THREADS option and related supporting code Includes naming cleanups

@enetheru enetheru marked this pull request as ready for review February 1, 2025 02:54
@enetheru enetheru requested review from a team as code owners February 1, 2025 02:54
Add the GODOT_THREADS option and related supporting code
Includes naming cleanups
@Calinou Calinou added the enhancement This is an enhancement on the current functionality label Feb 4, 2025
@dsnopek dsnopek added this to the 4.x milestone Feb 4, 2025
@dsnopek dsnopek added the cmake label Feb 4, 2025
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!

The code seems good to me. I tested the GODOT_THREADS option when building for Linux, and everything seemed to be working fine.

However, I'm actually not sure how to build for the web! I have both the Emscripten and normal Linux toolchains available, but I don't know what arguments to pass so that it selects Emscripten. With SCons, I do this via scons platform=web, but I'm not sure how to do that for CMake. Similar for cross-compiling to Windows, how do I make it select that toolchain rather than the native Linux one?

Not important for this PR, but something I'd like to know, and perhaps we should have an example in the cmake.rst doc?

@dsnopek dsnopek merged commit 560f786 into godotengine:master Feb 7, 2025
11 checks passed
@enetheru
Copy link
Contributor Author

enetheru commented Feb 7, 2025

However, I'm actually not sure how to build for the web! I have both the Emscripten and normal Linux toolchains available, but I don't know what arguments to pass so that it selects Emscripten. With SCons, I do this via scons platform=web, but I'm not sure how to do that for CMake. Similar for cross-compiling to Windows, how do I make it select that toolchain rather than the native Linux one?

Not important for this PR, but something I'd like to know, and perhaps we should have an example in the cmake.rst doc?

I'm going to have to re-write this anyway, so this is just practice explaining.
Some of the python snippits are of my hacky builder i've been writing.
There are a couple of ways, but I prefer altering the PATH, and failing that create toolchain files.
I haven't been working in macos or linux lately as I've been re-writing my builder in python so I dont have to keep translating the code from powershell to bash to csh, etc.

For Windows:

First up I purposefully have my PATH variable not include any of the compilers, because I run all the variations, I change it when needed. I would think this doesnt work on Linux in the majority case, unless a whole toolchain is in opt or something.

VisualStudio is automatically detected from native cmake, and the native cmake selects the visual studio generator by default.
If I want another toolchain I have to specify something else like ninja.

The emsdk has an environment script which alters the path, there is also emcmake.bat which wraps the cmake command and has the --toolchain <toolchain file> directive builtin. So I just use their toolchain file directly rather than the emcmake wrapper

cfg.cmake['toolchain_file'] = 'C:/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake'

For android I use the official toolchain file provided in the AndroidSDK and a couple of variables

cfg.cmake['config_vars'] =[
    "-DANDROID_PLATFORM=latest",
    "-DANDROID_ABI=x86_64"]
cfg.cmake['toolchain_file'] = 'C:/androidsdk/ndk/23.2.8568313/build/cmake/android.toolchain.cmake'

For all of the msys2 toolchains, they are individualised to work within their own shell environments, so I use those.

For msvc with clang downloaded from llvm.org I update my path to include the llvm binaries first. and use a really crappy toolchain file which "works for me"^tm

set( CMAKE_SYSTEM_NAME Windows )
set( CMAKE_SYSTEM_PROCESSOR x86_64 )

# which compilers to use for C and C++
#set( CMAKE_C_COMPILER "C:/Program Files/LLVM/bin/clang.exe" )

set( CMAKE_CXX_COMPILER "C:/Program Files/LLVM/bin/clang-cl.exe" )
set( CMAKE_RC_COMPILER "C:/Program Files/LLVM/bin/llvm-rc.exe" )

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )

# search headers and libraries in the target environment
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )

For llvm-mingw and mingw64 I alter the path

Godot

Using the above with my builder scripts gives me these godot variations:

  • godot
    - w64.msvc.windows.x86_64
    - w64.msvc.windows.x86_64.double
    - w64.msvc.windows.x86_32
    - w64.msys2-mingw32.windows.x86_32
    - w64.msys2-mingw64.windows.x86_64
    - w64.msys2-mingw64.windows.x86_64.double
    - w64.msys2-ucrt64.windows.x86_64
    - w64.msys2-ucrt64.windows.x86_64.double
    - w64.msys2-clang64.windows.x86_64
    - w64.msys2-clang64.windows.x86_64.double
    - w64.android.x86_64
    - w64.android.x86_64.double
    - w64.android.x86_32
    - w64.android.arm64
    - w64.android.arm64.double
    - w64.web
    - w64.llvm.windows.x86_64
    - w64.llvm.windows.x86_64.double
    - w64.llvm.windows.x86_32
    - w64.llvm.windows.arm64
    - w64.llvm.windows.arm64.double
    - w64.llvm-mingw.windows.x86_64
    - w64.llvm-mingw.windows.x86_64.double
    - w64.llvm-mingw.windows.x86_32
    - w64.llvm-mingw.windows.arm32
    - w64.llvm-mingw.windows.arm64
    - w64.llvm-mingw.windows.arm64.double
    - w64.mingw64.windows.x86_64
    - w64.mingw64.windows.x86_64.double

and I'm working on the godot-cpp scripts which are a bit more involved considering the multiplication of variation that CMake adds.

godot-cpp

These are not validated to work yet, I'm still in the middle of writing the generator code:

  • godot-cpp
    - w64.msvc.windows.x86_64.scons
    - w64.msvc.windows.x86_64.cmake
    - w64.msvc.windows.x86_64.cmake.ninja
    - w64.msvc.windows.x86_64.cmake.ninja-multi
    - w64.msvc.windows.x86_64.double.scons
    - w64.msvc.windows.x86_64.double.cmake
    - w64.msvc.windows.x86_64.double.cmake.ninja
    - w64.msvc.windows.x86_64.double.cmake.ninja-multi
    - w64.msvc.windows.x86_32.scons
    - w64.msvc.windows.x86_32.cmake
    - w64.msvc.windows.x86_32.cmake.ninja
    - w64.msvc.windows.x86_32.cmake.ninja-multi
    - w64.msys2-mingw32.windows.x86_32.scons
    - w64.msys2-mingw32.windows.x86_32.cmake.ninja
    - w64.msys2-mingw32.windows.x86_32.cmake.ninja-multi
    - w64.msys2-mingw64.windows.x86_64.scons
    - w64.msys2-mingw64.windows.x86_64.cmake.ninja
    - w64.msys2-mingw64.windows.x86_64.cmake.ninja-multi
    - w64.msys2-mingw64.windows.x86_64.double.scons
    - w64.msys2-mingw64.windows.x86_64.double.cmake.ninja
    - w64.msys2-mingw64.windows.x86_64.double.cmake.ninja-multi
    - w64.msys2-ucrt64.windows.x86_64.scons
    - w64.msys2-ucrt64.windows.x86_64.cmake.ninja
    - w64.msys2-ucrt64.windows.x86_64.cmake.ninja-multi
    - w64.msys2-ucrt64.windows.x86_64.double.scons
    - w64.msys2-ucrt64.windows.x86_64.double.cmake.ninja
    - w64.msys2-ucrt64.windows.x86_64.double.cmake.ninja-multi
    - w64.msys2-clang64.windows.x86_64.scons
    - w64.msys2-clang64.windows.x86_64.cmake.ninja
    - w64.msys2-clang64.windows.x86_64.cmake.ninja-multi
    - w64.msys2-clang64.windows.x86_64.double.scons
    - w64.msys2-clang64.windows.x86_64.double.cmake.ninja
    - w64.msys2-clang64.windows.x86_64.double.cmake.ninja-multi
    - w64.android.scons
    - w64.android.cmake.ninja
    - w64.android.cmake.ninja-multi
    - w64.android.double.scons
    - w64.android.double.cmake.ninja
    - w64.android.double.cmake.ninja-multi
    - w64.web.scons
    - w64.web.cmake.ninja
    - w64.web.cmake.ninja-multi
    - w64.llvm.windows.x86_64.scons
    - w64.llvm.windows.x86_64.cmake.ninja
    - w64.llvm.windows.x86_64.cmake.ninja-multi
    - w64.llvm.windows.x86_64.double.scons
    - w64.llvm.windows.x86_64.double.cmake.ninja
    - w64.llvm.windows.x86_64.double.cmake.ninja-multi
    - w64.llvm.windows.x86_32.scons
    - w64.llvm.windows.x86_32.cmake.ninja
    - w64.llvm.windows.x86_32.cmake.ninja-multi
    - w64.llvm.windows.arm64.scons
    - w64.llvm.windows.arm64.cmake.ninja
    - w64.llvm.windows.arm64.cmake.ninja-multi
    - w64.llvm.windows.arm64.double.scons
    - w64.llvm.windows.arm64.double.cmake.ninja
    - w64.llvm.windows.arm64.double.cmake.ninja-multi
    - w64.llvm-mingw.windows.x86_64.scons
    - w64.llvm-mingw.windows.x86_64.cmake.ninja
    - w64.llvm-mingw.windows.x86_64.cmake.ninja-multi
    - w64.llvm-mingw.windows.x86_64.double.scons
    - w64.llvm-mingw.windows.x86_64.double.cmake.ninja
    - w64.llvm-mingw.windows.x86_64.double.cmake.ninja-multi
    - w64.llvm-mingw.windows.x86_32.scons
    - w64.llvm-mingw.windows.x86_32.cmake.ninja
    - w64.llvm-mingw.windows.x86_32.cmake.ninja-multi
    - w64.llvm-mingw.windows.arm32.scons
    - w64.llvm-mingw.windows.arm32.cmake.ninja
    - w64.llvm-mingw.windows.arm32.cmake.ninja-multi
    - w64.llvm-mingw.windows.arm64.scons
    - w64.llvm-mingw.windows.arm64.cmake.ninja
    - w64.llvm-mingw.windows.arm64.cmake.ninja-multi
    - w64.llvm-mingw.windows.arm64.double.scons
    - w64.llvm-mingw.windows.arm64.double.cmake.ninja
    - w64.llvm-mingw.windows.arm64.double.cmake.ninja-multi
    - w64.mingw64.windows.x86_64.scons
    - w64.mingw64.windows.x86_64.cmake.ninja
    - w64.mingw64.windows.x86_64.cmake.ninja-multi
    - w64.mingw64.windows.x86_64.cmake.mingw
    - w64.mingw64.windows.x86_64.double.scons
    - w64.mingw64.windows.x86_64.double.cmake.ninja
    - w64.mingw64.windows.x86_64.double.cmake.ninja-multi
    - w64.mingw64.windows.x86_64.double.cmake.mingw

@enetheru enetheru deleted the threads branch February 8, 2025 00:03
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cmake enhancement This is an enhancement on the current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants