Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openh264/* upgrade to conan v2 #13849

Merged
merged 11 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions recipes/openh264/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"2.3.1":
url: "https://github.com/cisco/openh264/archive/refs/tags/v2.3.1.tar.gz"
sha256: "453afa66dacb560bc5fd0468aabee90c483741571bca820a39a1c07f0362dc32"
"2.1.1":
url: "https://github.com/cisco/openh264/archive/v2.1.1.tar.gz"
sha256: "af173e90fce65f80722fa894e1af0d6b07572292e76de7b65273df4c0a8be678"
Expand All @@ -8,19 +11,21 @@ sources:
patches:
"2.1.1":
- patch_file: "patches/2.1.1-0001-platform-android.mk.patch"
base_path: "source_subfolder"
patch_type: "conan"
patch_description: "Android Fix"
- patch_file: "patches/2.1.1-0002-macos-relocatable-shared.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.1.1-0003-no-fpic.patch"
base_path: "source_subfolder"
patch_type: "conan"
patch_description: "Macos relocatable shared fix"
- patch_file: "patches/1.7.0-0004-mingw-override-CC-CXX-AR-from-env.patch"
base_path: "source_subfolder"
patch_type: "conan"
Nomalah marked this conversation as resolved.
Show resolved Hide resolved
patch_description: "Mingw Override CC CXX AR from env Fix"
"1.7.0":
- patch_file: "patches/1.7.0-0001-platform-android.mk.patch"
base_path: "source_subfolder"
patch_type: "conan"
patch_description: "Android Fix"
- patch_file: "patches/1.7.0-0002-macos-relocatable-shared.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.7.0-0003-no-fpic.patch"
base_path: "source_subfolder"
patch_type: "conan"
patch_description: "Macos relocatable shared fix"
- patch_file: "patches/1.7.0-0004-mingw-override-CC-CXX-AR-from-env.patch"
base_path: "source_subfolder"
patch_type: "conan"
patch_description: "Mingw Override CC CXX AR from env Fix"
162 changes: 90 additions & 72 deletions recipes/openh264/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, tools, AutoToolsBuildEnvironment
from conan import ConanFile, Version
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, replace_in_file, chdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.apple import is_apple_os, fix_apple_shared_install_name
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, unix_path, msvc_runtime_flag

import os

required_conan_version = ">=1.33.0"
# Temporary duplication until conan 1.54, at which conan.tools.build.stdcpp_library will replace this.
def _stdcpp_library(conanfile):
libcxx = conanfile.settings.get_safe("compiler.libcxx")
if libcxx in ["libstdc++", "libstdc++11"]:
return "stdc++"
elif libcxx in ["libc++"]:
return "c++"
elif libcxx in ["c++_shared"]:
return "c++_shared"
elif libcxx in ["c++_static"]:
return "c++_static"
return None
Nomalah marked this conversation as resolved.
Show resolved Hide resolved

required_conan_version = ">=1.52.0"


class OpenH264Conan(ConanFile):
Expand All @@ -24,73 +43,72 @@ class OpenH264Conan(ConanFile):
}

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@property
def _is_clang_cl(self):
return self.settings.os == 'Windows' and self.settings.compiler == 'clang'

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass
Nomalah marked this conversation as resolved.
Show resolved Hide resolved

def layout(self):
# src_folder must use the same source folder name the project
Nomalah marked this conversation as resolved.
Show resolved Hide resolved
basic_layout(self, src_folder="src")

def build_requirements(self):
if self.settings.arch in ("x86", "x86_64"):
self.build_requires("nasm/2.15.05")
Nomalah marked this conversation as resolved.
Show resolved Hide resolved
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str):
self.tool_requires("msys2/cci.latest")
if is_msvc(self):
self.tool_requires("automake/1.16.5")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
if self._is_msvc:
tools.replace_in_file(os.path.join(self._source_subfolder, "build", "platform-msvc.mk"),
if is_msvc(self):
replace_in_file(self, os.path.join(self.source_folder, "build", "platform-msvc.mk"),
"CFLAGS_OPT += -MT",
"CFLAGS_OPT += -{}".format(msvc_runtime_flag(self)))
tools.replace_in_file(os.path.join(self._source_subfolder, "build", "platform-msvc.mk"),
f"CFLAGS_OPT += -{msvc_runtime_flag(self)}")
replace_in_file(self, os.path.join(self.source_folder, "build", "platform-msvc.mk"),
"CFLAGS_DEBUG += -MTd -Gm",
"CFLAGS_DEBUG += -{} -Gm".format(msvc_runtime_flag(self)))
f"CFLAGS_DEBUG += -{msvc_runtime_flag(self)} -Gm")
if self.settings.os == "Android":
tools.replace_in_file(os.path.join(self._source_subfolder, "codec", "build", "android", "dec", "jni", "Application.mk"),
replace_in_file(self, os.path.join(self.source_folder, "codec", "build", "android", "dec", "jni", "Application.mk"),
"APP_STL := stlport_shared",
"APP_STL := {}".format(self.settings.compiler.libcxx))
tools.replace_in_file(os.path.join(self._source_subfolder, "codec", "build", "android", "dec", "jni", "Application.mk"),
f"APP_STL := {self.settings.compiler.libcxx}")
replace_in_file(self, os.path.join(self.source_folder, "codec", "build", "android", "dec", "jni", "Application.mk"),
"APP_PLATFORM := android-12",
"APP_PLATFORM := {}".format(self._android_target))
f"APP_PLATFORM := {self._android_target}")

@property
def _library_filename(self):
prefix = "" if (self._is_msvc or self._is_clang_cl) else "lib"
prefix = "" if (is_msvc(self) or self._is_clang_cl) else "lib"
if self.options.shared:
if tools.is_apple_os(self.settings.os):
if is_apple_os(self):
suffix = ".dylib"
elif self.settings.os == "Windows":
suffix = ".dll"
else:
suffix = ".so"
else:
if self._is_msvc or self._is_clang_cl:
if is_msvc(self) or self._is_clang_cl:
suffix = ".lib"
else:
suffix = ".a"
Expand All @@ -102,80 +120,80 @@ def _make_arch(self):
"armv7": "arm",
"armv8": "arm64",
"x86": "i386",
"x86_64": "x86_64",
}.get(str(self.settings.arch), str(self.settings.arch))

@property
def _android_target(self):
return "android-{}".format(self.settings.os.api_level)
return f"android-{self.settings.os.api_level}"

@property
def _make_args(self):
prefix = os.path.abspath(self.package_folder)
if tools.os_info.is_windows:
prefix = tools.unix_path(prefix)
prefix = unix_path(self, os.path.abspath(self.package_folder))
args = [
"ARCH={}".format(self._make_arch),
"PREFIX={}".format(prefix),
f"ARCH={self._make_arch}",
f"PREFIX={prefix}"
]
autotools = AutoToolsBuildEnvironment(self)
if self._is_msvc:
autotools.flags.extend(["-nologo", "-{}".format(self.settings.compiler.runtime)])
autotools.link_flags.insert(0, "-link")
if not (self.settings.compiler == "Visual Studio" and tools.Version(self.settings.compiler.version) < "12"):
autotools.flags.append("-FS")
elif self.settings.compiler in ("apple-clang",):
if self.settings.arch in ("armv8",):
autotools.link_flags.append("-arch arm64")
if self.options.shared:
autotools.fpic = True
args.extend(["{}={}".format(k, v) for k,v in autotools.vars.items()])

if self._is_msvc or self._is_clang_cl:
if is_msvc(self) or self._is_clang_cl:
args.append("OS=msvc")
else:
if self.settings.os == "Windows":
args.append("OS=mingw_nt")
if self.settings.os == "Android":
libcxx = str(self.settings.compiler.libcxx)
stl_lib = "$(NDKROOT)/sources/cxx-stl/llvm-libc++/libs/$(APP_ABI)/lib{}".format("c++_static.a" if libcxx == "c++_static" else "c++_shared.so") \
stl_lib = f'$(NDKROOT)/sources/cxx-stl/llvm-libc++/libs/$(APP_ABI)/lib{"c++_static.a" if libcxx == "c++_static" else "c++_shared.so"}' \
+ "$(NDKROOT)/sources/cxx-stl/llvm-libc++/libs/$(APP_ABI)/libc++abi.a"
ndk_home = os.environ["ANDROID_NDK_HOME"]
args.extend([
"NDKLEVEL={}".format(self.settings.os.api_level),
"STL_LIB={}".format(stl_lib),
f"NDKLEVEL={self.settings.os.api_level}",
f"STL_LIB={stl_lib}",
"OS=android",
"NDKROOT={}".format(ndk_home), # not NDK_ROOT here
"TARGET={}".format(self._android_target),
f"NDKROOT={ndk_home}", # not NDK_ROOT here
f"TARGET={self._android_target}",
"CCASFLAGS=$(CFLAGS) -fno-integrated-as",
])

return args

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
tc = AutotoolsToolchain(self)
tc.make_args.extend(self._make_args)

if is_msvc(self):
tc.extra_cxxflags.append("-nologo")
if not (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) < "12"):
tc.extra_cxxflags.append("-FS")
elif self.settings.compiler in ("apple-clang",):
if self.settings.arch in ("armv8",):
tc.extra_ldflags.append("-arch arm64")
tc.generate()

def build(self):
apply_conandata_patches(self)
self._patch_sources()
with tools.vcvars(self) if (self._is_msvc or self._is_clang_cl) else tools.no_op():
with tools.chdir(self._source_subfolder):
env_build = AutoToolsBuildEnvironment(self)
env_build.make(args=self._make_args, target=self._library_filename)
autotools = Autotools(self)
with chdir(self, self.source_folder):
autotools.make(target=self._library_filename)

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
with tools.vcvars(self) if (self._is_msvc or self._is_clang_cl) else tools.no_op():
with tools.chdir(self._source_subfolder):
env_build = AutoToolsBuildEnvironment(self)
env_build.make(args=self._make_args, target="install-" + ("shared" if self.options.shared else "static-lib"))
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
autotools = Autotools(self)
with chdir(self, self.source_folder):
autotools.make(target=f'install-{"shared" if self.options.shared else "static-lib"}')

tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "openh264")
suffix = "_dll" if (self._is_msvc or self._is_clang_cl) and self.options.shared else ""
self.cpp_info.libs = ["openh264{}".format(suffix)]
suffix = "_dll" if (is_msvc(self) or self._is_clang_cl) and self.options.shared else ""
self.cpp_info.libs = [f"openh264{suffix}"]
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs.extend(["m", "pthread"])
if self.settings.os == "Android":
self.cpp_info.system_libs.append("m")
libcxx = tools.stdcpp_library(self)
libcxx = _stdcpp_library(self) # switch to conan.tools.build.stdcpp_library in conan 1.54
if libcxx:
self.cpp_info.system_libs.append(libcxx)
15 changes: 0 additions & 15 deletions recipes/openh264/all/patches/1.7.0-0003-no-fpic.patch

This file was deleted.

15 changes: 0 additions & 15 deletions recipes/openh264/all/patches/2.1.1-0003-no-fpic.patch

This file was deleted.

3 changes: 0 additions & 3 deletions recipes/openh264/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(openh264 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
Expand Down
19 changes: 14 additions & 5 deletions recipes/openh264/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
Expand All @@ -21,6 +30,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self, skip_x64_x86=True):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if not cross_building(self, skip_x64_x86=True):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/openh264/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Loading