Skip to content

Commit 4a2cbbb

Browse files
committed
implement better workaround for the lack of automatic interaction between MSBuild & MSBuildToolchain
1 parent 4e0dc05 commit 4a2cbbb

File tree

1 file changed

+14
-48
lines changed

1 file changed

+14
-48
lines changed

recipes/libsodium/all/conanfile.py

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def source(self):
7676
def generate(self):
7777
if is_msvc(self):
7878
tc = MSBuildToolchain(self)
79+
tc.configuration = "{}{}".format(
80+
"Debug" if self.settings.build_type == "Debug" else "Release",
81+
"DLL" if self.options.shared else "LIB",
82+
)
7983
tc.generate()
8084
else:
8185
env = VirtualBuildEnv(self)
@@ -121,68 +125,30 @@ def _msvc_sln_folder(self):
121125
return sln_folders.get(str(self.settings.compiler), {}).get(str(self.settings.compiler.version), default_folder)
122126

123127
def _build_msvc(self):
124-
msvc_builds_folder = os.path.join(self.source_folder, "builds", "msvc")
125-
msvc_sln_folder = os.path.join(msvc_builds_folder, self._msvc_sln_folder)
126-
vcxproj_path = os.path.join(msvc_sln_folder, "libsodium", "libsodium.vcxproj")
128+
msvc_sln_folder = os.path.join(self.source_folder, "builds", "msvc", self._msvc_sln_folder)
127129

128-
# 1.0.18 only supported up to vs2019. Add support for newer toolsets.
130+
#==============================
131+
# TODO: to remove once https://github.com/conan-io/conan/pull/12817 available in conan client
129132
if self.version == "1.0.18" and self._msvc_sln_folder == "vs2019":
130133
toolset = MSBuildToolchain(self).toolset
131134
replace_in_file(
132-
self, vcxproj_path,
135+
self, os.path.join(msvc_sln_folder, "libsodium", "libsodium.vcxproj"),
133136
"<PlatformToolset>v142</PlatformToolset>",
134137
f"<PlatformToolset>{toolset}</PlatformToolset>",
135138
)
136-
137-
# FIXME: There is currently no guarantee from new MSBuild helper that props files
138-
# generated by MSBuildToolchain and MSBuildDeps have precedence over custom values of project.
139-
# Therefore conantoolchain.props is injected manually before Microsoft.Cpp.Default.props like it was done
140-
# with /p:ForceImportBeforeCppTargets in legacy MSBuild helper.
141-
# see:
142-
# - https://learn.microsoft.com/en-us/cpp/build/modify-project-properties-without-changing-project-file
143-
# - https://github.com/conan-io/conan/issues/12155
144-
conantoolchain_props = os.path.join(self.generators_folder, "conantoolchain.props")
139+
conantoolchain_props = os.path.join(self.generators_folder, MSBuildToolchain.filename)
145140
replace_in_file(
146-
self, vcxproj_path,
147-
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />",
148-
f"<Import Project=\"{conantoolchain_props}\" />\n<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />",
141+
self, os.path.join(msvc_sln_folder, "libsodium", "libsodium.vcxproj"),
142+
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />",
143+
f"<Import Project=\"{conantoolchain_props}\" /><Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />",
149144
)
150-
151-
# Honor runtime library from profile
152-
runtime_library = MSBuildToolchain(self).runtime_library
153-
for prop_file, runtime_library_old in [
154-
("DebugDEXE.props", "MultiThreadedDebugDLL"),
155-
("DebugDLL.props", "MultiThreadedDebugDLL"),
156-
("DebugLEXE.props", "MultiThreadedDebug"),
157-
("DebugLIB.props", "MultiThreadedDebug"),
158-
("DebugLTCG.props", "MultiThreadedDebug"),
159-
("DebugSEXE.props", "MultiThreadedDebug"),
160-
("ReleaseDEXE.props", "MultiThreadedDLL"),
161-
("ReleaseDLL.props", "MultiThreadedDLL"),
162-
("ReleaseLEXE.props", "MultiThreaded"),
163-
("ReleaseLIB.props", "MultiThreaded"),
164-
("ReleaseLTCG.props", "MultiThreaded"),
165-
("ReleaseSEXE.props", "MultiThreaded"),
166-
]:
167-
replace_in_file(
168-
self, os.path.join(msvc_builds_folder, "properties", prop_file),
169-
f"<RuntimeLibrary>{runtime_library_old}</RuntimeLibrary>",
170-
f"<RuntimeLibrary>{runtime_library}</RuntimeLibrary>",
171-
)
145+
#==============================
172146

173147
msbuild = MSBuild(self)
174-
build_type = "{}{}".format(
148+
msbuild.build_type = "{}{}".format(
175149
"Dyn" if self.options.shared else "Static",
176150
"Debug" if self.settings.build_type == "Debug" else "Release",
177151
)
178-
179-
platform = {
180-
"x86": "Win32",
181-
"x86_64": "x64",
182-
}[str(self.settings.arch)]
183-
184-
msbuild.build_type = build_type
185-
msbuild.platform = platform
186152
msbuild.build(os.path.join(msvc_sln_folder, "libsodium.sln"))
187153

188154
def build(self):

0 commit comments

Comments
 (0)