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

giflib/5.1.x: migrate to Conan v2 #18628

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
230 changes: 110 additions & 120 deletions recipes/giflib/5.1.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os
import shutil

required_conan_version = ">=1.43.0"
from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import cross_building
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import chdir, copy, get, rename, replace_in_file, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, unix_path

required_conan_version = ">=1.53.0"


class GiflibConan(ConanFile):
name = "giflib"
description = "A library and utilities for reading and writing GIF images."
url = "https://github.com/conan-io/conan-center-index"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://giflib.sourceforge.net"
topics = ("giflib", "image", "multimedia", "format", "graphics")
topics = ("image", "multimedia", "format", "graphics")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -24,146 +32,128 @@ class GiflibConan(ConanFile):
"fPIC": True,
}

# The exported files I took them from https://github.com/bjornblissing/osg-3rdparty-cmake/tree/master/giflib
# refactored a little
exports_sources = ["unistd.h", "gif_lib.h"]

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)
def export_sources(self):
# The exported files I took them from
# https://github.com/bjornblissing/osg-3rdparty-cmake/tree/master/giflib
# refactored a little
copy(self, "unistd.h", src=self.recipe_folder, dst=self.export_sources_folder)
copy(self, "gif_lib.h", src=self.recipe_folder, dst=self.export_sources_folder)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

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

def build_requirements(self):
if not self._is_msvc:
self.build_requires("gnu-config/cci.20201022")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if not is_msvc(self):
self.tool_requires("gnu-config/cci.20210814")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
if is_msvc(self):
self.tool_requires("automake/1.16.5")

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

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")
tc = AutotoolsToolchain(self)
if is_msvc(self):
tc.extra_defines.append("USE_GIF_DLL" if self.options.shared else "USE_GIF_LIB")
tc.extra_cflags.append("-FS")
tc.generate()

if is_msvc(self):
env = Environment()
automake_conf = self.dependencies.build["automake"].conf_info
compile_wrapper = unix_path(self, automake_conf.get("user.automake:compile-wrapper", check_type=str))
env.define("CC", f"{compile_wrapper} cl -nologo")
env.define("CXX", f"{compile_wrapper} cl -nologo")
env.define("LD", "link -nologo")
# ar-lib wrapper is added by ./configure automatically
# env.define("AR", f'{ar_wrapper} "lib -nologo"')
env.define("NM", "dumpbin -symbols")
env.define("OBJDUMP", ":")
env.define("RANLIB", ":")
env.define("STRIP", ":")
env.vars(self).save_script("conanbuild_msvc")

def _patch_sources(self):
# disable util build - tools and internal libs
replace_in_file(self, os.path.join(self.source_folder, "Makefile.in"),
"SUBDIRS = lib util pic $(am__append_1)",
"SUBDIRS = lib pic $(am__append_1)")

if is_msvc(self):
# add unistd.h for VS
shutil.copy(os.path.join(self.export_sources_folder, "unistd.h"),
os.path.join(self.source_folder, "lib"))
# fully replace gif_lib.h for VS, with patched version
ver_components = self.version.split(".")
header_path = os.path.join(self.source_folder, "lib", "gif_lib.h")
shutil.copy(os.path.join(self.export_sources_folder, "gif_lib.h"), header_path)
replace_in_file(self, header_path, "@GIFLIB_MAJOR@", ver_components[0])
replace_in_file(self, header_path, "@GIFLIB_MINOR@", ver_components[1])
replace_in_file(self, header_path, "@GIFLIB_RELEASE@", ver_components[2])
for gnu_config in [
self.conf.get("user.gnu-config:config_guess", check_type=str),
self.conf.get("user.gnu-config:config_sub", check_type=str)
]:
if gnu_config:
copy(self, os.path.basename(gnu_config), src=os.path.dirname(gnu_config), dst=self.source_folder)
if is_apple_os(self):
# relocatable shared lib on macOS
replace_in_file(self, os.path.join(self.source_folder, "configure"),
"-install_name \\$rpath/\\$soname",
"-install_name \\@rpath/\\$soname")

def build(self):
# disable util build - tools and internal libs
tools.replace_in_file(os.path.join(self._source_subfolder, "Makefile.in"),
"SUBDIRS = lib util pic $(am__append_1)",
"SUBDIRS = lib pic $(am__append_1)")

if self._is_msvc:
self.build_visual()
else:
self.build_configure()

def build_visual(self):
# fully replace gif_lib.h for VS, with patched version
ver_components = self.version.split(".")
tools.replace_in_file("gif_lib.h", "@GIFLIB_MAJOR@", ver_components[0])
tools.replace_in_file("gif_lib.h", "@GIFLIB_MINOR@", ver_components[1])
tools.replace_in_file("gif_lib.h", "@GIFLIB_RELEASE@", ver_components[2])
shutil.copy("gif_lib.h", os.path.join(self._source_subfolder, "lib"))
# add unistd.h for VS
shutil.copy("unistd.h", os.path.join(self._source_subfolder, "lib"))

with tools.chdir(self._source_subfolder):
if self.settings.arch == "x86":
host = "i686-w64-mingw32"
elif self.settings.arch == "x86_64":
host = "x86_64-w64-mingw32"
else:
raise ConanInvalidConfiguration("unsupported architecture %s" % self.settings.arch)
if self.options.shared:
options = "--disable-static --enable-shared"
else:
options = "--enable-static --disable-shared"

cflags = ""
if not self.options.shared:
cflags = "-DUSE_GIF_LIB"

prefix = tools.unix_path(os.path.abspath(self.package_folder))
with tools.vcvars(self.settings):
command = "./configure " \
"{options} " \
"--host={host} " \
"--prefix={prefix} " \
'CC="$PWD/compile cl -nologo" ' \
'CFLAGS="-{runtime} {cflags}" ' \
'CXX="$PWD/compile cl -nologo" ' \
'CXXFLAGS="-{runtime} {cflags}" ' \
'CPPFLAGS="-I{prefix}/include" ' \
'LDFLAGS="-L{prefix}/lib" ' \
'LD="link" ' \
'NM="dumpbin -symbols" ' \
'STRIP=":" ' \
'AR="$PWD/ar-lib lib" ' \
'RANLIB=":" '.format(host=host, prefix=prefix, options=options,
runtime=self.settings.compiler.runtime, cflags=cflags)
self.run(command, win_bash=True)
self.run("make", win_bash=True)
self.run("make install", win_bash=True)

def build_configure(self):
shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB,
os.path.join(self._source_subfolder, "config.sub"))
shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS,
os.path.join(self._source_subfolder, "config.guess"))
env_build = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
]
with tools.chdir(self._source_subfolder):
if tools.is_apple_os(self.settings.os):
# relocatable shared lib on macOS
tools.replace_in_file(
"configure",
"-install_name \\$rpath/\\$soname",
"-install_name \\@rpath/\\$soname"
)

self.run("chmod +x configure")
env_build.configure(args=args)
env_build.make()
env_build.make(args=["install"])
self._patch_sources()
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
self.copy(pattern="COPYING*", dst="licenses", src=self._source_subfolder, ignore_case=True, keep_path=False)
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
tools.rmdir(os.path.join(self.package_folder, "share"))
if self._is_msvc and self.options.shared:
tools.rename(os.path.join(self.package_folder, "lib", "gif.dll.lib"),
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.install()
copy(self, "COPYING*",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder, keep_path=False)
rm(self, "*.la", self.package_folder, recursive=True)
rmdir(self, os.path.join(self.package_folder, "share"))
if is_msvc(self) and self.options.shared:
rename(self, os.path.join(self.package_folder, "lib", "gif.dll.lib"),
os.path.join(self.package_folder, "lib", "gif.lib"))

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "GIF")
self.cpp_info.set_property("cmake_target_name", "GIF::GIF")

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

self.cpp_info.libs = ["gif"]
if self._is_msvc:
if is_msvc(self):
self.cpp_info.defines.append("USE_GIF_DLL" if self.options.shared else "USE_GIF_LIB")

# TODO: to remove in conan v2
self.cpp_info.names["cmake_find_package"] = "GIF"
self.cpp_info.names["cmake_find_package_multi"] = "GIF"
7 changes: 2 additions & 5 deletions recipes/giflib/5.1.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

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

find_package(GIF REQUIRED)
find_package(GIF REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} GIF::GIF)
Expand Down
25 changes: 17 additions & 8 deletions recipes/giflib/5.1.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


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

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

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
if is_apple_os(self) and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
self.tool_requires("cmake/[>=3.22]")

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
if can_run(self):
img_name = os.path.join(self.source_folder, "testimg.gif")
bin_path = os.path.join("bin", "test_package")
command = "{} {}".format(bin_path, img_name)
self.run(command, run_environment=True)
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(f"{bin_path} {img_name}", env="conanrun")
8 changes: 8 additions & 0 deletions recipes/giflib/5.1.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
29 changes: 29 additions & 0 deletions recipes/giflib/5.1.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from conan.tools.apple import is_apple_os
danimtb marked this conversation as resolved.
Show resolved Hide resolved
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build_requirements(self):
if is_apple_os(self) and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")

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

def test(self):
if not tools.cross_building(self):
img_name = os.path.join(self.source_folder, "testimg.gif")
bin_path = os.path.join("bin", "test_package")
command = "{} {}".format(bin_path, img_name)
self.run(command, run_environment=True)
4 changes: 2 additions & 2 deletions recipes/giflib/5.2.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(GIF REQUIRED)
find_package(GIF REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE GIF::GIF)
2 changes: 1 addition & 1 deletion recipes/giflib/5.2.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
Expand Down
2 changes: 1 addition & 1 deletion recipes/giflib/5.2.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
Expand Down
Loading