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

fpng: add recipe #22823

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions recipes/fpng/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.8)
toge marked this conversation as resolved.
Show resolved Hide resolved
project(fpng LANGUAGES CXX)

include(GNUInstallDirs)

add_library(fpng ${FPNG_SRC_DIR}/src/fpng.cpp)
set_target_properties(fpng PROPERTIES
PUBLIC_HEADER ${FPNG_SRC_DIR}/src/fpng.h
WINDOWS_EXPORT_ALL_SYMBOLS ON
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
)
target_compile_features(fpng PRIVATE cxx_std_11)
if(FPNG_WITH_SSE)
if (NOT MSVC)
target_compile_options(fpng PRIVATE -msse4.1 -mpclmul)
endif()
target_compile_definitions(fpng PRIVATE -DFPNG_NO_SSE=0)
else()
target_compile_definitions(fpng PRIVATE -DFPNG_NO_SSE=1)
endif()

find_library(LIBM m)
target_link_libraries(fpng PRIVATE $<$<BOOL:${LIBM}>:${LIBM}>)

install(
TARGETS fpng
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
4 changes: 4 additions & 0 deletions recipes/fpng/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.6":
url: "https://github.com/richgel999/fpng/archive/01296df391d70e68af9d64baa3b7b80d9e38caa6.tar.gz"
sha256: "8c07bf75f01a33d797b895afd4ddf5302486a80b1e93ecb1956df00788748444"
77 changes: 77 additions & 0 deletions recipes/fpng/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, save, load
from conan.tools.build import check_min_cppstd
import os

required_conan_version = ">=1.53.0"


class FpngConan(ConanFile):
name = "fpng"
description = "Super fast C++ .PNG writer/reader"
license = "unlicense",
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/richgel999/fpng"
topics = ("png", "writer", "reader")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_sse": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_sse": False,
toge marked this conversation as resolved.
Show resolved Hide resolved
}
exports_sources = ["CMakeLists.txt"]

@property
def _min_cppstd(self):
return 11

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 validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["FPNG_SRC_DIR"] = self.source_folder.replace("\\", "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth changing it here, but I generally find it easier to

def export_sources(self):
    copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

That way all of the CMakeLists.txt and source paths work without any prefixing.

The current approach is not wrong either, though, of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valgur
Sorry for my late response.

I tried your comment, but I failed.
Are there any misunderstandings in my modification?

Error message is following.

fpng/1.0.6: Running CMake.configure()
fpng/1.0.6: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/toge/.conan2/p/b/fpng8db6eab8b7baf/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/toge/.conan2/p/b/fpng8db6eab8b7baf/b/src"
CMake Warning:
  Ignoring extra path from command line:

   "/home/toge/.conan2/p/b/fpng8db6eab8b7baf/b/src"


CMake Error: The source directory "/home/toge/.conan2/p/b/fpng8db6eab8b7baf/b/src" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

modified conanfile.py

``` from conan import ConanFile from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout from conan.tools.files import get, save, load, copy, rm from conan.tools.build import check_min_cppstd import os

required_conan_version = ">=1.53.0"

class FpngConan(ConanFile):
name = "fpng"
description = "Super fast C++ .PNG writer/reader"
license = "Unlicense",
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/richgel999/fpng"
topics = ("png", "writer", "reader")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_sse": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_sse": True,
}

def export_sources(self):
    copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

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 validate(self):
    check_min_cppstd(self, 11)

def source(self):
    get(self, **self.conan_data["sources"][self.version], strip_root=True)
    # remove original CMakeLists.txt (which builds a test program only)
    rm(self, "CMakeLists.txt", self.source_folder)

def generate(self):
    tc = CMakeToolchain(self)
    tc.variables["FPNG_WITH_SSE"] = self.options.with_sse
    tc.generate()

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

def package(self):
    filename = os.path.join(self.source_folder, "src", "fpng.cpp")
    file_content = load(self, filename)
    license_start = "	This is free and unencumbered software"
    license_end = "*/"
    license_contents = file_content[file_content.find(license_start):file_content.find(license_end)]
    save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents)
    cmake = CMake(self)
    cmake.install()

def package_info(self):
    self.cpp_info.libs = ["fpng"]
    if self.settings.os in ("FreeBSD", "Linux"):
        self.cpp_info.system_libs = ["m"]
</details>

tc.variables["FPNG_WITH_SSE"] = self.options.with_sse
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def package(self):
filename = os.path.join(self.source_folder, "src", "fpng.cpp")
file_content = load(self, filename)
license_start = " This is free and unencumbered software"
license_end = "*/"
license_contents = file_content[file_content.find(license_start):file_content.find(license_end)]
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["fpng"]
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs = ["m"]
8 changes: 8 additions & 0 deletions recipes/fpng/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(fpng REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE fpng::fpng)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
27 changes: 27 additions & 0 deletions recipes/fpng/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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")
font_path = os.path.join(self.source_folder, "OpenSans-Bold.ttf")
self.run(f"{bin_path} {font_path}", env="conanrun")
22 changes: 22 additions & 0 deletions recipes/fpng/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <vector>
#include <cstdint>

#include "fpng.h"

int main() {
fpng::fpng_init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valgur
Thanks a lot!
Fixed.


auto const WIDTH = 800;
auto const HEIGHT = 600;
auto const CHANNEL = 3;

auto buffer = std::vector<uint8_t>{};
buffer.reserve(WIDTH * HEIGHT * CHANNEL);

uint32_t flags = 0;

auto image = std::vector<uint8_t>{};
fpng::fpng_encode_image_to_memory(buffer.data(), WIDTH, HEIGHT, CHANNEL, image, flags);

return 0;
}
3 changes: 3 additions & 0 deletions recipes/fpng/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.6":
folder: all
Loading