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

Adding imagl recipe #4225

Merged
merged 4 commits into from
Jan 19, 2021
Merged
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
4 changes: 4 additions & 0 deletions recipes/imagl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.1.0":
url: "https://gitlab-lepuy.iut-clermont.uca.fr/opengl/imagl/-/archive/v0.1.0/imagl-v0.1.0.tar.gz"
sha256: "9dcfba4c2efa8d44bf4cc9edd324794865dd6d6331467d3c69f5c5574db3844e"
66 changes: 66 additions & 0 deletions recipes/imagl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from conans import ConanFile, CMake, tools, errors

class ImaglConan(ConanFile):
name = "imagl"
license = "GPL-3"
homepage = "https://github.com/Woazim/imaGL"
url = "https://github.com/conan-io/conan-center-index"
description = "A lightweight library to load image for OpenGL application. Directly compatible with glTexImage* functions. Tested on linux, macOS and Windows with gcc, clang and msvc."
topics = ("opengl", "texture", "image")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
Copy link
Contributor

Choose a reason for hiding this comment

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

You are missing the fPIC option

generators = "cmake"
requires = [("libpng/1.6.37")]

def source(self):
tools.get(**self.conan_data["sources"][self.version])
# This small hack might be useful to guarantee proper /MT /MD linkage
# in MSVC if the packaged project doesn't have variables to set it
# properly
tools.replace_in_file(self.name + "-v" + self.version + "/CMakeLists.txt", "# conan insert",
'''include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')
Copy link
Contributor

Choose a reason for hiding this comment

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

patching sources needs to be done in the build method


def build(self):
cmake = CMake(self)
cmake.verbose = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cmake.verbose = True

cmake.configure(source_folder=self.name + "-v" + self.version, defs={"STATIC_LIB": "OFF" if self.options.shared else "ON"})
cmake.build()
cmake.install()
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be done in the package method


# Explicit way:
Copy link
Contributor

Choose a reason for hiding this comment

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

pls remove dead code

# self.run('cmake %s/hello %s'
# % (self.source_folder, cmake.command_line))
# self.run("cmake --build . %s" % cmake.build_config)

def package(self):
self.copy("*.h", dst="include", src=self.package_folder + "include")
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
self.copy(self.name + "-v" + self.version + "/LICENSE", dst="licenses", keep_path=False)

def package_info(self):
debug_suffix = ""
static_suffix = ""
if self.settings.build_type == "Debug": debug_suffix = "d"
if not(self.options.shared): static_suffix = "s"
self.cpp_info.libs = ["imaGL{debug}{static}".format(debug = debug_suffix, static = static_suffix)]

def configure(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be higher up in the order see this https://github.com/conan-io/conan-center-index/blob/ddd8c3c7499678583061a570b03cac615d67b157/docs/reviewing.md#order-of-methods-and-attributes

For managing the c++ version requirements... I'd suggest you copy this snippet
conan-io/conan#8002

if (self.settings.compiler == "clang"
and tools.Version(self.settings.compiler.version) < "10.0.0"):
raise errors.ConanInvalidConfiguration("Library imaGL need clang 10+")
if (self.settings.compiler == "gcc"
and tools.Version(self.settings.compiler.version) < "9.0.0"):
raise errors.ConanInvalidConfiguration("Library imaGL need gcc 9+")
if (self.settings.compiler == "apple-clang"
and tools.Version(self.settings.compiler.version) < "11.0.3"):
raise errors.ConanInvalidConfiguration("Library imaGL need apple-clang 11.0.3+")
if (self.settings.compiler == "Visual Studio"
and tools.Version(self.settings.compiler.version) < "16.5"):
raise errors.ConanInvalidConfiguration("Library imaGL need Visual Studio 16.5+")

21 changes: 21 additions & 0 deletions recipes/imagl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)

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

add_executable(example example.cpp)
target_link_libraries(example ${CONAN_LIBS})

if(STATIC_LIB)
add_compile_definitions(IMAGL_STATIC)
endif()
Comment on lines +10 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

this most likely needs to be in the package info


set_property(TARGET example PROPERTY CXX_STANDARD 20)
set_property(TARGET example PROPERTY CXX_STANDARD_REQUIRED ON)

# CTest is a testing tool that can be used to test your project.
# enable_testing()
# add_test(NAME example
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
# COMMAND example)
22 changes: 22 additions & 0 deletions recipes/imagl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from conans import ConanFile, CMake, tools


class ImaglTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
generators = "cmake"

def build(self):
cmake = CMake(self)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
# in "test_package"
cmake.configure(defs={"STATIC_LIB": "OFF" if self.options.shared else "ON"})
cmake.build()

def test(self):
if not tools.cross_building(self):
os.chdir("bin")
self.run(".%sexample" % os.sep)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please follow our usual test package format

Suggested change
import os
from conans import ConanFile, CMake, tools
class ImaglTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
generators = "cmake"
def build(self):
cmake = CMake(self)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
# in "test_package"
cmake.configure(defs={"STATIC_LIB": "OFF" if self.options.shared else "ON"})
cmake.build()
def test(self):
if not tools.cross_building(self):
os.chdir("bin")
self.run(".%sexample" % os.sep)
import os
from conans import ConanFile, CMake, tools
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

12 changes: 12 additions & 0 deletions recipes/imagl/all/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include <imaGL/imaGL.h>

int main() {
try {
imaGL::CImaGL img("notfound.png");
}
catch(...) {
}
std::cout << "It works!\n";
return 0;
}
3 changes: 3 additions & 0 deletions recipes/imagl/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.1.0":
folder: all