diff options
author | John W. Parent <45471568+johnwparent@users.noreply.github.com> | 2023-03-14 19:46:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 16:46:49 -0700 |
commit | cd42fc5cc8dfda473643f40d359fc3d68d7906fb (patch) | |
tree | 387c7b1d6f18f7e02936c32c3ccb2e2c950165d5 /var | |
parent | 9a1254063a9e1c2fcd137359c82a7c6ba753c123 (diff) | |
download | spack-cd42fc5cc8dfda473643f40d359fc3d68d7906fb.tar.gz spack-cd42fc5cc8dfda473643f40d359fc3d68d7906fb.tar.bz2 spack-cd42fc5cc8dfda473643f40d359fc3d68d7906fb.tar.xz spack-cd42fc5cc8dfda473643f40d359fc3d68d7906fb.zip |
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).
Diffstat (limited to 'var')
3 files changed, 163 insertions, 11 deletions
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 @@ + > + <Tool + Name="VCCLCompilerTool" +- AdditionalIncludeDirectories=""..\..\..\..\libogg-$(LIBOGG_VERSION)\include";..\..\..\..\ogg\include;..\..\..\..\..\..\..\core\ogg\libogg\include" ++ AdditionalIncludeDirectories="$(SPACK_OGG_PREFIX)\include;"..\..\..\..\libogg-$(LIBOGG_VERSION)\include";..\..\..\..\ogg\include;..\..\..\..\..\..\..\core\ogg\libogg\include" + /> + <Tool + Name="VCLinkerTool" +- AdditionalLibraryDirectories=""..\..\..\..\libogg-$(LIBOGG_VERSION)\win32\VS2008\$(PlatformName)\$(ConfigurationName)";"..\..\..\..\ogg\win32\VS2008\$(PlatformName)\$(ConfigurationName)";"..\..\..\..\..\..\..\core\ogg\libogg\win32\VS2008\$(PlatformName)\$(ConfigurationName)"" ++ AdditionalLibraryDirectories="$(SPACK_OGG_PREFIX)\lib;"..\..\..\..\libogg-$(LIBOGG_VERSION)\win32\VS2008\$(PlatformName)\$(ConfigurationName)";"..\..\..\..\ogg\win32\VS2008\$(PlatformName)\$(ConfigurationName)";"..\..\..\..\..\..\..\core\ogg\libogg\win32\VS2008\$(PlatformName)\$(ConfigurationName)"" + /> + <UserMacro + Name="LIBOGG_VERSION" +diff --git a/win32/VS2008/libtheora_static.sln b/win32/VS2008/libtheora_static.sln +index 2b39635..fa40518 100644 +--- a/win32/VS2008/libtheora_static.sln ++++ b/win32/VS2008/libtheora_static.sln +@@ -1,12 +1,8 @@ + + Microsoft Visual Studio Solution File, Format Version 10.00 + # Visual Studio 2008 +-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dump_video_static", "dump_video\dump_video_static.vcproj", "{1A8CA99D-B6C7-48CB-B263-6CECDADF5FBF}" +-EndProject + Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtheora_static", "libtheora\libtheora_static.vcproj", "{653F3841-3F26-49B9-AFCF-091DB4B67031}" + EndProject +-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "encoder_example_static", "encoder_example\encoder_example_static.vcproj", "{AD710263-EBFA-4388-BAA9-AD73C32AFF26}" +-EndProject + Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 diff --git a/var/spack/repos/builtin/packages/libtheora/package.py b/var/spack/repos/builtin/packages/libtheora/package.py index 280d838bdd..5d3f181272 100644 --- a/var/spack/repos/builtin/packages/libtheora/package.py +++ b/var/spack/repos/builtin/packages/libtheora/package.py @@ -3,10 +3,16 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +import glob +import os +import sys + +from spack.build_systems.autotools import AutotoolsBuilder +from spack.build_systems.msbuild import MSBuildBuilder from spack.package import * -class Libtheora(AutotoolsPackage): +class Libtheora(AutotoolsPackage, MSBuildPackage): """Theora Video Compression.""" homepage = "https://www.theora.org" @@ -17,13 +23,25 @@ class Libtheora(AutotoolsPackage): variant("doc", default=False, description="Build documentation") - depends_on("autoconf", type="build") - depends_on("automake", type="build") - depends_on("libtool", type="build") - depends_on("m4", type="build") depends_on("doxygen", when="+doc", type="build") depends_on("libogg") depends_on("libpng") + with when("build_system=autotools"): + depends_on("autoconf", type="build") + depends_on("automake", type="build") + depends_on("libtool", type="build") + depends_on("m4", type="build") + + with when("platform=windows"): + variant( + "static", + default=True, + description="Enable static build, if false shared library is built", + ) + + build_system( + "msbuild", "autotools", default="autotools" if sys.platform != "win32" else "msbuild" + ) patch("exit-prior-to-running-configure.patch", when="@1.1.1") patch("fix_encoding.patch", when="@1.1:") @@ -32,15 +50,79 @@ class Libtheora(AutotoolsPackage): sha256="8b1f256fa6bfb4ce1355c5be1104e8cfe695c8484d8ea19db06c006880a02298", when="^libpng@1.6:", ) + patch("libtheora-inc-external-ogg.patch", when="platform=windows") + - def autoreconf(self, spec, prefix): +class AutotoolsBuilder(AutotoolsBuilder): + def configure_args(self): + args = [] + args += self.enable_or_disable("doc") + return args + + def autoreconf(self, pkg, spec, prefix): sh = which("sh") if self.spec.satisfies("target=aarch64:"): sh("./autogen.sh", "prefix={0}".format(prefix), "--build=arm-linux") else: sh("./autogen.sh", "prefix={0}".format(prefix)) - def configure_args(self): - args = [] - args += self.enable_or_disable("doc") - return args + +class MSBuildBuilder(MSBuildBuilder): + def is_64bit(self): + return "64" in self.pkg.spec.target.family + + def setup_build_environment(self, env): + spec = self.pkg.spec + env.set("SPACK_OGG_PREFIX", spec["libogg"].prefix) + # devenv is needed to convert ancient MSbuild project to modern + # msbuild project so MSBuild versions older than 2010 can build this + # project + devenv_path = os.path.join(self.pkg.compiler.vs_root, "Common7", "IDE") + env.prepend_path("PATH", devenv_path) + + @property + def build_directory(self): + win_dir = os.path.join(super().build_directory, "win32") + vs_dir = "VS2008" + return os.path.join(win_dir, vs_dir) + + @property + def sln_file(self): + if self.pkg.spec.satisfies("+static"): + f = "libtheora_static.sln" + else: + f = "libtheora_dynamic.sln" + return f + + def msbuild_args(self): + return [self.define("Configuration", "Release"), self.sln_file] + + def build(self, pkg, spec, prefix): + with working_dir(self.build_directory): + devenv = Executable("devenv") + devenv(self.sln_file, "/Upgrade") + super().build(pkg, spec, prefix) + + def install(self, pkg, spec, prefix): + mkdirp(prefix.lib) + libs_to_install = glob.glob( + os.path.join(self.build_directory, "**", "*.lib"), recursive=True + ) + if self.pkg.spec.satisfies("~static"): + libs_to_install.extend( + glob.glob(os.path.join(self.build_directory, "**", "*.dll"), recursive=True) + ) + for library in libs_to_install: + install(library, prefix.lib) + rename( + os.path.join(prefix.lib, "libtheora_static.lib"), + os.path.join(prefix.lib, "theora.lib"), + ) + # The encoder and decoder libs are baked into the theora lib on Windows, so we spoof them + # here so libtheora is detectable by CMake and pkg-config and linkable by + # consuming projects + with working_dir(prefix.lib): + copy("theora.lib", "theoradec.lib") + copy("theora.lib", "theoraenc.lib") + with working_dir(pkg.stage.source_path): + install_tree("include", prefix.include) |