Skip to content

Commit

Permalink
[boost] Fix test package on macOS when *:shared=True (#16348)
Browse files Browse the repository at this point in the history
* Use cmake support for testing boost package

Signed-off-by: Uilian Ries <[email protected]>

* Revert "Use cmake support for testing boost package"

This reverts commit 3e3f74a.

* avoid conanrun

Signed-off-by: Uilian Ries <[email protected]>

* boost test package: use build env when invoking ctest on non-windows platforms

* boost test package: add comment with clarification

* boost test package: add disable new dtags on Linux

---------

Signed-off-by: Uilian Ries <[email protected]>
Co-authored-by: Luis Caro Campos <[email protected]>
  • Loading branch information
uilianries and jcar87 authored Mar 3, 2023
1 parent 793485a commit cab2db2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions recipes/boost/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
15 changes: 12 additions & 3 deletions recipes/boost/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit cab2db2

Please sign in to comment.