diff --git a/recipes/boost/all/test_package/CMakeLists.txt b/recipes/boost/all/test_package/CMakeLists.txt index 769ce4cdc3ba2..d3d62d560560c 100644 --- a/recipes/boost/all/test_package/CMakeLists.txt +++ b/recipes/boost/all/test_package/CMakeLists.txt @@ -1,6 +1,13 @@ cmake_minimum_required(VERSION 3.15) project(test_package LANGUAGES CXX) +if(UNIX AND NOT APPLE) + # use RPATH instead of RUNPATH so that + # transitive dependencies can be located + add_link_options("LINKER:--disable-new-dtags") +endif() + +include(CTest) enable_testing() if(BOOST_NAMESPACE) diff --git a/recipes/boost/all/test_package/conanfile.py b/recipes/boost/all/test_package/conanfile.py index 66ee2b0e2d276..de19d7acf2aa4 100644 --- a/recipes/boost/all/test_package/conanfile.py +++ b/recipes/boost/all/test_package/conanfile.py @@ -3,12 +3,11 @@ from conan.tools.build import can_run from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout from conan.tools.files import chdir -from conan.tools.scm import Version class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "VirtualRunEnv" + generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv" test_type = "explicit" def _boost_option(self, name, default): @@ -59,4 +58,14 @@ def test(self): if not can_run(self): return with chdir(self, self.folders.build_folder): - self.run(f"ctest --output-on-failure -C {self.settings.build_type}", env="conanrun") + # When boost and its dependencies are built as shared libraries, + # the test executables need to locate them. Typically the + # `conanrun` env should be enough, but this may cause problems on macOS + # where the CMake installation has dependencies on Apple-provided + # system libraries that are incompatible with Conan-provided ones. + # When `conanrun` is enabled, DYLD_LIBRARY_PATH will also apply + # to ctest itself. Given that CMake already embeds RPATHs by default, + # we can bypass this by using the `conanbuild` environment on + # non-Windows platforms, while still retaining the correct behaviour. + env = "conanrun" if self.settings.os == "Windows" else "conanbuild" + self.run(f"ctest --output-on-failure -C {self.settings.build_type}", env=env)