Skip to content

Commit 69cba0e

Browse files
committed
honor runtime from profile
1 parent 1dfcdb2 commit 69cba0e

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

recipes/libsodium/all/conanfile.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,53 @@ def _msvc_sln_folder(self):
123123
def _build_msvc(self):
124124
msvc_builds_folder = os.path.join(self.source_folder, "builds", "msvc")
125125
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")
126127

127128
# 1.0.18 only supported up to vs2019. Add support for newer toolsets.
128129
if self.version == "1.0.18" and self._msvc_sln_folder == "vs2019":
129130
toolset = MSBuildToolchain(self).toolset
130131
replace_in_file(
131-
self, os.path.join(msvc_sln_folder, "libsodium", "libsodium.vcxproj"),
132-
f"<PlatformToolset>v142</PlatformToolset>",
132+
self, vcxproj_path,
133+
"<PlatformToolset>v142</PlatformToolset>",
133134
f"<PlatformToolset>{toolset}</PlatformToolset>",
134135
)
135136

136-
# There is no automagic interaction between MSBuildToolchain & MSBuild helper,
137-
# props file generated by MSBuildToolchain must be manually injected by any means.
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
138144
conantoolchain_props = os.path.join(self.generators_folder, "conantoolchain.props")
139145
replace_in_file(
140-
self, os.path.join(msvc_builds_folder, "properties", "Common.props"),
141-
"<ImportGroup Label=\"PropertySheets\">",
142-
f"<ImportGroup Label=\"PropertySheets\"><Import Project=\"{conantoolchain_props}\" />",
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\" />",
143149
)
144150

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+
145173
msbuild = MSBuild(self)
146174
build_type = "{}{}".format(
147175
"Dyn" if self.options.shared else "Static",

0 commit comments

Comments
 (0)