CMake configuration error with user provided OpenVDB
- Dominant language
- C++
- Stars
- 298
- Forks
- 30
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
If the user provides OpenVDB package prior including lagrange, it will trigger an error during CMake configuration step (version 3.31.6)
```
[cmake] CMake Error at build/_deps/lagrange-src/cmake/lagrange/lagrange_find_package.cmake:48 (target_link_libraries):
[cmake] Cannot specify link libraries for target "OpenVDB::openvdb" which is not
[cmake] built by this project.
```
from lines
https://github.com/adobe/lagrange/blob/b3f4080cf039c043d7024a78b0a3e42ea1379dec/cmake/lagrange/lagrange_find_package.cmake#L44-L49
because it seems `GLOBAL` target allows for modifying properties of the imported target.
> https://cmake.org/cmake/help/latest/command/find_package.html#basic-signature
> Added in version 3.24: Specifying the GLOBAL keyword will promote all imported targets to a global scope in the importing project. Alternatively, this functionality can be enabled by setting the [CMAKE_FIND_PACKAGE_TARGETS_GLOBAL](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_PACKAGE_TARGETS_GLOBAL.html#variable:CMAKE_FIND_PACKAGE_TARGETS_GLOBAL) variable.
The minimal reproducing example is
```cmake
cmake_minimum_required(VERSION 3.31)
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()
project(test_lagrange VERSION 0.1.0 LANGUAGES C CXX)
find_package(OpenVDB CONFIG REQUIRED)
# find_package(OpenVDB CONFIG REQUIRED GLOBAL) # Workaround
include(FetchContent)
FetchContent_Declare(lagrange GIT_REPOSITORY https://github.com/adobe/lagrange.git GIT_TAG v6.34.0 GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(lagrange)
lagrange_include_modules(volume)
```
Actually, I wonder what is the "right" CMake way around `find_package` with GLOBAL or not. It seems that there is even a [CMake default option](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_PACKAGE_TARGETS_GLOBAL.html) to put them all GLOBAL but off by default.
To make is work without the user knowing might be wrapping (all) `find_package` in `lagrange_find_package` by `if(NOT TARGET) ... endif()`
Contributor guide
Assessment
This issue has not been assessed yet.