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).
This commit is contained in:
parent
9a1254063a
commit
cd42fc5cc8
4 changed files with 176 additions and 12 deletions
|
@ -122,7 +122,19 @@ def platform_toolset_ver(self):
|
|||
@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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue