2
2
from conan .errors import ConanInvalidConfiguration
3
3
from conan .tools .apple import fix_apple_shared_install_name
4
4
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
6
6
from conan .tools .gnu import Autotools , AutotoolsToolchain
7
7
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
9
9
from conan .tools .scm import Version
10
10
import os
11
11
@@ -46,6 +46,14 @@ def _settings_build(self):
46
46
def _has_mp4_option (self ):
47
47
return Version (self .version ) < "1.29.1"
48
48
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
+
49
57
def export_sources (self ):
50
58
export_conandata_patches (self )
51
59
@@ -70,54 +78,114 @@ def requirements(self):
70
78
71
79
def validate (self ):
72
80
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" )
75
85
if self .options .get_safe ("with_mp4" ):
76
86
# TODO: as mpv4v2 as a conan package
77
87
raise ConanInvalidConfiguration ("building with mp4v2 is not supported currently" )
78
88
79
89
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" )
85
96
86
97
def source (self ):
87
98
get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
88
99
89
100
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 ()
97
113
98
114
def build (self ):
99
115
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
- "\n libfaac_la_LIBADD = " ,
105
- "\n libfaac_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
+ "\n libfaac_la_LIBADD = " ,
157
+ "\n libfaac_la_LIBADD = -no-undefined " )
158
+ autotools .configure ()
159
+ autotools .make ()
108
160
109
161
def package (self ):
110
162
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 )
116
183
117
184
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 } " ]
119
187
if self .settings .os in ["Linux" , "FreeBSD" ]:
120
188
self .cpp_info .system_libs .append ("m" )
121
189
122
- # TODO: to replace in conan v2
190
+ # TODO: to remove in conan v2
123
191
self .env_info .PATH .append (os .path .join (self .package_folder , "bin" ))
0 commit comments