Skip to content

libsodium: conan2 compatibility with msvc #14959

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

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions recipes/libsodium/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from conan.tools.files import export_conandata_patches, apply_conandata_patches, get, rmdir, copy, rm, replace_in_file
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, MSBuildDeps, MSBuildToolchain, MSBuild, VCVars, unix_path, msvc_runtime_flag, vs_layout
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, MSBuildDeps, MSBuildToolchain, MSBuild, VCVars, unix_path, vs_layout
import os

required_conan_version = ">=1.52.0"
required_conan_version = ">=1.53.0"


class LibsodiumConan(ConanFile):
Expand All @@ -17,7 +17,6 @@ class LibsodiumConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://doc.libsodium.org/"
topics = "encryption", "signature", "hashing"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand Down Expand Up @@ -49,18 +48,9 @@ def config_options(self):

def configure(self):
if self.options.shared:
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
if is_msvc(self):
Expand Down Expand Up @@ -118,31 +108,30 @@ def source(self):

@property
def _msvc_sln_folder(self):
if self.settings.compiler == "Visual Studio":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess str(self.settings.compiler) == "Visual Studio" would also work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably so

Copy link
Contributor

@SpaceIm SpaceIm Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are other checks like that afterwards, so it requires more modifications in this method.

Copy link
Contributor

@SpaceIm SpaceIm Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace by something like this:

    @property
    def _msvc_sln_folder(self):
        sln_folders = {
            "Visual Studio": {
                "10": "vs2010",
                "11": "vs2012",
                "12": "vs2013",
                "14": "vs2015",
                "15": "vs2017",
                "16": "vs2019",
            },
            "msvc": {
                "170": "vs2012",
                "180": "vs2013",
                "190": "vs2015",
                "191": "vs2017",
                "192": "vs2019",
            }
        }
        if self.version != "1.0.18":
            sln_folders["Visual Studio"]["17"] = "vs2022"
            sln_folders["msvc"]["193"] = "vs2022"

        backup_folder = "vs2022" if self.version != "1.0.18" else "vs2019"

        return sln_folders.get(str(self.settings.compiler), {}).get(str(self.settings.compiler.version), backup_folder)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely right, I did this quickly and didn't check it further. Thank you for the code suggestion

folder = {
sln_folders = {
"Visual Studio": {
"10": "vs2010",
"11": "vs2012",
"12": "vs2013",
"14": "vs2015",
"15": "vs2017",
"16": "vs2019",
}
elif self.settings.compiler == "msvc":
folder = {
},
"msvc": {
"170": "vs2012",
"180": "vs2013",
"190": "vs2015",
"191": "vs2017",
"192": "vs2019",
}
else:
raise ConanException("Should not call this function with any other compiler")

}
if self.version != "1.0.18":
if self.settings.compiler == "Visual Studio":
folder["17"] = "vs2022"
else:
folder["193"] = "vs2022"
sln_folders["Visual Studio"]["17"] = "vs2022"
sln_folders["msvc"]["193"] = "vs2022"

backup_folder = "vs2022" if self.version != "1.0.18" else "vs2019"

return folder.get(str(self.settings.compiler.version))
return sln_folders.get(str(self.settings.compiler), {}).get(str(self.settings.compiler.version), backup_folder)

@property
def _msvc_platform(self):
Expand Down