conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.24k stars 980 forks source link

[question] How should CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM actually work? #11577

Open harsszegi opened 2 years ago

harsszegi commented 2 years ago

Hi,

I'm a bit puzzled by the usage of CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM. Generally CMake does a whole lot of dark voodoo magic during the project() call (e.g. setting up CMAKE_AR, CMAKE_C_COMPILER, etc.).

conanbuildinfo.cmake (which practically transforms CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM into CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) on its own is pulled in after project() calls - or at least this is the case for bzip2 and some other recipes.

And this is where I'm completely lost (e.g. for me it appears it happens quite late).

I'd like to do cross compilation with Yocto SDK, where it is mandatory that CMAKE_SYSROOT is not searched for any kind of tools (as those tools are the native tools, not the cross compilation compatible ones).

What is the meaning of CONAN_CMAKE_FIND_ROOT*? And how should they be used so that the project() call already sees the changed (by Conan) values?

Thanks,

harsszegi commented 2 years ago

Can someone make me understand this code snippet?

        # system processor
        cmake_system_processor = os.getenv("CONAN_CMAKE_SYSTEM_PROCESSOR")
        if cmake_system_processor:
            definitions["CMAKE_SYSTEM_PROCESSOR"] = cmake_system_processor

        if definitions:  # If enabled cross compile
            for env_var in ["CONAN_CMAKE_FIND_ROOT_PATH",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
                            "CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"]:

                value = os.getenv(env_var)
                if value:
                    definitions[env_var] = value

_cmake_cross_build_defines generally converts the CONAN prefixed CMake variables into "native" CMake ones. Why are the CMAKE_FIND_ROOT_PATH ones exceptions? E.g. why are they transfered to CMake as -DCONANCMAKE variables and not regular CMAKE_* variables? Thanks,

harsszegi commented 2 years ago

Just a sidenote, I have replaced

definitions[env_var] = value

with

definitions[env_var.replace("CONAN_", "", 1)] = value

And for me it fixed cross compilation perfectly, e.g. as both CMAKE_FIND_ROOT_PATH_MODE_PROGRAM and CMAKE_SYSROOT were preset properly, cross compiliation tools were found properly and everything compiled fine. Also it means that conan_set_find_paths can be simplified (as there is no need to set the CMAKE_FIND_ROOT* variables there anymore