-
Notifications
You must be signed in to change notification settings - Fork 27
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
lagrange/cmake/lagrange/lagrange_find_package.cmake
Lines 44 to 49 in b3f4080
| # https://github.com/AcademySoftwareFoundation/openvdb/issues/1630 | |
| if(NOT BUILD_SHARED_LIBS) | |
| find_package(blosc CONFIG REQUIRED) | |
| find_package(ZLIB REQUIRED) | |
| target_link_libraries(OpenVDB::openvdb INTERFACE blosc_static ZLIB::ZLIB) | |
| endif() |
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 variable.
The minimal reproducing example is
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 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()