from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, save
from conan.tools.microsoft import is_msvc
import os
required_conan_version = ">=2.0"
class live555Conan ( ConanFile ):
name = "live555"
# Optional metadata
license = "LGPL"
homepage = "http://live555.com/liveMedia/"
description = "libraries for standards-based RTP/RTCP/RTSP/SIP multimedia streaming, suitable for embedded and/or low-cost streaming applications"
url = "https://github.com/conan-io/conan-center-index"
topics = ( "RTP" , "RTCP" , "RTSP" , "SIP" )
# Binary configuration
settings = "os" , "arch" , "compiler" , "build_type"
options = {
"shared" : [ True , False ],
"fPIC" : [ True , False ],
}
default_options = {
"shared" : False ,
"fPIC" : True ,
}
# Sources are located in the same place as this recipe, copy them to the recipe
def export_sources (self):
export_conandata_patches( self )
def config_options (self):
if self .settings.os == "Windows" :
self .options.rm_safe( "fPIC" )
def configure (self):
print ( "-- configure() --" )
if self .options.shared:
self .options.rm_safe( "fPIC" )
self .settings.rm_safe( "compiler.cppstd" )
self .settings.rm_safe( "compiler.libcxx" )
def layout (self):
basic_layout( self )
# set build folder to source folder in order to execute make in build()
self .folders.build = self .source_folder
# set generators folder to source folder in order to generate Makefile in generate()
self .folders.generators = self .source_folder
def requirements (self):
print ( "-- requirements() --" )
self .requires( "openssl/[>=1.1 <4]@thirdparty/stable" )
# download source and copy to build forlder
def source (self):
print ( "-- source() --" )
get( self , ** self .conan_data[ "sources" ][ self .version], strip_root = True )
apply_conandata_patches( self )
def generate (self):
print ( "-- generate() --" )
components = [ "UsageEnvironment" , "BasicUsageEnvironment" , "groupsock" , "liveMedia" ]
for component in components:
self .run( f "chmod +w { component } /Makefile.tail" )
replace_in_file( self , f " { component } /Makefile.tail" , f "$(DESTDIR)$(PREFIX)/include/ { component } " , "$(DESTDIR)$(PREFIX)/include/" )
if cross_building( self ):
# add write permission for each config files
self .run( "chmod +w config.*" )
# for cross compile
replace_in_file( self , "config.armlinux" , "CROSS_COMPILE?= arm-elf-" , "CROSS_COMPILE= $(CROSS_COMPILE_PREFIX)" )
replace_in_file( self , "config.armlinux" , "CPLUSPLUS_FLAGS = $(COMPILE_OPTS) -Wall -DBSD=1" , "CPLUSPLUS_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) -Wall -DBSD=1" )
replace_in_file( self , "config.armlinux" , "LIBS_FOR_CONSOLE_APPLICATION = -lssl -lcrypto" , "LIBS_FOR_CONSOLE_APPLICATION = $(LDFLAGS) -lssl -lcrypto -lz -ldl -lpthread -lrt" )
save( self , "config.armlinux" , "PREFIX = " , True )
if self .settings.arch == "x86_64" :
self .run( "./genMakefiles linux-64bit" )
elif self .settings.arch == "armv8" :
self .run( "./genMakefiles armlinux" )
else :
print ( f "UNKNOWN arch: {self .settings.arch } " )
return
env = VirtualBuildEnv( self )
env.generate()
tc = AutotoolsToolchain( self )
tc.generate()
td = AutotoolsDeps( self )
td.generate()
def build (self):
print ( "-- build() --" )
# add execute permission for generated scripts
self .run( "chmod +x conan*.sh deactivate*.sh" )
self .run( "./conanbuild.sh" )
autotools = Autotools( self )
autotools.make()
self .run( "./deactivate_conanbuild.sh" )
def package (self):
print ( "-- package() --" )
print ( "source_folder:" , self .source_folder)
print ( "package_folder:" , self .package_folder)
copy( self , "COPYING*" , src = self .source_folder, dst = os.path.join( self .package_folder, "licenses" ))
self .run( "./conanbuild.sh" )
autotools = Autotools( self )
autotools.install()
self .run( "./deactivate_conanbuild.sh" )
@ property
def _live555_components (self):
components = [
{ "target" : "UsageEnvironment" , "lib" : "UsageEnvironment" , "requires" : []},
{ "target" : "BasicUsageEnvironment" , "lib" : "BasicUsageEnvironment" , "requires" : []},
{ "target" : "groupsock" , "lib" : "groupsock" , "requires" : []},
{ "target" : "liveMedia" , "lib" : "liveMedia" , "requires" : []},
]
return components
def package_info (self):
version = self .version.split( "." )
version = "" .join(version) if self .settings.os == "Windows" else ""
debug = "d" if self .settings.build_type == "Debug" and is_msvc( self ) else ""
def get_lib_name (module):
return module
def add_components (components):
for component in components:
conan_component = component[ "target" ]
cmake_target = component[ "target" ]
cmake_component = component[ "lib" ]
lib_name = get_lib_name(component[ "lib" ])
requires = component[ "requires" ]
# TODO : we should also define COMPONENTS names of each target for find_package() but not possible yet in CMakeDeps
# see https://github.com/conan-io/conan/issues/10258
self .cpp_info.components[conan_component].set_property( "cmake_target_name" , cmake_target)
self .cpp_info.components[conan_component].libs = [lib_name]
self .cpp_info.components[conan_component].requires = requires
if self .settings.os in [ "Linux" , "FreeBSD" ]:
self .cpp_info.components[conan_component].system_libs = [ "dl" , "m" , "pthread" , "rt" ]
self .cpp_info.set_property( "cmake_file_name" , "live555" )
add_components( self ._live555_components)