Skip to content

Commit

Permalink
implement better workaround for lack of robustness in interaction bet…
Browse files Browse the repository at this point in the history
…ween MSBuild & MSBuildToolchain
  • Loading branch information
SpaceIm committed Dec 31, 2022
1 parent 4e0dc05 commit 3b69354
Showing 1 changed file with 12 additions and 40 deletions.
52 changes: 12 additions & 40 deletions recipes/libsodium/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def source(self):
def generate(self):
if is_msvc(self):
tc = MSBuildToolchain(self)
tc.configuration = "{}{}".format(
"Debug" if self.settings.build_type == "Debug" else "Release",
"DLL" if self.options.shared else "LIB",
)
tc.generate()
else:
env = VirtualBuildEnv(self)
Expand Down Expand Up @@ -134,55 +138,23 @@ def _build_msvc(self):
f"<PlatformToolset>{toolset}</PlatformToolset>",
)

# FIXME: There is currently no guarantee from new MSBuild helper that props files
# TODO: to remove once https://github.com/conan-io/conan/pull/12817 available in conan client.
# There is currently no guarantee from new MSBuild helper that props files
# generated by MSBuildToolchain and MSBuildDeps have precedence over custom values of project.
# Therefore conantoolchain.props is injected manually before Microsoft.Cpp.Default.props like it was done
# with /p:ForceImportBeforeCppTargets in legacy MSBuild helper.
# see:
# - https://learn.microsoft.com/en-us/cpp/build/modify-project-properties-without-changing-project-file
# - https://github.com/conan-io/conan/issues/12155
conantoolchain_props = os.path.join(self.generators_folder, "conantoolchain.props")
# So for the moment, conantoolchain.props is injected manually to emulate
# /p:ForceImportBeforeCppTargets=<path/to/conantoolchain.props>
conantoolchain_props = os.path.join(self.generators_folder, MSBuildToolchain.filename)
replace_in_file(
self, vcxproj_path,
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />",
f"<Import Project=\"{conantoolchain_props}\" />\n<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />",
"<Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.targets\" />",
f"<Import Project=\"{conantoolchain_props}\" /><Import Project=\"$(VCTargetsPath)\Microsoft.Cpp.targets\" />",
)

# Honor runtime library from profile
runtime_library = MSBuildToolchain(self).runtime_library
for prop_file, runtime_library_old in [
("DebugDEXE.props", "MultiThreadedDebugDLL"),
("DebugDLL.props", "MultiThreadedDebugDLL"),
("DebugLEXE.props", "MultiThreadedDebug"),
("DebugLIB.props", "MultiThreadedDebug"),
("DebugLTCG.props", "MultiThreadedDebug"),
("DebugSEXE.props", "MultiThreadedDebug"),
("ReleaseDEXE.props", "MultiThreadedDLL"),
("ReleaseDLL.props", "MultiThreadedDLL"),
("ReleaseLEXE.props", "MultiThreaded"),
("ReleaseLIB.props", "MultiThreaded"),
("ReleaseLTCG.props", "MultiThreaded"),
("ReleaseSEXE.props", "MultiThreaded"),
]:
replace_in_file(
self, os.path.join(msvc_builds_folder, "properties", prop_file),
f"<RuntimeLibrary>{runtime_library_old}</RuntimeLibrary>",
f"<RuntimeLibrary>{runtime_library}</RuntimeLibrary>",
)

msbuild = MSBuild(self)
build_type = "{}{}".format(
msbuild.build_type = "{}{}".format(
"Dyn" if self.options.shared else "Static",
"Debug" if self.settings.build_type == "Debug" else "Release",
)

platform = {
"x86": "Win32",
"x86_64": "x64",
}[str(self.settings.arch)]

msbuild.build_type = build_type
msbuild.platform = platform
msbuild.build(os.path.join(msvc_sln_folder, "libsodium.sln"))

def build(self):
Expand Down

0 comments on commit 3b69354

Please sign in to comment.