-
-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake Configuration Exporting #1309
base: master
Are you sure you want to change the base?
Conversation
1b59336
to
79a0d64
Compare
Thanks! At a high-level, this makes sense: you can build the necessary version of godot-cpp into a Docker image, and then re-use it during CI. And I tested it using the commands in the description, and it seemed to work fine! However, personally, I don't know cmake very well, so I can't say if this is the right/best way to accomplish this. Also, because I don't know cmake very well, I'm a little wary of having to maintain this long-term. So, I think it'd be good to get a 2nd opinion from someone on the GDExtension team with more cmake experience. |
I actually just did something very similar to this PR last night. I wanted godot-cpp packaged in vcpkg for my project, but I needed these exports to do it. When we link against a library in CMake, the official and recommended way is to use At a glance, I do see some odd things going on here. There should be no reason to add It is also suggested to use the GNUInstallDirs to set up the install locations. I can take a deeper look at this when I have some more time if you'd like. It's easy to miss details, so it warrants a few more eyes, but if we get it right the first time, it shouldn't need to be modified often. |
If you use godot-cpp project as subproject (eg. in your GDExtension CMake project) and you use add_subdirectory(godot-cpp)
#...
add_library(MyExtension)
target_link_libraries(MyExtension PRIVATE godot::cpp)
install(TARGETS MyExtension ...) then installing GDExtension project will export not only MyExtension.so (or *.dll), but also godot-cpp's library and config which in most of cases is not expected behavior. To avoid that there is a common practice in CMake for libraries/frameworks exporting config to introduce flag like _INSTALL, eg. like in Google Test we have a cache flag If we use godot-cpp CMake project as sub-project we set cache flag before calling set(GODOT_CPP_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(godot_cpp) Now building target Regarding install locations, targets by default use GNUInstallDirs, only header files need to be setup here. I try to use it by assigning include directories as |
I have been playing with if (GODOT_GDEXTENSION_DIR AND EXISTS ${GODOT_GDEXTENSION_DIR})
file(GLOB_RECURSE GODOT_GDEXTENSION_HEADERS CONFIGURE_DEPENDS ${GODOT_GDEXTENSION_DIR}/*.h**)
endif ()
set(PUBLIC_HEADERS_LIST
${GENERATED_FILES_LIST}
${HEADERS}
${GODOT_GDEXTENSION_HEADERS}
)
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS_LIST}") and it install all header files in install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gen/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
) results in CMake project loading error, because during project configuration variable |
This is great! I would like something like this, so I can use this library with package managers like vcpkg. That said I feel like the export name should be be consistent with the alias name, which is godot::cpp. A library user would expect the library's target name to be the same regardless of how it's consumed. Fortunately the fix is only 1 line, just add set_target_properties(${PROJECT_NAME}
PROPERTIES
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
OUTPUT_NAME "${OUTPUT_NAME}"
EXPORT_NAME "cpp"
) |
Any chance this can be updated with the latest changes? |
Feature
Allows to build CMake
install
target that exports GodotCppConfig.cmake allowing to find it by usingfind_package()
function.Usage
Configure godot-cpp CMake project in build directory:
Now instead of storing godot_cpp project as submodule in GDExtension CMake project we can:
Configuring GDExtension project in build directory
Finding and linking to godot_cpp library:
Why?
RUN
Docker command in Dockerfile. Stored built godot-cpp in Docker image allows to use it in separate environment (eg. on CI) and save time and resources.Example install godot-cpp in Dockerfile
Tip:
/usr/local/
is by default in Linux env inPATH
, so when GDExtension CMake project is configured we do not need to provideCMAKE_PREFIX_PATH
.