godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.75k stars 580 forks source link

Added options to enable/disable targets to be added to a cmake build. #1650

Open Torets opened 6 days ago

Torets commented 6 days ago

In CMake build system all of the targets were added to build (solution for Visual Studio), which might case confusion and unnecessary additional build time. I have added following options to CMake:

Additionally to make sure that 'Test' target dependency stays valid, the following logic was added. If dependency gets turned off by corresponding GODOT_ADD_TARGET_*, then the dependency is switched to next target in following order template_debug -> template_release ->editor.

Also separate flag GODOT_CPP_USE_TEST with default value ON was added to have an ability to turn off testing as well.

These changes can be further supported in Fix break prior modernization PR by adding ${GODOT_DEFAULT_TARGET} ALIAS instead of hardcoded template_debug after both PRs are merged. Even without the change default behavior of CMake build should stay the same as it was before

enetheru commented 5 days ago

This concept arose in conversation between @Torets and I while discussing the changes in master.

Being able to disable/enable the targets gives a best of both worlds scenario when dealing with CMake and IDE's that have cluttered target lists, and build everything like Visual Studio does. But does not prevent building everything all at once if desired.

enetheru commented 1 day ago

Hey @Torets I was doing some testing, and setup a new project which fetched godot-cpp. Visual studio didnt build anything at all when triggering the all build. Can you re-check with a fresh source tree that the build-all in visual studio does/does not infact try to build all targets for you? I had to consume a target, or remove EXLCUDE_FROM_ALL to get it to want to build the library when clicking the build all, i htink f6, or from the build menu.

Torets commented 1 day ago

@enetheru It does for me. Though I've got version from my clone. If I check Project Dependencies, here is what I have for ALL_BUILD: изображение

Torets commented 1 day ago

The only EXCLUDE_FROM_ALL I have in my version is in CMakeLists.txt from my folder. And regardless of having it for the rest of projects or no and having folders for them (which is always good), I think having an option to remove projects from *.sln is needed QoL feature

enetheru commented 1 day ago

The only EXCLUDE_FROM_ALL I have in my version is in CMakeLists.txt from my folder

what? there should be an ... crap do you see this add_library( ${TARGET_NAME} STATIC ${EXCLUDE} ) somwhere around godot-cpp/cmake/godotcpp.cmake:~243? that ${EXLCUDE} is supposed to read EXCLUDE_FROM_ALL and was from a previous attempt at making the default template_debug, but it just got in the way.

add_library cmake docs

think having an option to remove projects from *.sln is needed QoL feature

I agree with you, I think it is a good idea, I just had conflicting information I needed to clean up in my mind.

Torets commented 1 day ago

yeah, that EXCLUDE is always empty right now from what I see. I can assume it could get in a way of passing test or some other default behavior. If not, may then I return it in your PR?