-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
toge
wants to merge
9
commits into
conan-io:master
Choose a base branch
from
toge:fpng-add-recipe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fpng: add recipe #22823
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f3032c0
fpng: add recipe
toge 36416bc
Merge branch 'master' into fpng-add-recipe
toge fcd81c7
update cmake version
toge edb158f
enable sse on default
toge 85591ca
fix indent
toge 848de39
Update recipes/fpng/all/conanfile.py
AbrilRBS 0e557d9
rename official tarball
toge 87d4932
simplify test_pacakge.cpp
toge b6aaae2
make static-library on msvc
toge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
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 | ||
) | ||
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} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/refs/tags/v1.0.6.tar.gz" | ||
sha256: "0f4b60f0b638d47addfbd150bb19bfe2f3343c4ed2d742c02c085456de0ee1dd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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 | ||
from conan.tools.microsoft import is_msvc | ||
import os | ||
|
||
required_conan_version = ">=2.1" | ||
|
||
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, | ||
} | ||
exports_sources = ["CMakeLists.txt"] | ||
|
||
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") | ||
if is_msvc(self): | ||
self.package_type = "static-library" | ||
del self.options.shared | ||
|
||
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) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["FPNG_SRC_DIR"] = self.source_folder.replace("\\", "/") | ||
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "fpng.h" | ||
|
||
int main() { | ||
fpng::fpng_init(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"1.0.6": | ||
folder: all |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
That way all of the CMakeLists.txt and source paths work without any prefixing.
The current approach is not wrong either, though, of course.
There was a problem hiding this comment.
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.
modified conanfile.py
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,
}