Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] CONAN_CMAKE_SYSTEM_PROCESSOR is not applied #9736

Closed
madebr opened this issue Oct 5, 2021 · 2 comments
Closed

[bug] CONAN_CMAKE_SYSTEM_PROCESSOR is not applied #9736

madebr opened this issue Oct 5, 2021 · 2 comments

Comments

@madebr
Copy link
Contributor

madebr commented Oct 5, 2021

The CONAN_CMAKE_SYSTEM_PROCESSOR environment variable is not applied to a cmake build,
instead CMAKE_SYSTEM_PROCESSOR is set to self.settings.arch.

Reading the documentation about cmake related environment variables, it seems to me that by settings the CONAN_CMAKE_SYSTEM_PROCESSOR, the cmake variable CMAKE_SYSTEM_PROCESSOR will be set automatically.

The following script reproduces my problem/question:

#!/usr/bin/sh

cd /tmp

cat >buildreq.py <<EOF
from conans import ConanFile

class BuildReq(ConanFile):
    name = "buildreq"
    version = "0.1"
    def package_info(self):
        self.env_info.CONAN_CMAKE_SYSTEM_PROCESSOR = "awesomecpu"
EOF

cat >consumer.py <<EOF
from conans import CMake, ConanFile, tools
import textwrap

class Consumer(ConanFile):
    name = "consumer"
    version = "0.1"
    generators = "cmake"
    def build_requirements(self):
        self.build_requires("buildreq/0.1")
    def build(self):
        tools.save("CMakeLists.txt", textwrap.dedent("""\
            cmake_minimum_required(VERSION 3.0)
            project(consumer C)
            include("\${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
            conan_basic_setup()
            message(STATUS "CMAKE_SYSTEM_PROCESSOR: \${CMAKE_SYSTEM_PROCESSOR}")
            message(STATUS "CONAN_CMAKE_SYSTEM_PROCESSOR: \$ENV{CONAN_CMAKE_SYSTEM_PROCESSOR}")
        """))
        cmake = CMake(self)
        cmake.configure()
EOF

conan create buildreq.py -tf None
conan create consumer.py -tf None

The output of the cmake configure step is:

-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- CONAN_CMAKE_SYSTEM_PROCESSOR: awesomecpu

Where I expect it to contain awesomecpu twice.

The Android NDK requires setting CMAKE_SYSTEM_PROCESSOR to a known and valid architecture.
I added CONAN_CMAKE_SYSTEM_PROCESSOR to the android-ndk recipe in conan-io/conan-center-index#7474,
but it looks to me that conan is missing functionality here.

@martin-schulze-vireso
Copy link
Contributor

martin-schulze-vireso commented Nov 30, 2021

I dug a bit deeper into conan to see where this invalid setting is coming from and I think I found what is described here to be the culprit (emphasis mine):

If user_toolchain is not defined and Conan detects it is cross-building, because the build and host profiles contain different OS or architecture, it will try to define the following variables:
[...]
CMAKE_SYSTEM_PROCESSOR: tools.cmake.cmaketoolchain:system_processor conf if defined, otherwise arch setting (host) if defined

system_name, system_version, system_processor = self._get_cross_build()
return {"compiler": compiler,
"toolset": toolset,
"generator_platform": generator_platform,
"build_type": build_type,
"cmake_system_name": system_name,
"cmake_system_version": system_version,
"cmake_system_processor": system_processor}

With _get_cross_build containing

system_processor = self._conanfile.conf["tools.cmake.cmaketoolchain:system_processor"]

and if hasattr(self._conanfile, "settings_build"):

if system_name is not None and system_processor is None:
if arch != arch_build:
system_processor = arch

so arch (host) is taken.

CONAN_CMAKE_SYSTEM_PROCESSOR is used in

cmake_system_processor = os.getenv("CONAN_CMAKE_SYSTEM_PROCESSOR")

@memsharded
Copy link
Member

Closing as outdated, referring to legacy generators removed in 2.0

@memsharded memsharded closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants