question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infer Conan profile from CMake toolchain file for cross-building?

See original GitHub issue

I try to integrate Conan in a CMake project using CMake toolchain files for cross-building.

The only way I could get it working was creating an additional Conan profile file matching the toolchain file settings. I wonder if it’s possible to infer those information from the CMake toolchain file to simply (cross-)building:

conan_cmake_run(
    CONANFILE conanfile.txt
    BASIC_SETUP
    PROFILE ${CMAKE_SOURCE_DIR}/profile-armv7.conan  # <- neccessary?
    PROFILE_AUTO ALL
    BUILD missing
)

I created a small example project to showcase the current state and goals: https://github.com/lukasberbuer/cmake-conan-crossbuild

PS: I’m pretty new to Conan and very impressed so far - solves a lot of problems for me. Great project!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lukasberbuercommented, Jan 24, 2021

@uyha: It seems to work, thanks! I updated the repository with your recommended solution.

The arch variable needs to be specified in the CMake toolchain file:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CONAN_ARCHITECTURE armv7)
...

Everything else can be derived from CMake. The Conan profile file is not necessary any more:

if(CMAKE_CROSSCOMPILING AND NOT CONAN_ARCHITECTURE)
    message(FATAL_ERROR "The variable CONAN_ARCHITECTURE must be specified for cross-compiling")
endif()

conan_cmake_run(
    CONANFILE conanfile.txt
    BASIC_SETUP
    ARCH ${CONAN_ARCHITECTURE}
    ENV CC=${CMAKE_C_COMPILER}
    ENV CXX=${CMAKE_CXX_COMPILER}
    ENV CFLAGS=${CMAKE_C_FLAGS}
    ENV CXXFLAGS=${CMAKE_CXX_FLAGS}
    PROFILE_AUTO ALL
    BUILD missing
)
1reaction
gabyxcommented, Mar 28, 2022

Note: Beware of strange paths on Windows:

ENV CC=${CMAKE_C_COMPILER}

I think these should be native patchs with cmake_path(NATIVE CMAKE_C_COMPILER NORMALIZE cc) like ENV CC=${cc} but ninja, still has troubles when this resolves to something C:/Program Files which is treaded as

"C:/Program" "Files" in Ninja…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross building — conan 1.56.0 documentation
Using a profile: install the toolchain in your computer and use a profile to declare the settings and point to the needed tools/libraries...
Read more >
Conanfile settings when cross-compiling with CMake and ...
I found I can set this in the [env] section of the profile, using CONAN_CMAKE_TOOLCHAIN_FILE , but it is not considered in settings...
Read more >
Untitled
A CMake toolchain file is most often used for cross-compilation. ... was creating an additional Conan profile file matching the toolchain file settings....
Read more >
Packaging C/C++ dependencies with Conan
from conans import ConanFile, CMake ... cmake. 22 conanfile.txt. Conan 101: Consuming packages ... conan create . theo/stable --profile clang5-debug.
Read more >
Formula Install On Request Events (365 days)
#1919, null-dev/firefox-profile-switcher/firefox-profile-switcher-connector ... #2689, messense/macos-cross-toolchains/x86_64-unknown-linux-gnu, 1,440, 0%.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found