Skip to content

Commit

Permalink
dcmtk: fix macOS build with host_arch=x86_64 & build_arch=arm64
Browse files Browse the repository at this point in the history
Requires rosetta & `tools.build.cross_building:can_run=True`
  • Loading branch information
mayeut committed Dec 28, 2023
1 parent fada8c5 commit a5cc508
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions recipes/dcmtk/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.build import can_run, cross_building
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir, save
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
Expand Down Expand Up @@ -118,12 +118,17 @@ def validate(self):
self.settings.os == "Macos" and self.settings.arch == "armv8":
# FIXME: Probable issue with flags, build includes header 'mmintrin.h'
raise ConanInvalidConfiguration("Cross building to Macos M1 is not supported (yet)")
if hasattr(self, "settings_build") and cross_building(self) and \
self.settings.os == "Macos" and self.settings.arch == "x86_64" and not can_run(self):
raise ConanInvalidConfiguration("Cross building to macOS x86_64 is only supported from macOS arm64 using rosetta with 'tools.build.cross_building:can_run=True'")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
if cross_building(self) and can_run(self):
tc.variables["CMAKE_CROSSCOMPILING_EMULATOR"] = ""
# DICOM Data Dictionaries are required
tc.variables["CMAKE_INSTALL_DATADIR"] = self._dcm_datadictionary_path.replace("\\", "/")
tc.cache_variables["DCMTK_USE_FIND_PACKAGE"] = True
Expand Down Expand Up @@ -193,7 +198,12 @@ def _collect_cmake_required(self, host_dependency):

def _patch_sources(self):
apply_conandata_patches(self)

replace_in_file(
self,
os.path.join(self.source_folder, "CMake", "dcmtkTryRun.cmake"),
"if(CMAKE_CROSSCOMPILING)",
"if(CMAKE_CROSSCOMPILING AND NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR)",
)
# Workaround for CMakeDeps bug with check_* like functions.
# See https://github.com/conan-io/conan/issues/12012 & https://github.com/conan-io/conan/issues/12180
if self.options.with_openssl:
Expand Down

0 comments on commit a5cc508

Please sign in to comment.