Skip to content

Commit

Permalink
Make cross.toolchain_file optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Jul 24, 2023
1 parent e5f389d commit 2f974cb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/py_build_cmake/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,17 @@ def get_cmaker(pkg_dir: Path, install_dir: Optional[Path], cmake_cfg: dict,
native_install_dir: Optional[Path],
package_info: PackageInfo, **kwargs):
# Optionally include the cross-compilation settings
cross_opts = {k: None for k in
('toolchain_file', 'python_prefix', 'python_library')}
if cross_cfg:
cross_compiling = True
cross_opts = {
'toolchain_file': cross_cfg.get('toolchain_file'),
'python_prefix': cross_cfg.get('prefix'),
'python_library': cross_cfg.get('library'),
}
else:
cross_compiling = False
cross_keys = 'toolchain_file', 'python_prefix', 'python_library'
cross_opts = {k: None for k in cross_keys}

# Add some CMake configure options
options = cmake_cfg.get('options', {})
Expand Down Expand Up @@ -557,6 +560,7 @@ def get_cmaker(pkg_dir: Path, install_dir: Optional[Path], cmake_cfg: dict,
args=cmake_cfg.get('args', []),
preset=cmake_cfg.get('preset'),
generator=cmake_cfg.get('generator'),
cross_compiling=cross_compiling,
**cross_opts,
),
build_settings=cmake.CMakeBuildSettings(
Expand Down
3 changes: 2 additions & 1 deletion src/py_build_cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CMakeConfigureSettings:
args: List[str]
preset: Optional[str]
generator: Optional[str]
cross_compiling: bool
toolchain_file: Optional[Path]
python_prefix: Optional[Path]
python_library: Optional[Path]
Expand Down Expand Up @@ -85,7 +86,7 @@ def prepare_environment(self):
return self.environment

def cross_compiling(self) -> bool:
return self.conf_settings.toolchain_file is not None
return self.conf_settings.cross_compiling

def get_configure_options_package(self) -> List[str]:
"""Flags specific to py-build-cmake, useful in the user's CMake scripts."""
Expand Down
2 changes: 1 addition & 1 deletion src/py_build_cmake/pyproject_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_options(project_path: Path, *, test: bool = False):
"https://cmake.org/cmake/help/book/mastering-cmake"
"/chapter/Cross%20Compiling%20With%20CMake.html for "
"more information.",
default=RequiredValue(),
default=NoDefaultValue(),
base_path=RelativeToCurrentConfig(project_path),
must_exist=not test,
allow_abs=True,
Expand Down
1 change: 0 additions & 1 deletion src/py_build_cmake/quirks/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def cross_compile_win(config: ConfigNode, plat_name, library_dirs, cmake_platfor
assert not config.contains('cross')
cross_cfg = {
'os': 'windows',
'toolchain_file': '',
'arch': platform_to_platform_tag(plat_name),
'cmake': {
'options': {
Expand Down

0 comments on commit 2f974cb

Please sign in to comment.