From cd42fc5cc8dfda473643f40d359fc3d68d7906fb Mon Sep 17 00:00:00 2001 From: "John W. Parent" <45471568+johnwparent@users.noreply.github.com> Date: Tue, 14 Mar 2023 19:46:49 -0400 Subject: Libogg and libtheora: build on windows (#35099) Adds builders appropriate for building these packages on Windows. It is intended that builds on other platforms are unaffected (e.g. they build with Autotools as before on Linux). --- lib/spack/spack/compilers/msvc.py | 14 ++- var/spack/repos/builtin/packages/libogg/package.py | 37 +++++++- .../libtheora/libtheora-inc-external-ogg.patch | 35 +++++++ .../repos/builtin/packages/libtheora/package.py | 102 +++++++++++++++++++-- 4 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 var/spack/repos/builtin/packages/libtheora/libtheora-inc-external-ogg.patch diff --git a/lib/spack/spack/compilers/msvc.py b/lib/spack/spack/compilers/msvc.py index 7a8432ecfa..9be10b0826 100644 --- a/lib/spack/spack/compilers/msvc.py +++ b/lib/spack/spack/compilers/msvc.py @@ -122,7 +122,19 @@ class Msvc(Compiler): @property def cl_version(self): """Cl toolset version""" - return spack.compiler.get_compiler_version_output(self.cc) + return Version( + re.search( + Msvc.version_regex, + spack.compiler.get_compiler_version_output(self.cc, version_arg=None), + ).group(1) + ) + + @property + def vs_root(self): + # The MSVC install root is located at a fix level above the compiler + # and is referenceable idiomatically via the pattern below + # this should be consistent accross versions + return os.path.abspath(os.path.join(self.cc, "../../../../../../../..")) def setup_custom_environment(self, pkg, env): """Set environment variables for MSVC using the diff --git a/var/spack/repos/builtin/packages/libogg/package.py b/var/spack/repos/builtin/packages/libogg/package.py index c0fad6bbf3..c82794e9ba 100644 --- a/var/spack/repos/builtin/packages/libogg/package.py +++ b/var/spack/repos/builtin/packages/libogg/package.py @@ -3,10 +3,13 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +import os + +from spack.build_systems.generic import GenericBuilder from spack.package import * -class Libogg(AutotoolsPackage): +class Libogg(CMakePackage, AutotoolsPackage, Package): """Ogg is a multimedia container format, and the native file and stream format for the Xiph.org multimedia codecs.""" @@ -24,3 +27,35 @@ class Libogg(AutotoolsPackage): sha256="0f4d289aecb3d5f7329d51f1a72ab10c04c336b25481a40d6d841120721be485", when="@1.3.4 platform=darwin", ) + build_system( + conditional("cmake", when="@1.3.4:"), + conditional("generic", when="@1.3.2 platform=windows"), + "autotools", + default="autotools", + ) + + +class GenericBuilder(GenericBuilder): + phases = ["build", "install"] + + def is_64bit(self): + return "64" in self.pkg.spec.target.family + + def build(self, spec, prefix): + if spec.satisfies("%msvc"): + plat_tools = self.pkg.compiler.msvc_version + else: + raise RuntimeError("Package does not support non MSVC compilers on Windows") + ms_build_args = ["libogg_static.vcxproj", "/p:PlatformToolset=v%s" % plat_tools] + msbuild(*ms_build_args) + + def install(self, spec, prefix): + mkdirp(prefix.include.ogg) + mkdirp(prefix.lib) + mkdirp(prefix.share) + install( + os.path.join(self.pkg.stage.source_path, "include", "ogg", "*.h"), prefix.include.ogg + ) + plat_prefix = "x64" if self.is_64bit() else "x86" + install(os.path.join(plat_prefix, "Debug", "*.lib"), prefix.lib) + install_tree(os.path.join(self.pkg.stage.source_path, "doc"), prefix.share) diff --git a/var/spack/repos/builtin/packages/libtheora/libtheora-inc-external-ogg.patch b/var/spack/repos/builtin/packages/libtheora/libtheora-inc-external-ogg.patch new file mode 100644 index 0000000000..fd88480e7c --- /dev/null +++ b/var/spack/repos/builtin/packages/libtheora/libtheora-inc-external-ogg.patch @@ -0,0 +1,35 @@ +diff --git a/win32/VS2008/libogg.vsprops b/win32/VS2008/libogg.vsprops +index 1355b50..8b3c5b8 100644 +--- a/win32/VS2008/libogg.vsprops ++++ b/win32/VS2008/libogg.vsprops +@@ -6,11 +6,11 @@ + > + + +