conan-io / conan-vs-extension

Conan Extension for Visual Studio
https://marketplace.visualstudio.com/items?itemName=conan-io.conan-vs-extension
MIT License
59 stars 34 forks source link

[Question] How to configure compilation options #245

Closed Jeanmilost closed 12 hours ago

Jeanmilost commented 3 days ago

I'm converting several VS2019 project which used Conan to VS2022. To achieve that I installed the Conan2 package management, and the Conan VS extension.

With Conan 1 I needed to configure a text file which contained the libraries to install, alongside with several important options. Below is one of the files I was using:

[requires]
libcurl/8.1.1
boost/1.84.0
cryptopp/8.9.0
zlib/1.3.1
minizip/1.3.1
miniz/3.0.2
libjpeg/9e
nlohmann_json/3.11.3
sqlite3/3.45.2
libraw/0.21.2
libpng/1.6.43

[options]
libcurl:with_ssl=schannel
zlib:shared=False
libraw:with_jasper=False

Now with Conan 2 I could generate the same dependencies, from the VS extension:

# This file is managed by the Conan Visual Studio Extension, contents will be overwritten.
# To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements
requirements:
- libcurl/8.6.0
- boost/1.85.0
- cryptopp/8.9.0
- zlib/1.3.1
- minizip/1.3.1
- miniz/3.0.2
- libjpeg/9e
- libpng/1.6.43
- nlohmann_json/3.11.3
- sqlite3/3.45.2
- libraw/0.21.2

When I start to compile, the below configuration file is also generated automatically from the VS extension:

[settings]
arch=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=20
compiler.runtime=static

compiler.runtime_type=Debug
compiler.version=193
os=Windows

However there is an issue: The [options] block of the first Conan configuration file is completely discarded. In my case, this cause my compilation to fail while libraw is compiled, because it tries to include jasper in the middle, and this result to the following errors:

... 1> jp2_enc.c 1> jpc_bs.c 1> jpc_cs.c 1> jpc_cod.c 1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\vcruntime_c11_stdatomic.h(36,24): error C2061: syntax error: identifier 'atomicbool' [C:\Users\jean.conan2\p\b\jaspe4294a4f9c147f\b\build\src\libjasper\libjasper.vcxproj] 1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\vcruntime_c11stdatomic.h(36,24): error C2059: syntax error: ';' [C:\Users\jean.conan2\p\b\jaspe4294a4f9c147f\b\build\src\libjasper\libjasper.vcxproj] 1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\vcruntime_c11_stdatomic.h(37,23): error C2061: syntax error: identifier 'atomicchar' [C:\Users\jean.conan2\p\b\jaspe4294a4f9c147f\b\build\src\libjasper\libjasper.vcxproj] 1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\vcruntime_c11stdatomic.h(37,23): error C2059: syntax error: ';' [C:\Users\jean.conan2\p\b\jaspe4294a4f9c147f\b\build\src\libjasper\libjasper.vcxproj] 1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\vcruntime_c11_stdatomic.h(38,30): error C2061: syntax error: identifier 'atomicschar' [C:\Users\jean.conan2\p\b\jaspe4294a4f9c147f\b\build\src\libjasper\libjasper.vcxproj] ...

On a previous Conan VS extension version, I could at least add this [options] block manually in the configuration file, which allowed to compile the dependencies successfully. But with the latest version, the file is regenerated automatically, and all my options are removed, causing the build to fail.

On the other hand, I searched the correct way to configure these options, but I couldn't find how to achieve that.

Here are the options I need to add:

[options]
libcurl:with_ssl=schannel
zlib:shared=False
libraw:with_jasper=False

Can you please either tell me how to configure these options, or add a way to achieve that?

memsharded commented 1 day ago

Hi @Jeanmilost

Thanks for your question.

The previous conanfile.txt has been replaced in this one by conanfile.py and conandata.yml.

You can define your options in your conanfile.py, mostly with the default_options (https://docs.conan.io/2/reference/conanfile/attributes.html#default-options) you can define values for your dependencies such as {"zlib/*:shared": False} for example. Note in Conan 2 it is necessary to define patterns like zlib/*:shared, not just zlib:shared.

AbrilRBS commented 1 day ago

Note thay you will need to remove the comment guard for the extension not to overwrite your local conanfile.py changes :)

Jeanmilost commented 12 hours ago

@memsharded @AbrilRBS Thank you very much. This worked for me and resolved the issue.

memsharded commented 12 hours ago

Thanks for the feedback! Closing as solved then.