CMake custom command fails in certain build configurations #2719
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Hello,
When adding the project via FetchContent, or when including it as a subdirectory, an error occurs when building. Specifically, when building the
generate_core_mavlink_xml_headertarget, an error occurs as CMake can't findcmake/generate_embedded_xml.cmake.This can be reproduced by the following CMake file:
In this case, we are adding a sub-directory that contains the MAVSDK source, but this could be done via FetchContent as well. Configuring will go ok, but if CMake is asked to build all targets then the error occurs.
This is because there is a custom CMake command that uses the
CMAKE_SOURCE_DIRvariable to locate the root of the project. The problem is, when including MAVSDK using the methods defined above, this variable instead points to the root of the project including MAVSDK. Because the parent project does not have this file, a build error occurs. We fix this by instead navigating to the root manually from the problematic CMake file.Please let me know if there are any changes required, this is a small patch. Also, if it is not intended to include MAVSDK in this way, then this change might not be useful.
Thanks!