Reputation: 692
Conan does not auto-detect MinGW compiler while creating package. Please refer below error:
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
ERROR: : 'settings.compiler' value not defined
Upvotes: 3
Views: 6237
Reputation: 514
using the conan dev packages you can install msys2 or mingw64.
Conan has setup some bins you can clone via build requires. These work like pre-requisites meaning any machine that uses the conan profile with these will get them installed. This would mean you would get another self container mingw, and msys inside your conan packages (home/.conan/data/ blah blah).
[build_requires]
mingw_installer/1.0@conan/stable
msys2/20190524
[settings]
os_build=Windows
os=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=4.9
compiler.libcxx=libstdc++11
compiler.threads=posix
build_type=Release
Credits to AvadhanaSolutions
The reason that it is not working is because not only does the toolchain need to be set for gcc,g++ but also the target and generator need to be defined. This needs to be clear to both conan, and cmake. In this case cmake cannot find these toolchains.
Given that the recommended install locations for mingw and msys binaries are to not place in "Program Files". The install location is variable from one person to the next. Given that variability we need to ensure two things to generate successful builds. The following would not only apply for gcc but also for other tools like clang
Steps
Find path for gcc,g++, and make for your machine.
(careful to ensure that you have the full names)
#!/bin/bash
echo "Find Gcc,G++ and mingw make then append these to a conan profile"
which gcc
which g++
which make
Which will return something like
/c/msys64/mingw64/bin/gcc
/c/msys64/mingw64/bin/g++
/c/msys64/usr/bin/make
Add environment variables to the conan install profile.
(ie my conan file has)
[env]
CC=C:/msys64/mingw64/bin/gcc
CXX=C:/msys64/mingw64/bin/g++
Define the Generator for Cmake. Here we need to setup the equivalent to the CMake command cmake .. -G "MinGW Makefiles
. By default conan uses Unix Makefiles unless your running windows ;) then it just uses whatever cmake applies as the default generator. Therefore, if you want to use mingw make files that needs to be defined and passed to cmake manually. (found this in the conan documentation here. But note that the conanfile on that page is somewhat incomplete. In the end you have to add other elements from your default conan profile to the conan profile you will be using for building to target the MinGw platform using the mingw toolchain.
toolchain=C:/msys64/mingw64/bin
target_host=x86_64-w64-mingw32
cc_compiler=gcc
cxx_compiler=g++
[env]
CONAN_CMAKE_FIND_ROOT_PATH=$toolchain
CHOST=$target_host
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
STRIP=$target_host-strip
RC=$target_host-windres
[settings]
#We are cross-building to Window
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
build_type=Release
compiler.libcxx=libstdc++11
compiler.cppstd=20
compiler.version=10
[options]
[env]
CC=C:/msys64/mingw64/bin/gcc
CXX=C:/msys64/mingw64/bin/g++
Note that the CC, and CXX toolchain variables are duplicative, but I honestly don't care. I want to tell windows and cmake in as many ways as possible to use those.
In the end, it is probably easiest to think of this as "Cross Compiling" because the default installs of cmake, path variables, and the windows platform is not setup to compile using non-windows compilers. This page (newer) from conan describes how this can be defined on a windows machine. There is a bit of background at the top, but it is helpful to understand the landscape of what is going on between these tools.
In the end... after all of this, I am going to take a look at ninja because it appears that it will improve my quality of life. I am also going to switch to a conanfile.py instead of a conanfile.txt because the documentation is better for these.
Upvotes: 4
Reputation: 692
The issue can be resolved by updating default profile or create a new profile for MinGW.
conan profile update settings.compiler=gcc /path/to/profile
conan profile update settings.compiler.version=9.2 /path/to/profile
conan profile update settings.compiler.libcxx=libstdc++11 /path/to/profile
[build_requires]
mingw_installer/1.0@conan/stable
msys2/20190524
[settings]
os_build=Windows
os=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=4.9
compiler.libcxx=libstdc++11
compiler.threads=posix
build_type=Release
Note: You need to add MinGW/bin path in windows environment. Developer can choose compiler version as per their installation.
Upvotes: 1