Minimal example using CMake and Conan to cross-build with CMake toolchain files.
Problem: The CMake toolchain file is not sufficient for cross-building. An additional Conan profile file must be specified for the host.
Is it possible to infer the Conan profile from the CMake toolchain file settings?
Goals:
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain-armv7.cmake ..
make
conan_cmake_run(
CONANFILE conanfile.txt
BASIC_SETUP
PROFILE ${CMAKE_SOURCE_DIR}/profile-armv7.conan # <- neccessary?
PROFILE_AUTO ALL
BUILD missing
)
It's possible. Link to issue: https://github.com/conan-io/cmake-conan/issues/307
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
)