3

This is a simple need of selecting build type when calling conan build.

Normally we have to call conan install with the desired build type and then conan build with the following commands :

conan install conanfile.py install -s build_type=Debug
conan build conanfile.py

I have seen that we can force conan to do an install with the build command using --intall. I have tried the following command but it does not update the settings.build_type value.

conan build conanfile.py --install -s build_type=Release

Does any one have an idea how to change the build type with conan build command or at least pass a variables to be checked later in the conanfile.py

Thanks in advance

John McFarlane
  • 5,528
  • 4
  • 34
  • 38

1 Answers1

2

The conan build command will use whatever configuration was provided to the conan install command. So the way to change configuration (settings, options, etc) is to do a conan install with the right configuration.

When a conan install command is executed it will create information about dependencies for the current configuration (profile, settings, options), and will generate files as conanbuildinfo.cmake as defined by the Conan generators. The conan build command will use those files to find the right dependencies binaries for that configuration. Trying to conan build with a different configuration without updating the dependencies generated files will typically result in compile or link errors for using the incorrect dependencies binaries.

drodri
  • 5,157
  • 15
  • 21
  • Keeping in mind the `cmake_layout()`, which creates `build/Release` and `build/Debug` folders: If we call `conan install` twice, for example first calling `conan install` with a debug profile and then with a release profile, we could have two conanbuildinfo.cmake generated. Wouldn't it then be possible to build for the specified `build_type` using `conan build`? Currently, calling `conan build .` will still use the build_type that was set during the latest call to conan install, regardless of what is passed to `conan build`. – evolved Sep 08 '22 at 22:09
  • ``cmake_layout()`` is a modern feature, that should go together with the new build system integrations, like ``CMakeDeps`` and ``CMakeToolchain`` generators, but it will not work with the legacy ``cmake`` generator (the one generating ``conanbuildinfo.cmake``) – drodri Sep 09 '22 at 07:52
  • Sorry I forgot to mention that we use already the new `CMakeDeps` and `CMakeToolchain` generators but `conan build .` will still build the configuration that was last used during `conan install`. Does conan take this information from `conanbuildinfo.txt`? And will it be possible to set the `build_type` during `conan build . -s build_type=Release/Debug` or is this feature not planned/possible? Thanks – evolved Sep 09 '22 at 12:39
  • 1
    Then, better create a new issue (typically better in Github), because this one is unrelated, it is talking about a different generator. Conan 2.0 indeed will take settings as parameter to ``conan build``, but not yet in 1.X – drodri Sep 10 '22 at 17:21
  • Thanks drodri, is this also somewhere documented in the documentation that conan 1.X doesn't yet consider the settings as parameter to `conan build`? – evolved Sep 14 '22 at 11:48
  • Well, it doesn't document the absences of parameters that exist in future versions, indeed, but the docs of ``conan build`` should show that this argument doesn't exist. – drodri Sep 15 '22 at 12:56