diff --git a/conan/tools/build/cross_building.py b/conan/tools/build/cross_building.py index 9602d6f0fbb..0e92ace864c 100644 --- a/conan/tools/build/cross_building.py +++ b/conan/tools/build/cross_building.py @@ -1,9 +1,7 @@ def cross_building(conanfile=None, skip_x64_x86=False): - host_os = conanfile.settings.get_safe("os") - host_arch = conanfile.settings.get_safe("arch") - build_os = conanfile.settings_build.get_safe('os') - build_arch = conanfile.settings_build.get_safe('arch') + + build_os, build_arch, host_os, host_arch = get_cross_building_settings(conanfile) if skip_x64_x86 and host_os is not None and (build_os == host_os) and \ host_arch is not None and ((build_arch == "x86_64") and (host_arch == "x86") or @@ -18,3 +16,15 @@ def cross_building(conanfile=None, skip_x64_x86=False): return False + +def get_cross_building_settings(conanfile): + # FIXME: Develop2 this shouldn't go in develop2 where the build settings always exists + # Keep the current develop2 implementation for the whole module while merging + os_host = conanfile.settings.get_safe("os") + arch_host = conanfile.settings.get_safe("arch") + + if hasattr(conanfile, 'settings_build'): + return (conanfile.settings_build.get_safe('os'), conanfile.settings_build.get_safe('arch'), + os_host, arch_host) + else: + return os_host, arch_host, os_host, arch_host diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index 00618103b05..e033137d445 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -10,7 +10,7 @@ from conan.tools.build import build_jobs from conan.tools.cmake.toolchain import CONAN_TOOLCHAIN_FILENAME from conan.tools.cmake.utils import is_multi_configuration -from conan.tools.cross_building import cross_building +from conan.tools.build.cross_building import cross_building from conan.tools.intel import IntelCC from conan.tools.microsoft.visual import is_msvc from conans.errors import ConanException diff --git a/conan/tools/cross_building.py b/conan/tools/cross_building.py deleted file mode 100644 index cb89a144615..00000000000 --- a/conan/tools/cross_building.py +++ /dev/null @@ -1,28 +0,0 @@ - -def cross_building(conanfile=None, skip_x64_x86=False): - - build_os, build_arch, host_os, host_arch = get_cross_building_settings(conanfile) - - if skip_x64_x86 and host_os is not None and (build_os == host_os) and \ - host_arch is not None and ((build_arch == "x86_64") and (host_arch == "x86") or - (build_arch == "sparcv9") and (host_arch == "sparc") or - (build_arch == "ppc64") and (host_arch == "ppc32")): - return False - - if host_os is not None and (build_os != host_os): - return True - if host_arch is not None and (build_arch != host_arch): - return True - - return False - - -def get_cross_building_settings(conanfile): - os_host = conanfile.settings.get_safe("os") - arch_host = conanfile.settings.get_safe("arch") - - if hasattr(conanfile, 'settings_build'): - return (conanfile.settings_build.get_safe('os'), conanfile.settings_build.get_safe('arch'), - os_host, arch_host) - else: - return os_host, arch_host, os_host, arch_host diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index f06bc384576..97f5d3d172b 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -3,7 +3,7 @@ build_type_link_flags from conan.tools.apple.apple import apple_min_version_flag, to_apple_arch, \ apple_sdk_path -from conan.tools.cross_building import cross_building, get_cross_building_settings +from conan.tools.build.cross_building import cross_building, get_cross_building_settings from conan.tools.env import Environment from conan.tools.files.files import save_toolchain_args from conan.tools.gnu.get_gnu_triplet import _get_gnu_triplet diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py index b9da955f593..4f3880e3e4d 100644 --- a/conan/tools/meson/toolchain.py +++ b/conan/tools/meson/toolchain.py @@ -4,7 +4,7 @@ from conan.tools._check_build_profile import check_using_build_profile from conan.tools.apple.apple import to_apple_arch, is_apple_os, apple_min_version_flag -from conan.tools.cross_building import cross_building, get_cross_building_settings +from conan.tools.build.cross_building import cross_building, get_cross_building_settings from conan.tools.env import VirtualBuildEnv from conan.tools.meson.helpers import * from conan.tools.microsoft import VCVars, msvc_runtime_flag diff --git a/conans/assets/templates/new_v2_cmake.py b/conans/assets/templates/new_v2_cmake.py index ba2b6125228..891d1634c62 100644 --- a/conans/assets/templates/new_v2_cmake.py +++ b/conans/assets/templates/new_v2_cmake.py @@ -1,4 +1,4 @@ -conanfile_sources_v2 = """from conans import ConanFile +conanfile_sources_v2 = """from conan import ConanFile from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout @@ -48,8 +48,9 @@ def package_info(self): test_conanfile_v2 = """import os -from conans import ConanFile, tools +from conan import ConanFile from conan.tools.cmake import CMake, cmake_layout +from conan.tools.build import cross_building class {package_name}TestConan(ConanFile): @@ -58,6 +59,10 @@ class {package_name}TestConan(ConanFile): # (it will be defined in Conan 2.0) generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv", "VirtualRunEnv" apply_env = False + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -68,7 +73,7 @@ def layout(self): cmake_layout(self) def test(self): - if not tools.cross_building(self): + if not cross_building(self): cmd = os.path.join(self.cpp.build.bindirs[0], "example") self.run(cmd, env="conanrun") """ @@ -219,7 +224,7 @@ def get_cmake_lib_files(name, version, package_name="Pkg"): return files -conanfile_exe = """from conans import ConanFile +conanfile_exe = """from conan import ConanFile from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout @@ -263,15 +268,13 @@ def package(self): add_executable({name} src/{name}.cpp src/main.cpp) target_include_directories({name} PUBLIC include) -install(TARGETS {name} DESTINATION "." - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - ) +install(TARGETS {name}) """ test_conanfile_exe_v2 = """import os -from conans import ConanFile, tools +from conan import ConanFile +from conan.tools.build import cross_building +from conan.tools.layout import basic_layout class {package_name}TestConan(ConanFile): @@ -280,9 +283,16 @@ class {package_name}TestConan(ConanFile): # (it will be defined in Conan 2.0) generators = "VirtualRunEnv" apply_env = False + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + basic_layout(self) def test(self): - if not tools.cross_building(self): + if not cross_building(self): self.run("{name}", env="conanrun") """ diff --git a/conans/test/assets/cmake.py b/conans/test/assets/cmake.py index 08cd07813d1..b61ef68556f 100644 --- a/conans/test/assets/cmake.py +++ b/conans/test/assets/cmake.py @@ -75,19 +75,10 @@ def gen_cmakelists(language="CXX", verify=True, project="project", libname="myli {% if install %} {% if appsources %} - install(TARGETS {{appname}} DESTINATION ".") + install(TARGETS {{appname}}) {% endif %} {% if libsources %} - install(TARGETS {{libname}} DESTINATION "." - {% if public_header %} - PUBLIC_HEADER DESTINATION include - {% endif %} - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - FRAMEWORK DESTINATION Frameworks - BUNDLE DESTINATION bin - ) + install(TARGETS {{libname}}) {% endif %} {% endif %} """) diff --git a/conans/test/functional/toolchains/cmake/test_ninja.py b/conans/test/functional/toolchains/cmake/test_ninja.py index 9faea4a059d..a506bc59ff4 100644 --- a/conans/test/functional/toolchains/cmake/test_ninja.py +++ b/conans/test/functional/toolchains/cmake/test_ninja.py @@ -79,7 +79,7 @@ def test_locally_build_linux(build_type, shared, client): assert "main: {}!".format(build_type) in client.out client.run("install hello/1.0@ -g=deploy -if=mydeploy {}".format(settings)) ldpath = os.path.join(client.current_folder, "mydeploy", "hello", "lib") - client.run_command("LD_LIBRARY_PATH='{}' ./mydeploy/hello/myapp".format(ldpath)) + client.run_command("LD_LIBRARY_PATH='{}' ./mydeploy/hello/bin/myapp".format(ldpath)) check_exe_run(client.out, ["main", "hello"], "gcc", None, build_type, "x86_64", cppstd=None) @@ -111,7 +111,7 @@ def test_locally_build_msvc(build_type, shared, client): assert 'cmake -G "Ninja"' in client.out assert "main: {}!".format(build_type) in client.out client.run("install hello/1.0@ -g=deploy -if=mydeploy {}".format(settings)) - client.run_command(r"mydeploy\hello\myapp.exe") + client.run_command(r"mydeploy\hello\bin\myapp.exe") check_exe_run(client.out, ["main", "hello"], "msvc", "19", build_type, "x86_64", cppstd="14")