diff --git a/src/py_build_cmake/build.py b/src/py_build_cmake/build.py index f8c3ae3..fb466a6 100644 --- a/src/py_build_cmake/build.py +++ b/src/py_build_cmake/build.py @@ -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', {}) @@ -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( diff --git a/src/py_build_cmake/cmake.py b/src/py_build_cmake/cmake.py index 0755b22..0e65062 100644 --- a/src/py_build_cmake/cmake.py +++ b/src/py_build_cmake/cmake.py @@ -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] @@ -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.""" diff --git a/src/py_build_cmake/pyproject_options.py b/src/py_build_cmake/pyproject_options.py index 99e7c03..8562a46 100644 --- a/src/py_build_cmake/pyproject_options.py +++ b/src/py_build_cmake/pyproject_options.py @@ -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, diff --git a/src/py_build_cmake/quirks/config.py b/src/py_build_cmake/quirks/config.py index 59bd4c3..62a540b 100644 --- a/src/py_build_cmake/quirks/config.py +++ b/src/py_build_cmake/quirks/config.py @@ -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': {