Skip to content

Commit 3b69354

Browse files
committed
implement better workaround for lack of robustness in interaction between MSBuild & MSBuildToolchain
1 parent 4e0dc05 commit 3b69354

File tree

1 file changed

+12
-40
lines changed

1 file changed

+12
-40
lines changed

recipes/libsodium/all/conanfile.py

Lines changed: 12 additions & 40 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)
@@ -134,55 +138,23 @@ def _build_msvc(self):
134138
f"<PlatformToolset>{toolset}</PlatformToolset>",
135139
)
136140

137-
# FIXME: There is currently no guarantee from new MSBuild helper that props files
141+
# TODO: to remove once https://github.com/conan-io/conan/pull/12817 available in conan client.
142+
# There is currently no guarantee from new MSBuild helper that props files
138143
# 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")
144+
# So for the moment, conantoolchain.props is injected manually to emulate
145+
# /p:ForceImportBeforeCppTargets=<path/to/conantoolchain.props>
146+
conantoolchain_props = os.path.join(self.generators_folder, MSBuildToolchain.filename)
145147
replace_in_file(
146148
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\" />",
149+
"<Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.targets\" />",
150+
f"<Import Project=\"{conantoolchain_props}\" /><Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.targets\" />",
149151
)
150152

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-
)
172-
173153
msbuild = MSBuild(self)
174-
build_type = "{}{}".format(
154+
msbuild.build_type = "{}{}".format(
175155
"Dyn" if self.options.shared else "Static",
176156
"Debug" if self.settings.build_type == "Debug" else "Release",
177157
)
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
186158
msbuild.build(os.path.join(msvc_sln_folder, "libsodium.sln"))
187159

188160
def build(self):

0 commit comments

Comments
 (0)