Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use conan with CMake to generate multi-config Visual Studio Solution Files? #3517

Open
1 task done
RochaStratovan opened this issue Jan 19, 2024 · 2 comments
Open
1 task done
Assignees
Milestone

Comments

@RochaStratovan
Copy link

What is your question?

Hello,

We have a sizeable C/C++ code base that uses CMake to generate multi-config solution files for Windows, as well as single config make file for Linux. Our company is split pretty evenly between Linux and Windows developers.

We would like to use Conan for package management and integration with GitLab. I've worked through the examples, and I'm stuck on one issue. How do I use Conan with CMake to generate a multi-configuration Visual Studio solution file that allows me to select any of the configurations and compile?

Here is the problem I noticed. I worked through the tutorial's Build a simple CMake project using Conan demo.

Following the instructions, I created a Visual Studio solution file that would compile when using the command line cmake --build . --config Release or the Visual Studio IDE set to Release.

I noticed the VS IDE still had the selector for Debug and RelWithDebInfo, so I tried compiling Debug, and it failed saying it couldn't find zlib.h file. I used the VS IDE and quickly saw that the extra include paths and link libraries for Debug weren't set.

This makes sense, because I only configured Release, but I cannot find any documentation that explains how to get it to work with both Release and Debug at the same time.

I found the tutorial page "Building for multiple configurations: Release, Debug, Static and Shared", but this page explains how to change configuration, essentially meaning a separate solution file per configuration.

How can I use conan to to install the desired dependencies: Release and Debug and then run cmake to use the installed Release and Debug dependencies?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@RochaStratovan
Copy link
Author

I continued to play around with this and I found that the following steps appear to do what I want:

conan install . --output-folder=build --build=missing --settings=build_type=Release
conan install . --output-folder=build --build=missing --settings=build_type=Debug
conan install . --output-folder=build --build=missing --settings=build_type=RelWithDebInfo
cd build
cmake .. -G "Visual Studio 15 2017" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake

However, I don't see this actually documentation that approves or sanctions this, but I recall wording in the introduction that I interpreted to say, "if it's not documented, it can be broken at any time by a new release."

@memsharded memsharded self-assigned this Jan 20, 2024
@memsharded
Copy link
Member

Hi @RochaStratovan

Your steps are completely correct.
We try to describe about configurations in https://docs.conan.io/2/tutorial/consuming_packages/different_configurations.html, but it is true that it is not that explicit this for Visual Studio multi-configuration projects

In other parts like https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/build_project_cmake_presets.html#examples-tools-cmake-toolchain-build-project-presets it describes

We can call conan install to install both Release and Debug configurations. Conan will generate a conan_toolchain.cmake at the corresponding generators folder:

$ conan install .
$ conan install . -s build_type=Debug

To install both configurations first

I am moving this ticket to the docs repo to try to improve this, thanks for the feedback!

@memsharded memsharded transferred this issue from conan-io/conan Jan 20, 2024
@memsharded memsharded added this to the 2 milestone Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants