CMake Compatibility with FetchContent - #13311
Conversation
… FetchContent() compatibility
|
Hi @mprat Question, just based on a really quick look:
So, for example, in a file like This evaluated to the |
Not quite - the If you want to get rid of this ambiguity, the |
There was a problem hiding this comment.
Pull Request Overview
This PR updates CMake configuration to improve compatibility with FetchContent by replacing CMAKE_SOURCE_DIR with PROJECT_SOURCE_DIR. This change ensures that when librealsense is used as a dependency via CMake's FetchContent framework, the build system correctly references the project's source directory rather than the parent project's directory.
- Replace
CMAKE_SOURCE_DIRwithPROJECT_SOURCE_DIRacross multiple CMakeLists.txt files - Update include directory paths for Python wrappers, PCL wrappers, C# bindings, and examples
- Modify CMake include statements for OpenGL configuration
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| wrappers/python/CMakeLists.txt | Updates include directories for pybackend2 target to use PROJECT_SOURCE_DIR |
| wrappers/pcl/pcl/CMakeLists.txt | Updates GLFW include directory path for rs-pcl target |
| wrappers/pcl/pcl-color/CMakeLists.txt | Updates GLFW include directory path for rs-pcl-color target |
| wrappers/csharp/Intel.RealSense/CMakeLists.txt | Updates Unity bindings directory reference |
| tools/CMakeLists.txt | Updates OpenGL configuration include path |
| src/gl/CMakeLists.txt | Updates OpenGL configuration include path |
| examples/CMakeLists.txt | Updates OpenGL configuration include path |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Can one of the admins verify this patch? |
|
I've fixed the conflicts with the latest base; I am starting a new project with |
|
@mprat I will try to help you with that. |
|
@mprat since we see no reggresion in our CI I will help and merge it. |

To allow for projects using CMake's
FetchContentframework, instances ofCMAKE_SOURCE_DIRshould be replaced withPROJECT_SOURCE_DIR.FetchContentusesadd_subdirectory()under the cmake hood, and usingCMAKE_SOURCE_DIRcannot be set manually; it is set as the parent project source directory. For correctadd_subdirectory()cmake builds usinglibrealsenseas a dependency, these should be changed toPROJECT_SOURCE_DIR.