You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CMake - When executing cmake --build build on the command line the project does not build #1724
When attempting to build godot-cpp from the command line using traditional CMake methods the Makefile will not execute a default project when cmake --build . or make is executed. It reports that there are files that are to be generated but executing make does nothing. It was only until I opened up the Makefile that CMake generated that I was able to find the target names that can be built:
godot-cpp.generate_bindings
godot-cpp.template_debug
godot-cpp.template_release
godot-cpp.editor
I have no idea which of these are supposed to be built or if they all need to be built in order to create the necessary tools and libraries. CMake is supposed to act as a use and forget about it. A seasoned CMake user as myself expects the following:
This is not straight forward and if this is the intended behavior then it should be available in the README.md or in the Official Build Documents. Ideally, it would be nice to have an install version as well for portability. It's nice to be able to point to a customized install of a package using something like the following:
I have no idea which of these are supposed to be built or if they all need to be built in order to create the necessary tools and libraries.
This depends entirely on how the GDExtension you're building works. If you're building someone else's GDExtension, take a look in the .gdextension file - you need to build all the targets that are used there (although, hopefully they've documented that in their documentation). If you're building your own GDExtension, you need the ones you need for your purposes :-)
That said, with scons, we default to building the template_debug target.
I don't know if that's a good default, but if it's possible to do a similar default with CMake, perhaps we should for build system parity? But perhaps there's a good reason not to do a default for CMake?
cc @enetheru the maintainer of the cmake configuration
Hey yeah, so from what I gathered from your comments is that you want to build godot-cpp like a library and install it. But its really not designed to be used like that. It's not a stand alone library.
What you need to do instead is consume it as part of your gdextension library, by including it in your project and then linking to it.
Edit: The targets are there to match whatever godot executables you are using.
This is kind of where I disagree, and maybe this is me not understanding how the cpp bindings are supposed to work, but I have my CMake project set up in a way where I can point to modular builds of third party dependencies. In which this case, godot-cpp is a third party library with a static library provided.
And since it provides a static library, then one should be safe to assume that it’s okay to link said library with the overall project.
I do have a .gdextension which I can point to my shared object or DLL to a custom location in my build folder. And I’ve been able to load my shared library just fine and build against it.
I still think if CMake is trying to achieve the same thing as scons then it should build 1 target by default.
I still think if CMake is trying to achieve the same thing as scons then it should build 1 target by default.
If there's no technical reason not to have a default target, we should probably have the same one as scons
However, like I said above, I'm not sure it's the best default. If you're making an editor-only extension, then you won't want to make a template_debug build. But there really isn't a default that will work for all use cases
I still think if CMake is trying to achieve the same thing as scons then it should build 1 target by default.
If there's no technical reason not to have a default target, we should probably have the same one as scons
However, like I said above, I'm not sure it's the best default. If you're making an editor-only extension, then you won't want to make a template_debug build. But there really isn't a default that will work for all use cases
Which I think can be solved in two ways:
Either put it in the readme in this repository. Which would be the quickest and most versatile.
Or have it build all targets. I’m more than happy to have a conversation about this or contribute in any way. You don’t have to listen to me though haha. I’m a CMake snob and purest and I actually put in a install function on my end, built it, ran it, and it worked great.
If we have a default, it shouldn't be different than the default used by scons, unless there's a special cmake-specific reason to do so, but it doesn't sound like there is in this case
If we have a default, it shouldn't be different than the default used by scons, unless there's a special cmake-specific reason to do so, but it doesn't sound like there is in this case
Then I think if the behavior is to be the same as scons being executed then template_debug should be the way to go.
There is a conflict here that I do not have a complete solution for.
Currently all the targets are excluded from ALL on purpose because when godot is consumed by a project it isnt supposed to build anything that isnt directly asked for.
Adding(or more specifically not excluding) template_debug to the default all target, means that it will build no matter if you are using it or not, which is undesirable.
CMake 3.21 added PROJECT_IS_TOP_LEVEL, but we are on 3.17
I can work around that by checking if PROJECT_NAME is set prior to the godot-cpp project call and setting a variable.
then I can add template_debug as a target for ALL predicated on that result.
However, it is impossible to create a 1:1 match to SCons because the CMake build type default is Debug, which is not fixable for multi-config generators like Ninja-Multi-Config, Visual Studio, and I believe XCode.
No matter how its arranged input from the user is expected in that regard.
Side note for @Sailanarmo why are you building godot-cpp separately and using find package, rather than either fetchconfig or include? It's not the kind of library that gets build separately from a project, or installed on a system.
However, it is impossible to create a 1:1 match to SCons because the CMake build type default is Debug, which is not fixable for multi-config generators like Ninja-Multi-Config, Visual Studio, and I believe XCode.
If there's CMake-specific technical issues with having a default, could we maybe instead give a warning if someone tries to build without giving a target?
Side note for @Sailanarmo why are you building godot-cpp separately and using find package, rather than either fetchconfig or include? It's not the kind of library that gets build separately from a project, or installed on a system.
@enetheru I apologize if I come off as aggressive, or snarky, since that is not my intent. But it is the lack of clear documentation that leaves me to believe that if developer gives me the power to build something as a library, I am going to do it and link it into my project. I know that traditionally, this repository gets cloned down into the game project as a submodule and it is built into the project all together at once.
However, it is my understanding, that a static library gets built and it is linked into the project. Now, if there is clear documentation that says this is not the intention of the repository and that all code MUST be compiled and linked. Then I would have followed that route. However, because I am so familiar with CMake I see the following lines in the code:
This tells me that files are going to be built and populated. If I see something use FetchContent, that tells me that the project can be fetched, built, and linked into your project as a dependency. So if I see that, I will assume that I can build the package myself, deploy and installation, and then link to it whenever.
This was further confirmed to me when I cloned down the repository, ran the build, and found static libraries populated. I also found targets.cmake files where it tells CMake, "Here is where the include files are, here is where the library is, and here is the godot-cpp:: namespace that you can append to it."
So with that knowledge, I decided to add install macros here:
I then tested it locally by doing, cmake -B build -S . -DCMAKE_INSTALL_PREFIX=install and then ran cmake --build build --target godot-cpp.template_debug and cmake --build build --target install and watched it populate all of the headers, cmake targets, cmake package configs, and the static library libgodot-cpp.linux.template_debug.x86_64.a. I then pointed my godot project to it by doing:
I cleaned my build, watched it run, link, compile, I then opened up the Godot Editor to test if it was working and my class popped up in the editor exactly the same as I had done with fetch content. So that told me that this was a success and I am indeed able to create this as a modularized package that I don't have to recompile every time if I have to clean my build.
So I hope that answers your question on to why I am doing it that way. The bigger answer to your question is, "If I can find a way to not pull in a dependency's source code into my build I am going to do everything in my power to do that." Why? Because I am not touching the thirdparty libraries code. I am modifying my own code and the only thing that should be built is my code. It saves on compile time dramatically.
Again, if there is clear documentation that says that this repo must be built with the source code then I will not go down this route anymore. I am all about making libraries and working that way. If I notice that what I am building is a library I will build it into a library. My current CMake project looks like:
Which then I can built my smaller libraries like this:
Which then does this:
Which then populates my binary that I can pull into godot via the .gdextension script:
Which then happily loads in godot:
So again, if I am doing this wrong then I can correct it. But I again implore that the value of documentation on how CMake, or this repo, is meant to be treated or built. I apologize for the long essay of an explanation. And again, I am not trying to be argumentative, snarky, rude, or arrogant. I am a very skilled C++ developer with a lot of knowledge on CMake and build architecture who is trying their hand in a new world of game development and has little to no understanding on how this project specifically is supposed to work.
If there's CMake-specific technical issues with having a default, could we maybe instead give a warning if someone tries to build without giving a target?
However, it is my understanding, that a static library gets built and it is linked into the project. Now, if there is clear documentation that says this is not the intention of the repository and that all code MUST be compiled and linked.
There's a number of very commonly used features that aren't compatible with keeping a single godot-cpp static library and reusing it in all projects, namely:
Using a custom extension_api.json. We only bundle the latest stable JSON for a given branch. Commonly extension developers want to use either (1) an older one, like if we bundle 4.2.2 and they want to use 4.2.0 for compatibility with more Godot versions, or (2) one from a custom build of Godot where extra features were included (one that comes up a lot is building Godot with double precision), or certain features were compiled out
Using a build_profile.json to only build the godot-cpp classes that are actually used in a specific extension. This can dramatically reduce the binary size of a GDExtension, so many (most?) GDExtensions that are distributed publicly do this
We probably could do a better job of documenting those features :-)
Using a build_profile.json to only build the godot-cpp classes that are actually used in a specific extension. This can dramatically reduce the binary size of a GDExtension, so many (most?) GDExtensions that are distributed publicly do this
We probably could do a better job of documenting those features :-)
Thank you for the response and I believe this clears up a lot of misunderstandings from my end. This would warrant a conversation outside of this issue but for now I believe I understand the point of this repository.
I guess if I have a Class Foo, that does some fooey stuff. Then I need to build Foo with this repository and then import that extension(?) into my greater game project?
And if I have a Class Bar, that does some barey stuff, I will need to build Bar with this repository and do the same thing that I did with Foo?
I just want to be clear that is the intended behavior? I'm not even sure that I made myself clear with this haha.
I'm not entirely sure I understand your example, but godot-cpp generates code for a lot of classes (953 in a quick ls of the gen/src/classes directory). If your extension only uses, for example, 10 of those, you can provide a build_profile.json that will build godot-cpp with only those 10 classes, which will result in your GDExtension binary being dramatically smaller than if you used a build of godot-cpp with all the classes.
I'm not entirely sure I understand your example, but godot-cpp generates code for a lot of classes (953 in a quick ls of the gen/src/classes directory). If your extension only uses, for example, 10 of those, you can provide a build_profile.json that will build godot-cpp with only those 10 classes, which will result in your GDExtension binary being dramatically smaller than if you used a build of godot-cpp with all the classes.
That actually makes a ton of sense! You actually answered the question on why creating a default could be difficult. Since the default would build all the classes and create one static library from that.
The example I gave was poorly structured as I typed it out. So I will try again.
I have an abstract class in which I created a concrete child class from. We will call it Foo. Foo inherits from the Abstract Foo, and the Abstract Foo inherits from a Character2D object. As of right now, I can register both oh them with the register types and produce the DLL to load in.
I was asking if I want to create another class Bar. That is not abstract, that I eventually want to use with Foo. But I want to test the behavior and functionality before I give it to Foo. So I assumed I could build Bar into the same DLL to use. But perhaps that isn't the case? Am I supposed to build Bar outside of Foo, with it's own cpp-godot repo?
Essentially is it supposed to look like:
Game Project
-> bin/foo.dll, bar.dll
-> foo.gdextension
-> bar.gdextension
So I assumed I could build Bar into the same DLL to use. But perhaps that isn't the case? Am I supposed to build Bar outside of Foo, with it's own cpp-godot repo?
No, you absolutely can build both classes into the same GDExtension using the same build of godot-cpp.
However, your GDExtension is unlikely to need to use all 900+ classes that godot-cpp can generate code for, so if you only need 2 Godot classes from godot-cpp, you can have it only build those 2. The idea is that each GDExtension can (and probably should) only build the godot-cpp classes it needs for any build that gets distributed. (In development, you may want to build with all classes, but that's up to the developer.)
@dsnopek Thanks for the response. One final off topic question then. So I am encountering an issue where my class Bar cannot link against a class it has been compiled against. Call it Fuzz.
I've registered it in the register_types.cpp file, everything compiles fine and seems to link fine in the binary. But when it tries to load through Godot it gets angry and says it has an undefined symbol to one of the functions in Fuzz. Now, Fuzz doesn't rely on Godot at all. It's bare bones C++ stuff. Honestly, it's just a class that has an Id, which is an integer, and a name, which is a std::string. With getters and setters to it.
Is the reason that it is having issues with Fuzz is because Fuzz does not inherit from a godot::Object or godot::Ref?
Activity
dsnopek commentedon Mar 4, 2025
This depends entirely on how the GDExtension you're building works. If you're building someone else's GDExtension, take a look in the .gdextension file - you need to build all the targets that are used there (although, hopefully they've documented that in their documentation). If you're building your own GDExtension, you need the ones you need for your purposes :-)
That said, with scons, we default to building the
template_debugtarget.I don't know if that's a good default, but if it's possible to do a similar default with CMake, perhaps we should for build system parity? But perhaps there's a good reason not to do a default for CMake?
cc @enetheru the maintainer of the cmake configuration
enetheru commentedon Mar 4, 2025
Hey yeah, so from what I gathered from your comments is that you want to build godot-cpp like a library and install it. But its really not designed to be used like that. It's not a stand alone library.
What you need to do instead is consume it as part of your gdextension library, by including it in your project and then linking to it.
Edit: The targets are there to match whatever godot executables you are using.
enetheru commentedon Mar 4, 2025
eg using fetchcontent, but you could use any method to include the godot-cpp source.
enetheru commentedon Mar 4, 2025
Please close this as it is working as intended.
Sailanarmo commentedon Mar 4, 2025
This is kind of where I disagree, and maybe this is me not understanding how the cpp bindings are supposed to work, but I have my CMake project set up in a way where I can point to modular builds of third party dependencies. In which this case, godot-cpp is a third party library with a static library provided.
And since it provides a static library, then one should be safe to assume that it’s okay to link said library with the overall project.
I do have a .gdextension which I can point to my shared object or DLL to a custom location in my build folder. And I’ve been able to load my shared library just fine and build against it.
I still think if CMake is trying to achieve the same thing as scons then it should build 1 target by default.
dsnopek commentedon Mar 4, 2025
If there's no technical reason not to have a default target, we should probably have the same one as scons
However, like I said above, I'm not sure it's the best default. If you're making an editor-only extension, then you won't want to make a
template_debugbuild. But there really isn't a default that will work for all use casesSailanarmo commentedon Mar 4, 2025
Which I think can be solved in two ways:
Either put it in the readme in this repository. Which would be the quickest and most versatile.
Or have it build all targets. I’m more than happy to have a conversation about this or contribute in any way. You don’t have to listen to me though haha. I’m a CMake snob and purest and I actually put in a install function on my end, built it, ran it, and it worked great.
dsnopek commentedon Mar 4, 2025
If we have a default, it shouldn't be different than the default used by scons, unless there's a special cmake-specific reason to do so, but it doesn't sound like there is in this case
Sailanarmo commentedon Mar 4, 2025
Then I think if the behavior is to be the same as scons being executed then template_debug should be the way to go.
enetheru commentedon Mar 5, 2025
There is a conflict here that I do not have a complete solution for.
Currently all the targets are excluded from ALL on purpose because when godot is consumed by a project it isnt supposed to build anything that isnt directly asked for.
Adding(or more specifically not excluding) template_debug to the default
alltarget, means that it will build no matter if you are using it or not, which is undesirable.CMake 3.21 added PROJECT_IS_TOP_LEVEL, but we are on 3.17
I can work around that by checking if PROJECT_NAME is set prior to the godot-cpp project call and setting a variable.
then I can add template_debug as a target for ALL predicated on that result.
However, it is impossible to create a 1:1 match to SCons because the CMake build type default is Debug, which is not fixable for multi-config generators like Ninja-Multi-Config, Visual Studio, and I believe XCode.
No matter how its arranged input from the user is expected in that regard.
Side note for @Sailanarmo why are you building godot-cpp separately and using find package, rather than either fetchconfig or include? It's not the kind of library that gets build separately from a project, or installed on a system.
dsnopek commentedon Mar 5, 2025
If there's CMake-specific technical issues with having a default, could we maybe instead give a warning if someone tries to build without giving a target?
Sailanarmo commentedon Mar 5, 2025
@enetheru I apologize if I come off as aggressive, or snarky, since that is not my intent. But it is the lack of clear documentation that leaves me to believe that if developer gives me the power to build something as a library, I am going to do it and link it into my project. I know that traditionally, this repository gets cloned down into the game project as a submodule and it is built into the project all together at once.
However, it is my understanding, that a static library gets built and it is linked into the project. Now, if there is clear documentation that says this is not the intention of the repository and that all code MUST be compiled and linked. Then I would have followed that route. However, because I am so familiar with CMake I see the following lines in the code:
This tells me that files are going to be built and populated. If I see something use FetchContent, that tells me that the project can be fetched, built, and linked into your project as a dependency. So if I see that, I will assume that I can build the package myself, deploy and installation, and then link to it whenever.
This was further confirmed to me when I cloned down the repository, ran the build, and found static libraries populated. I also found targets.cmake files where it tells CMake, "Here is where the include files are, here is where the library is, and here is the godot-cpp:: namespace that you can append to it."
So with that knowledge, I decided to add install macros here:
I then tested it locally by doing,
cmake -B build -S . -DCMAKE_INSTALL_PREFIX=installand then rancmake --build build --target godot-cpp.template_debugandcmake --build build --target installand watched it populate all of the headers, cmake targets, cmake package configs, and the static librarylibgodot-cpp.linux.template_debug.x86_64.a. I then pointed my godot project to it by doing:I cleaned my build, watched it run, link, compile, I then opened up the Godot Editor to test if it was working and my class popped up in the editor exactly the same as I had done with fetch content. So that told me that this was a success and I am indeed able to create this as a modularized package that I don't have to recompile every time if I have to clean my build.
So I hope that answers your question on to why I am doing it that way. The bigger answer to your question is, "If I can find a way to not pull in a dependency's source code into my build I am going to do everything in my power to do that." Why? Because I am not touching the thirdparty libraries code. I am modifying my own code and the only thing that should be built is my code. It saves on compile time dramatically.
Again, if there is clear documentation that says that this repo must be built with the source code then I will not go down this route anymore. I am all about making libraries and working that way. If I notice that what I am building is a library I will build it into a library. My current CMake project looks like:
Which then I can built my smaller libraries like this:
Which then does this:
Which then populates my binary that I can pull into godot via the .gdextension script:
Which then happily loads in godot:
So again, if I am doing this wrong then I can correct it. But I again implore that the value of documentation on how CMake, or this repo, is meant to be treated or built. I apologize for the long essay of an explanation. And again, I am not trying to be argumentative, snarky, rude, or arrogant. I am a very skilled C++ developer with a lot of knowledge on CMake and build architecture who is trying their hand in a new world of game development and has little to no understanding on how this project specifically is supposed to work.
Sailanarmo commentedon Mar 5, 2025
I think this would be a perfectly valid solution!
dsnopek commentedon Mar 5, 2025
There's a number of very commonly used features that aren't compatible with keeping a single godot-cpp static library and reusing it in all projects, namely:
extension_api.json. We only bundle the latest stable JSON for a given branch. Commonly extension developers want to use either (1) an older one, like if we bundle 4.2.2 and they want to use 4.2.0 for compatibility with more Godot versions, or (2) one from a custom build of Godot where extra features were included (one that comes up a lot is building Godot with double precision), or certain features were compiled outbuild_profile.jsonto only build the godot-cpp classes that are actually used in a specific extension. This can dramatically reduce the binary size of a GDExtension, so many (most?) GDExtensions that are distributed publicly do thisWe probably could do a better job of documenting those features :-)
Sailanarmo commentedon Mar 5, 2025
Thank you for the response and I believe this clears up a lot of misunderstandings from my end. This would warrant a conversation outside of this issue but for now I believe I understand the point of this repository.
I guess if I have a Class Foo, that does some fooey stuff. Then I need to build Foo with this repository and then import that extension(?) into my greater game project?
And if I have a Class Bar, that does some barey stuff, I will need to build Bar with this repository and do the same thing that I did with Foo?
I just want to be clear that is the intended behavior? I'm not even sure that I made myself clear with this haha.
dsnopek commentedon Mar 5, 2025
I'm not entirely sure I understand your example, but godot-cpp generates code for a lot of classes (953 in a quick
lsof thegen/src/classesdirectory). If your extension only uses, for example, 10 of those, you can provide abuild_profile.jsonthat will build godot-cpp with only those 10 classes, which will result in your GDExtension binary being dramatically smaller than if you used a build of godot-cpp with all the classes.Sailanarmo commentedon Mar 5, 2025
That actually makes a ton of sense! You actually answered the question on why creating a default could be difficult. Since the default would build all the classes and create one static library from that.
The example I gave was poorly structured as I typed it out. So I will try again.
I have an abstract class in which I created a concrete child class from. We will call it Foo. Foo inherits from the Abstract Foo, and the Abstract Foo inherits from a Character2D object. As of right now, I can register both oh them with the register types and produce the DLL to load in.
I was asking if I want to create another class Bar. That is not abstract, that I eventually want to use with Foo. But I want to test the behavior and functionality before I give it to Foo. So I assumed I could build Bar into the same DLL to use. But perhaps that isn't the case? Am I supposed to build Bar outside of Foo, with it's own cpp-godot repo?
Essentially is it supposed to look like:
Game Project
-> bin/foo.dll, bar.dll
-> foo.gdextension
-> bar.gdextension
Foo
-> godot-cpp
-> build/foo.dll
-> CMakeLists.txt
-> Souce Code for Foo
Bar
-> godot-cpp
-> build/bar.dll
-> CMakeLists.txt
-> Source Code for Bar
dsnopek commentedon Mar 5, 2025
No, you absolutely can build both classes into the same GDExtension using the same build of godot-cpp.
However, your GDExtension is unlikely to need to use all 900+ classes that godot-cpp can generate code for, so if you only need 2 Godot classes from godot-cpp, you can have it only build those 2. The idea is that each GDExtension can (and probably should) only build the godot-cpp classes it needs for any build that gets distributed. (In development, you may want to build with all classes, but that's up to the developer.)
Sailanarmo commentedon Mar 5, 2025
@dsnopek Thanks for the response. One final off topic question then. So I am encountering an issue where my class Bar cannot link against a class it has been compiled against. Call it Fuzz.
So:
I've registered it in the register_types.cpp file, everything compiles fine and seems to link fine in the binary. But when it tries to load through Godot it gets angry and says it has an undefined symbol to one of the functions in Fuzz. Now, Fuzz doesn't rely on Godot at all. It's bare bones C++ stuff. Honestly, it's just a class that has an Id, which is an integer, and a name, which is a std::string. With getters and setters to it.
Is the reason that it is having issues with Fuzz is because Fuzz does not inherit from a
godot::Objectorgodot::Ref?enetheru commentedon Mar 6, 2025
merged #1728 which solves the primary issue here.
enetheru commentedon Mar 14, 2025
even better solution merged, should #1733, thanks for your feedback.
If you are still having issues with this can you submit a new bug, or discuss in forums or discord please.