Skip to content

Commit 96e93b8

Browse files
authored
(#15123) faac: add Visual Studio support + drop 1.28
* drop 1.28 * add msvc support * more explicit message if static & drm & msvc
1 parent a2275fb commit 96e93b8

File tree

6 files changed

+220
-37
lines changed

6 files changed

+220
-37
lines changed

recipes/faac/all/conandata.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ sources:
22
"1.30":
33
url: "https://github.com/knik0/faac/archive/1_30.tar.gz"
44
sha256: "adc387ce588cca16d98c03b6ec1e58f0ffd9fc6eadb00e254157d6b16203b2d2"
5-
"1.28":
6-
url: "https://github.com/knik0/faac/archive/refs/tags/faac1_28.tar.gz"
7-
sha256: "fec821797a541e8359f086fef454b947a7f7246fe8ec6207668968b86606a7dd"
85
patches:
96
"1.30":
10-
- patch_file: "patches/001-fix-out-of-root-build.patch"
7+
- patch_file: "patches/1.30-0001-fix-out-of-root-build.patch"
118
patch_description: "Fix out of root build"
129
patch_source: "https://github.com/knik0/faac/commit/c8d12a5c7c5b6f1c4593f0a6c1eeceacc4d7c941.patch"
1310
patch_type: "conan"
11+
- patch_file: "patches/1.30-0002-dont-hardcode-x86.patch"
12+
patch_description: "Allow to build for x86_64"
13+
patch_type: "portability"
14+
- patch_file: "patches/1.30-0003-relax-windows-sdk.patch"
15+
patch_description: "Don't constrain Windows SDK"
16+
patch_type: "portability"

recipes/faac/all/conanfile.py

Lines changed: 99 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from conan.errors import ConanInvalidConfiguration
33
from conan.tools.apple import fix_apple_shared_install_name
44
from conan.tools.env import VirtualBuildEnv
5-
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
5+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rename, replace_in_file, rm, rmdir
66
from conan.tools.gnu import Autotools, AutotoolsToolchain
77
from conan.tools.layout import basic_layout
8-
from conan.tools.microsoft import is_msvc
8+
from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain
99
from conan.tools.scm import Version
1010
import os
1111

@@ -46,6 +46,14 @@ def _settings_build(self):
4646
def _has_mp4_option(self):
4747
return Version(self.version) < "1.29.1"
4848

49+
@property
50+
def _msbuild_configuration(self):
51+
return "Debug" if self.settings.build_type == "Debug" else "Release"
52+
53+
@property
54+
def _sln_folder(self):
55+
return os.path.join(self.source_folder, "project", "msvc")
56+
4957
def export_sources(self):
5058
export_conandata_patches(self)
5159

@@ -70,54 +78,114 @@ def requirements(self):
7078

7179
def validate(self):
7280
if is_msvc(self):
73-
# FIXME: add msvc support since there are MSBuild files upstream
74-
raise ConanInvalidConfiguration("libfaac conan-center recipe doesn't support building with Visual Studio yet")
81+
if self.settings.arch not in ["x86", "x86_64"]:
82+
raise ConanInvalidConfiguration(f"{self.ref} only supports x86 and x86_64 with Visual Studio")
83+
if self.options.drm and not self.options.shared:
84+
raise ConanInvalidConfiguration(f"{self.ref} with drm support can't be built as static with Visual Studio")
7585
if self.options.get_safe("with_mp4"):
7686
# TODO: as mpv4v2 as a conan package
7787
raise ConanInvalidConfiguration("building with mp4v2 is not supported currently")
7888

7989
def build_requirements(self):
80-
self.tool_requires("libtool/2.4.7")
81-
if self._settings_build.os == "Windows":
82-
self.win_bash = True
83-
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
84-
self.tool_requires("msys2/cci.latest")
90+
if not is_msvc(self):
91+
self.tool_requires("libtool/2.4.7")
92+
if self._settings_build.os == "Windows":
93+
self.win_bash = True
94+
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
95+
self.tool_requires("msys2/cci.latest")
8596

8697
def source(self):
8798
get(self, **self.conan_data["sources"][self.version], strip_root=True)
8899

89100
def generate(self):
90-
VirtualBuildEnv(self).generate()
91-
tc = AutotoolsToolchain(self)
92-
yes_no = lambda v: "yes" if v else "no"
93-
tc.configure_args.append(f"--enable-drm={yes_no(self.options.drm)}")
94-
if self._has_mp4_option:
95-
tc.configure_args.append(f"--with-mp4v2={yes_no(self.options.with_mp4)}")
96-
tc.generate()
101+
if is_msvc(self):
102+
tc = MSBuildToolchain(self)
103+
tc.configuration = self._msbuild_configuration
104+
tc.generate()
105+
else:
106+
VirtualBuildEnv(self).generate()
107+
tc = AutotoolsToolchain(self)
108+
yes_no = lambda v: "yes" if v else "no"
109+
tc.configure_args.append(f"--enable-drm={yes_no(self.options.drm)}")
110+
if self._has_mp4_option:
111+
tc.configure_args.append(f"--with-mp4v2={yes_no(self.options.with_mp4)}")
112+
tc.generate()
97113

98114
def build(self):
99115
apply_conandata_patches(self)
100-
autotools = Autotools(self)
101-
autotools.autoreconf()
102-
if self._is_mingw and self.options.shared:
103-
replace_in_file(self, os.path.join(self.build_folder, "libfaac", "Makefile"),
104-
"\nlibfaac_la_LIBADD = ",
105-
"\nlibfaac_la_LIBADD = -no-undefined ")
106-
autotools.configure()
107-
autotools.make()
116+
if is_msvc(self):
117+
#==========================
118+
# TODO: to remove once https://github.com/conan-io/conan/pull/12817 available in conan client
119+
vcxproj_files = ["faac.vcxproj", "libfaac.vcxproj", "libfaac_dll.vcxproj", "libfaac_dll_drm.vcxproj"]
120+
platform_toolset = MSBuildToolchain(self).toolset
121+
conantoolchain_props = os.path.join(self.generators_folder, MSBuildToolchain.filename)
122+
for vcxproj_file in vcxproj_files:
123+
replace_in_file(
124+
self, os.path.join(self._sln_folder, vcxproj_file),
125+
"<PlatformToolset>v141</PlatformToolset>",
126+
f"<PlatformToolset>{platform_toolset}</PlatformToolset>",
127+
)
128+
replace_in_file(
129+
self, os.path.join(self._sln_folder, vcxproj_file),
130+
"<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />",
131+
f"<Import Project=\"{conantoolchain_props}\" /><Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />",
132+
)
133+
#==========================
134+
135+
msbuild = MSBuild(self)
136+
msbuild.build_type = self._msbuild_configuration
137+
msbuild.platform = "Win32" if self.settings.arch == "x86" else msbuild.platform
138+
# Allow to build for other archs than Win32
139+
if self.settings.arch != "x86":
140+
for vc_proj_file in (
141+
"faac.sln", "faac.vcxproj", "libfaac.vcxproj",
142+
"libfaac_dll.vcxproj", "libfaac_dll_drm.vcxproj"
143+
):
144+
replace_in_file(self, os.path.join(self._sln_folder, vc_proj_file), "Win32", msbuild.platform)
145+
targets = ["faac"]
146+
if self.options.drm:
147+
targets.append("libfaac_dll_drm")
148+
else:
149+
targets.append("libfaac_dll" if self.options.shared else "libfaac")
150+
msbuild.build(os.path.join(self._sln_folder, "faac.sln"), targets=targets)
151+
else:
152+
autotools = Autotools(self)
153+
autotools.autoreconf()
154+
if self._is_mingw and self.options.shared:
155+
replace_in_file(self, os.path.join(self.build_folder, "libfaac", "Makefile"),
156+
"\nlibfaac_la_LIBADD = ",
157+
"\nlibfaac_la_LIBADD = -no-undefined ")
158+
autotools.configure()
159+
autotools.make()
108160

109161
def package(self):
110162
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
111-
autotools = Autotools(self)
112-
autotools.install()
113-
rmdir(self, os.path.join(self.package_folder, "share"))
114-
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
115-
fix_apple_shared_install_name(self)
163+
if is_msvc(self):
164+
copy(self, "*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
165+
output_folder = os.path.join(self._sln_folder, "bin", self._msbuild_configuration)
166+
copy(self, "*.exe", src=output_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)
167+
copy(self, "*.dll", src=output_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)
168+
if self.options.drm:
169+
old_libname = "libfaacdrm.lib"
170+
new_libname = "faac_drm.lib"
171+
else:
172+
old_libname = "libfaac_dll.lib" if self.options.shared else "libfaac.lib"
173+
new_libname = "faac.lib"
174+
lib_folder = os.path.join(self.package_folder, "lib")
175+
copy(self, old_libname, src=output_folder, dst=lib_folder, keep_path=False)
176+
rename(self, os.path.join(lib_folder, old_libname), os.path.join(lib_folder, new_libname))
177+
else:
178+
autotools = Autotools(self)
179+
autotools.install()
180+
rmdir(self, os.path.join(self.package_folder, "share"))
181+
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
182+
fix_apple_shared_install_name(self)
116183

117184
def package_info(self):
118-
self.cpp_info.libs = ["faac"]
185+
suffix = "_drm" if self.options.drm else ""
186+
self.cpp_info.libs = [f"faac{suffix}"]
119187
if self.settings.os in ["Linux", "FreeBSD"]:
120188
self.cpp_info.system_libs.append("m")
121189

122-
# TODO: to replace in conan v2
190+
# TODO: to remove in conan v2
123191
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
--- a/project/msvc/faac.vcxproj
2+
+++ b/project/msvc/faac.vcxproj
3+
@@ -66,7 +66,7 @@
4+
<Culture>0x0413</Culture>
5+
</ResourceCompile>
6+
<Link>
7+
- <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
8+
+ <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
9+
<SuppressStartupBanner>true</SuppressStartupBanner>
10+
<GenerateDebugInformation>true</GenerateDebugInformation>
11+
<SubSystem>Console</SubSystem>
12+
@@ -89,7 +89,7 @@
13+
<Culture>0x0413</Culture>
14+
</ResourceCompile>
15+
<Link>
16+
- <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
17+
+ <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
18+
<SuppressStartupBanner>true</SuppressStartupBanner>
19+
<SubSystem>Console</SubSystem>
20+
</Link>
21+
--- a/project/msvc/libfaac_dll.vcxproj
22+
+++ b/project/msvc/libfaac_dll.vcxproj
23+
@@ -61,10 +61,9 @@
24+
<SuppressStartupBanner>true</SuppressStartupBanner>
25+
</ClCompile>
26+
<Link>
27+
- <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
28+
+ <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
29+
<SuppressStartupBanner>true</SuppressStartupBanner>
30+
<ModuleDefinitionFile>.\libfaac.def</ModuleDefinitionFile>
31+
- <TargetMachine>MachineX86</TargetMachine>
32+
</Link>
33+
<PreBuildEvent>
34+
<Message>Retrieving package version...</Message>
35+
@@ -84,11 +83,10 @@
36+
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
37+
</ClCompile>
38+
<Link>
39+
- <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
40+
+ <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
41+
<SuppressStartupBanner>true</SuppressStartupBanner>
42+
<ModuleDefinitionFile>.\libfaac.def</ModuleDefinitionFile>
43+
<GenerateDebugInformation>true</GenerateDebugInformation>
44+
- <TargetMachine>MachineX86</TargetMachine>
45+
</Link>
46+
<PreBuildEvent>
47+
<Message>Retrieving package version...</Message>
48+
--- a/project/msvc/libfaac_dll_drm.vcxproj
49+
+++ b/project/msvc/libfaac_dll_drm.vcxproj
50+
@@ -61,10 +61,9 @@
51+
<SuppressStartupBanner>true</SuppressStartupBanner>
52+
</ClCompile>
53+
<Link>
54+
- <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
55+
+ <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
56+
<SuppressStartupBanner>true</SuppressStartupBanner>
57+
<ModuleDefinitionFile>.\libfaac.def</ModuleDefinitionFile>
58+
- <TargetMachine>MachineX86</TargetMachine>
59+
<ImportLibrary>$(OutDir)libfaacdrm.lib</ImportLibrary>
60+
</Link>
61+
<PreBuildEvent>
62+
@@ -85,11 +84,10 @@
63+
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
64+
</ClCompile>
65+
<Link>
66+
- <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
67+
+ <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
68+
<SuppressStartupBanner>true</SuppressStartupBanner>
69+
<ModuleDefinitionFile>.\libfaac.def</ModuleDefinitionFile>
70+
<GenerateDebugInformation>true</GenerateDebugInformation>
71+
- <TargetMachine>MachineX86</TargetMachine>
72+
<ImportLibrary>$(OutDir)libfaacdrm.lib</ImportLibrary>
73+
</Link>
74+
<PreBuildEvent>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--- a/project/msvc/faac.vcxproj
2+
+++ b/project/msvc/faac.vcxproj
3+
@@ -12,7 +12,6 @@
4+
</ItemGroup>
5+
<PropertyGroup Label="Globals">
6+
<ProjectGuid>{92992E74-AEDE-46DC-AD8C-ADEA876F1A4C}</ProjectGuid>
7+
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
8+
</PropertyGroup>
9+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
10+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
11+
--- a/project/msvc/libfaac.vcxproj
12+
+++ b/project/msvc/libfaac.vcxproj
13+
@@ -13,7 +13,6 @@
14+
<PropertyGroup Label="Globals">
15+
<ProjectName>libfaac</ProjectName>
16+
<ProjectGuid>{9CC48C6E-92EB-4814-AD37-97AB3622AB65}</ProjectGuid>
17+
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
18+
</PropertyGroup>
19+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
21+
--- a/project/msvc/libfaac_dll.vcxproj
22+
+++ b/project/msvc/libfaac_dll.vcxproj
23+
@@ -13,7 +13,6 @@
24+
<PropertyGroup Label="Globals">
25+
<ProjectName>libfaac_dll</ProjectName>
26+
<ProjectGuid>{856BB8CF-B944-4D7A-9D59-4945316229AA}</ProjectGuid>
27+
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
31+
--- a/project/msvc/libfaac_dll_drm.vcxproj
32+
+++ b/project/msvc/libfaac_dll_drm.vcxproj
33+
@@ -13,7 +13,6 @@
34+
<PropertyGroup Label="Globals">
35+
<ProjectName>libfaac_dll_drm</ProjectName>
36+
<ProjectGuid>{AA2D0EFE-E73D-40AD-ADCE-8A2B54F34C6F}</ProjectGuid>
37+
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
38+
</PropertyGroup>
39+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
40+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

recipes/faac/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
versions:
22
"1.30":
33
folder: all
4-
"1.28":
5-
folder: all

0 commit comments

Comments
 (0)