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

OpenJPH: Add recipe for new library #25045

Merged
merged 13 commits into from
Sep 30, 2024
Merged
16 changes: 16 additions & 0 deletions recipes/openjph/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sources:
"0.16.0":
url: "https://github.com/aous72/OpenJPH/archive/0.16.0.tar.gz"
sha256: "94bea4d7057f7a5dcb3f8eee3f854955ce153d98dad99602dd0ba50a560d7cf6"
"0.15.0":
url: "https://github.com/aous72/OpenJPH/archive/0.15.0.tar.gz"
sha256: "36601fbd3b4e1fe54eef5e6fa51ac0eca7be94b2a3d7c0967e3c8da66687ff2c"
patches:
"0.16.0":
- patch_file: "patches/0.15.0_cmake-cxx-standard.patch"
patch_description: "Remove setting of CXX standard to a fixed value overriding the toolchain provided by Conan"
patch_type: "conan"
"0.15.0":
- patch_file: "patches/0.15.0_cmake-cxx-standard.patch"
patch_description: "Remove setting of CXX standard to a fixed value overriding the toolchain provided by Conan"
patch_type: "conan"
119 changes: 119 additions & 0 deletions recipes/openjph/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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, copy, export_conandata_patches, get, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

import os

required_conan_version = ">=1.53.0"

class OpenJPH(ConanFile):
name = "openjph"
description = "Open-source implementation of JPEG2000 Part-15 (or JPH or HTJ2K)"
license = "BSD-2-Clause"
homepage = "https://github.com/aous72/OpenJPH"
url = "https://github.com/conan-io/conan-center-index"
topics = ("ht-j2k", "jpeg2000", "jp2", "openjph", "image", "multimedia", "format", "graphics")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_executables": [True, False],
"with_tiff": [True, False],
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
"with_stream_expand_tool": [True, False],
"disable_simd": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_executables": True,
"with_tiff": True,
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
"with_stream_expand_tool": False,
"disable_simd": False,
}

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 layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.with_executables and self.options.with_tiff:
self.requires("libtiff/4.6.0")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
required_cpp_version = 11
if self.options.with_stream_expand_tool:
required_conan_version = 14

Check warning on line 60 in recipes/openjph/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Redefining name 'required_conan_version' from outer scope (line 11)

Check warning on line 60 in recipes/openjph/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused variable 'required_conan_version'
check_min_cppstd(self, required_cpp_version)

if self.settings.compiler == "gcc" and \
Version(self.settings.compiler.version) < "6.0":
raise ConanInvalidConfiguration(f"{self.ref} requires gcc >= 6.0")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["OJPH_BUILD_EXECUTABLES"] = self.options.with_executables
tc.variables["OJPH_ENABLE_TIFF_SUPPORT"] = self.options.with_tiff
tc.variables["OJPH_BUILD_STREAM_EXPAND"] = self.options.with_stream_expand_tool
tc.variables["OJPH_DISABLE_SIMD"] = self.options.disable_simd

# Workaround for Conan 1 where the CXX standard version isn't set to a fallback to gnu98 happens
if not self.settings.get_safe("compiler.cppstd"):
tc.cache_variables["CMAKE_CXX_STANDARD"] = 14 if self.options.with_stream_expand_tool else 11

tc.generate()

deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)

def build(self):
self._patch_sources()

cm = CMake(self)
cm.configure()
cm.build()

def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))

cm = CMake(self)
cm.install()

# Cleanup package own pkgconfig
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

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

version_suffix = ""
if is_msvc(self):
v = Version(self.version)
version_suffix = f".{v.major}.{v.minor}"
self.cpp_info.libs = ["openjph" + version_suffix]

# TODO: to remove in conan v2 once cmake_find_package_* & pkg_config generators removed
self.cpp_info.names["cmake_find_package"] = "openjph"
self.cpp_info.names["cmake_find_package_multi"] = "openjph"
self.cpp_info.names["pkg_config"] = "openjph"
26 changes: 26 additions & 0 deletions recipes/openjph/all/patches/0.15.0_cmake-cxx-standard.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git CMakeLists.txt CMakeLists.txt
index cfa70ea..7e761db 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -93,7 +93,7 @@ message(STATUS "Building ${CMAKE_BUILD_TYPE}")

## C++ version and flags
# C++14 is needed for gtest, otherwise, C++11 is sufficient for the library
-set(CMAKE_CXX_STANDARD 14)
+#set(CMAKE_CXX_STANDARD 14)
if (MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
diff --git src/apps/ojph_stream_expand/CMakeLists.txt src/apps/ojph_stream_expand/CMakeLists.txt
index 5aea342..e21bdd9 100644
--- src/apps/ojph_stream_expand/CMakeLists.txt
+++ src/apps/ojph_stream_expand/CMakeLists.txt
@@ -5,7 +5,7 @@ if (OJPH_BUILD_STREAM_EXPAND)

include_directories(../common)
include_directories(../../core/common)
- set(CMAKE_CXX_STANDARD 14)
+ #set(CMAKE_CXX_STANDARD 14)
irieger marked this conversation as resolved.
Show resolved Hide resolved

file(GLOB OJPH_STREAM_EXPAND "*.cpp" "*.h")
file(GLOB OJPH_SOCKETS "../others/ojph_sockets.cpp")
7 changes: 7 additions & 0 deletions recipes/openjph/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.11)
project(test_package LANGUAGES CXX)

find_package(openjph REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE openjph::openjph)
26 changes: 26 additions & 0 deletions recipes/openjph/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


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

def layout(self):
cmake_layout(self)

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

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
13 changes: 13 additions & 0 deletions recipes/openjph/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <openjph/ojph_arch.h>
#include <openjph/ojph_version.h>

#include <iostream>


int main() {
// Print the version number but also do an API call to check the library
std::cout << "OpenJPH Version: " << OPENJPH_VERSION_MAJOR << '.' << OPENJPH_VERSION_MINOR << '.' << OPENJPH_VERSION_PATCH << std::endl;
std::cout << "CPU Extension level: " << ojph::get_cpu_ext_level() << std::endl;

return EXIT_SUCCESS;
}
5 changes: 5 additions & 0 deletions recipes/openjph/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
versions:
"0.16.0":
folder: all
"0.15.0":
folder: all
Loading