Skip to content

Commit

Permalink
(#23955) Add recipe for the bmx library provided by the BBC
Browse files Browse the repository at this point in the history
* Add recipe for the bmx library provided by the BBC

* Add libcurl flag to conanfile

* Add version ranges for expat & libcurl and remove fixed target C++ version

* Switch linking of CURL to public as otherwise on Linux there is a ton of undefined references

* Add patch source for compatibility patch

* Fix all the deps to not use their own CXX standard override

* Bump the CCI tagged release build to the latest commit which integrates the patches to build with C++20 without non-cmake patches.

* Remove unused import

* Remove -O2 flag & bump cci-version to current master with upstream changes to the CMake not requiering most of the patches

* Add the target_compile_features as applied by bbc/bmx@b764c59

* Enforce minimum CXX11 for test package too

* Deactivate windows shared library building

* Add a descriptive comment for the restriction to disallow shared builds on Windows

---------

Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
  • Loading branch information
irieger and AbrilRBS authored Jun 19, 2024
1 parent 544f71a commit e0571e4
Show file tree
Hide file tree
Showing 9 changed files with 437 additions and 0 deletions.
20 changes: 20 additions & 0 deletions recipes/bmx/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sources:
"1.2":
url: "https://github.com/bbc/bmx/archive/refs/tags/v1.2.tar.gz"
sha256: "e64d91b2d27478d6b892d72183e1ecf79c99880b079ce04442432f3caed1e259"
"cci.20240517":
url: "https://github.com/bbc/bmx/archive/52c7517923dde6e4de881fe1e47fbae5e60df731.tar.gz"
sha256: "b4a0545e2fa33bd7c25adce3b61fd4b06a68a192d037dd0e5eb14defd0b2c936"
patches:
"1.2":
- patch_file: "patches/1.2-cmake-fixes.patch"
patch_description: "Ensure project builds correctly with Conan (don't pick up disabled dependencies from the system, fix different spelling of libraries)"
patch_type: "conan"
- patch_file: "patches/1.2-fix-cpp20.patch"
patch_description: "Fix a compilation problem with C++20"
patch_type: "portability"
patch_source: "https://github.com/bbc/bmx/pull/69"
"cci.20240517":
- patch_file: "patches/cci.20240517-cmake-fixes.patch"
patch_description: "Ensure project builds correctly with Conan (don't pick up disabled dependencies from the system, fix different spelling of libraries)"
patch_type: "conan"
140 changes: 140 additions & 0 deletions recipes/bmx/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, rmdir
import os

required_conan_version = ">=1.53.0"


class BmxConan(ConanFile):
name = "bmx"
description = (
"Library for handling broadcast/production oriented media file formats. "
"Allows reading, modifying and writing media metadata and file essences."
)
topics = ("vfx", "image", "picture", "video", "multimedia", "mxf")
license = "BSD-3-Clause"
homepage = "https://github.com/bbc/bmx"
url = "https://github.com/conan-io/conan-center-index"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_libcurl": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_libcurl": True,
}

def export_sources(self):
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def requirements(self):
# Required libraries
self.requires("uriparser/0.9.8")
self.requires("expat/[>=2.6.2 <3]")

if not (self.settings.os == 'Windows' or self.settings.os == 'Macos'):
self.requires('libuuid/1.0.3')

# Configuration dependent requirements
if self.options.with_libcurl:
self.requires("libcurl/[>=7.78.0 <9]")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, 11)

# Symbol export is currently not working properly on Windows so shared
# libraries are currently deactivated. This can later be revisited based
# on https://github.com/bbc/bmx/issues/80
if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration(
"Building as a shared library currently not supported on Windows!"
)

def layout(self):
cmake_layout(self, src_folder="src")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BMX_BUILD_WITH_LIBCURL"] = self.options.with_libcurl
tc.generate()

cd = CMakeDeps(self)
cd.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

@staticmethod
def _conan_comp(name):
return f"bmx_{name.lower()}"

def _add_component(self, name):
component = self.cpp_info.components[self._conan_comp(name)]
component.set_property("cmake_target_name", f"bmx::{name}")
component.names["cmake_find_package"] = name
component.names["cmake_find_package_multi"] = name
return component

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "bmx")
self.cpp_info.set_property("pkg_config_name", "bmx")

self.cpp_info.names["cmake_find_package"] = "bmx"
self.cpp_info.names["cmake_find_package_multi"] = "bmx"

# bbc-bmx::MXF
libmxf = self._add_component("MXF")
libmxf.libs = ["MXF"]
libmxf.requires = []
if not (self.settings.os == 'Windows' or self.settings.os == 'Macos'):
libmxf.requires.append("libuuid::libuuid")

# bbc-bmx::MXF++
libmxfpp = self._add_component("MXF++")
libmxfpp.libs = ["MXF++"]
libmxfpp.requires = [
"bmx_mxf"
]

# bbc-bmx::bmx
libbmx = self._add_component("bmx")
libbmx.libs = ["bmx"]
libbmx.requires = [
"bmx_mxf",
"bmx_mxf++",
"expat::expat",
"uriparser::uriparser",
]
if not (self.settings.os == 'Windows' or self.settings.os == 'Macos'):
libbmx.requires.append("libuuid::libuuid")

if self.options.with_libcurl:
libbmx.requires.append("libcurl::libcurl")
141 changes: 141 additions & 0 deletions recipes/bmx/all/patches/1.2-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
diff --git CMakeLists.txt CMakeLists.txt
index 6fe9540e7..8b2578852 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -34,7 +34,7 @@ if(BUILD_SHARED_LIBS OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

-set(CMAKE_CXX_STANDARD 11)
+#set(CMAKE_CXX_STANDARD 11)

# Set the test samples output directory
if(BMX_TEST_SAMPLES_DIR STREQUAL "")
@@ -75,7 +75,7 @@ if(MSVC)
endforeach()
endif()
else()
- add_compile_options(-W -Wall -O2)
+ add_compile_options(-W -Wall)

# Enable large file support on 32-bit systems.
add_definitions(
@@ -93,11 +93,25 @@ add_custom_target(bmx_test_data)

include("${PROJECT_SOURCE_DIR}/cmake/libmxf.cmake")
include("${PROJECT_SOURCE_DIR}/cmake/libmxfpp.cmake")
-include("${PROJECT_SOURCE_DIR}/cmake/ext_uuid.cmake")
-include("${PROJECT_SOURCE_DIR}/cmake/ext_expat.cmake")
-include("${PROJECT_SOURCE_DIR}/cmake/ext_uriparser.cmake")
+#include("${PROJECT_SOURCE_DIR}/cmake/ext_uuid.cmake")
+#include("${PROJECT_SOURCE_DIR}/cmake/ext_expat.cmake")
+#include("${PROJECT_SOURCE_DIR}/cmake/ext_uriparser.cmake")
+#if(BMX_BUILD_WITH_LIBCURL)
+# include("${PROJECT_SOURCE_DIR}/cmake/ext_libcurl.cmake")
+#endif()
+
+find_package(expat REQUIRED)
+find_package(uriparser REQUIRED)
+if(UNIX AND NOT APPLE)
+ find_package(libuuid REQUIRED)
+ set(uuid_link_lib libuuid::libuuid)
+else()
+ # MSVC: "ole" will already be linked in
+ # APPLE: doesn't require uuid library
+ set(uuid_link_lib)
+endif()
if(BMX_BUILD_WITH_LIBCURL)
- include("${PROJECT_SOURCE_DIR}/cmake/ext_libcurl.cmake")
+ find_package(CURL REQUIRED)
endif()

configure_file(config.h.in config.h)
diff --git deps/libMXF/CMakeLists.txt deps/libMXF/CMakeLists.txt
index d36fde6c0..6a1af100b 100644
--- deps/libMXF/CMakeLists.txt
+++ deps/libMXF/CMakeLists.txt
@@ -35,7 +35,7 @@ if(BUILD_SHARED_LIBS OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

-set(CMAKE_CXX_STANDARD 11)
+#set(CMAKE_CXX_STANDARD 11)

# Set the test samples output directory
if(LIBMXF_TEST_SAMPLES_DIR STREQUAL "")
@@ -76,7 +76,7 @@ if(MSVC)
endforeach()
endif()
else()
- add_compile_options(-W -Wall -O2)
+ add_compile_options(-W -Wall)

# Enable large file support on 32-bit systems.
add_definitions(
diff --git deps/libMXFpp/CMakeLists.txt deps/libMXFpp/CMakeLists.txt
index 2272a2709..924fdf770 100644
--- deps/libMXFpp/CMakeLists.txt
+++ deps/libMXFpp/CMakeLists.txt
@@ -35,7 +35,7 @@ if(BUILD_SHARED_LIBS OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

-set(CMAKE_CXX_STANDARD 11)
+#set(CMAKE_CXX_STANDARD 11)

if(MSVC)
add_compile_options(/W3 /EHsc)
@@ -61,7 +61,7 @@ if(MSVC)
endforeach()
endif()
else()
- add_compile_options(-W -Wall -O2)
+ add_compile_options(-W -Wall)

# Enable large file support on 32-bit systems.
add_definitions(
diff --git deps/libMXFpp/libMXF++/CMakeLists.txt deps/libMXFpp/libMXF++/CMakeLists.txt
index 94d48c905..e6c6a63f9 100644
--- deps/libMXFpp/libMXF++/CMakeLists.txt
+++ deps/libMXFpp/libMXF++/CMakeLists.txt
@@ -32,6 +32,8 @@ add_library(MXFpp
${MXFpp_sources}
)

+target_compile_features(MXFpp PUBLIC cxx_std_11)
+
target_include_directories(MXFpp PUBLIC
${PROJECT_SOURCE_DIR}
)
diff --git src/CMakeLists.txt src/CMakeLists.txt
index 1c0824d8a..94f9c00d6 100644
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -26,6 +26,8 @@ target_include_directories(bmx PUBLIC
${PROJECT_SOURCE_DIR}/include
)

+target_compile_features(bmx PUBLIC cxx_std_11)
+
# Add path to header files if not included in MSVC distribution
if(MSVC)
include(CheckIncludeFile)
@@ -65,13 +67,14 @@ target_link_libraries(bmx
${MXFpp_link_lib}
PRIVATE
${uuid_link_lib}
- ${expat_link_lib}
- ${uriparser_link_lib}
+ expat::expat
+ uriparser::uriparser
)

if(BMX_BUILD_WITH_LIBCURL)
- target_link_libraries(bmx PRIVATE
- ${libcurl_link_lib}
+ # Linking public to see if the shared library for curls dependencies correctly link
+ target_link_libraries(bmx PUBLIC
+ CURL::libcurl
)
endif()

26 changes: 26 additions & 0 deletions recipes/bmx/all/patches/1.2-fix-cpp20.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git deps/libMXFpp/libMXF++/MXFVersion.cpp deps/libMXFpp/libMXF++/MXFVersion.cpp
index 333d5871..bb247a32 100644
--- deps/libMXFpp/libMXF++/MXFVersion.cpp
+++ deps/libMXFpp/libMXF++/MXFVersion.cpp
@@ -33,6 +33,8 @@
#include "config.h"
#endif

+#include <string>
+
#include "git.h"
#include "fallback_git_version.h"

diff --git src/common/Version.cpp src/common/Version.cpp
index a4f00e14..d51da64a 100644
--- src/common/Version.cpp
+++ src/common/Version.cpp
@@ -219,7 +219,7 @@ mxfProductVersion bmx::get_bmx_mxf_product_version()
// Set the patch version value to the commit offset from the release tag.
// The commit offset is part of the git describe tag string which has the
// format "<tag>-<offset>-g<commit id>"
- string describe = bmx_git::DescribeTag();
+ string describe = std::string(bmx_git::DescribeTag());
#ifdef PACKAGE_GIT_VERSION_STRING
if (describe.empty() || describe == "unknown")
describe = PACKAGE_GIT_VERSION_STRING;
57 changes: 57 additions & 0 deletions recipes/bmx/all/patches/cci.20240517-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
diff --git CMakeLists.txt CMakeLists.txt
index 3139ef78e..a08fbb589 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -91,11 +91,26 @@ add_custom_target(bmx_test_data)

include("${PROJECT_SOURCE_DIR}/cmake/libmxf.cmake")
include("${PROJECT_SOURCE_DIR}/cmake/libmxfpp.cmake")
-include("${PROJECT_SOURCE_DIR}/cmake/ext_uuid.cmake")
-include("${PROJECT_SOURCE_DIR}/cmake/ext_expat.cmake")
-include("${PROJECT_SOURCE_DIR}/cmake/ext_uriparser.cmake")
+#include("${PROJECT_SOURCE_DIR}/cmake/ext_uuid.cmake")
+#include("${PROJECT_SOURCE_DIR}/cmake/ext_expat.cmake")
+#include("${PROJECT_SOURCE_DIR}/cmake/ext_uriparser.cmake")
+#if(BMX_BUILD_WITH_LIBCURL)
+# include("${PROJECT_SOURCE_DIR}/cmake/ext_libcurl.cmake")
+#endif()
+
+find_package(expat REQUIRED)
+find_package(uriparser REQUIRED)
+if(UNIX AND NOT APPLE)
+ find_package(libuuid REQUIRED)
+ set(uuid_link_lib libuuid::libuuid)
+else()
+ # MSVC: "ole" will already be linked in
+ # APPLE: doesn't require uuid library
+ set(uuid_link_lib)
+endif()
if(BMX_BUILD_WITH_LIBCURL)
include("${PROJECT_SOURCE_DIR}/cmake/ext_libcurl.cmake")
+ find_package(CURL REQUIRED)
endif()

configure_file(config.h.in config.h)
diff --git src/CMakeLists.txt src/CMakeLists.txt
index 59c94b8b9..94f9c00d6 100644
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -67,13 +67,14 @@ target_link_libraries(bmx
${MXFpp_link_lib}
PRIVATE
${uuid_link_lib}
- ${expat_link_lib}
- ${uriparser_link_lib}
+ expat::expat
+ uriparser::uriparser
)

if(BMX_BUILD_WITH_LIBCURL)
- target_link_libraries(bmx PRIVATE
- ${libcurl_link_lib}
+ # Linking public to see if the shared library for curls dependencies correctly link
+ target_link_libraries(bmx PUBLIC
+ CURL::libcurl
)
endif()

8 changes: 8 additions & 0 deletions recipes/bmx/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(bmx REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
target_link_libraries(${PROJECT_NAME} PRIVATE bmx::bmx)
Loading

0 comments on commit e0571e4

Please sign in to comment.