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

lcms: modernize #9032

Merged
merged 1 commit into from
Jan 25, 2022
Merged
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
85 changes: 45 additions & 40 deletions recipes/lcms/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
from conans.tools import Version
import os
import re
import shutil

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.36.0"


class LcmsConan(ConanFile):
Expand All @@ -14,6 +13,7 @@ class LcmsConan(ConanFile):
license = "MIT"
homepage = "https://github.com/mm2/Little-CMS"
topics = ("lcms", "cmm", "icc", "cmm-engine")

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -30,10 +30,18 @@ class LcmsConan(ConanFile):
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 config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -45,7 +53,7 @@ def configure(self):
del self.settings.compiler.cppstd

def build_requirements(self):
if self.settings.compiler != "Visual Studio":
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")
Expand All @@ -55,15 +63,18 @@ def source(self):
destination=self._source_subfolder, strip_root=True)

def _patch_sources(self):
if self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= "14":
compiler_version = tools.Version(self.settings.compiler.version)
if (self.settings.compiler == "Visual Studio" and compiler_version >= "14") or \
str(self.settings.compiler) == "msvc":
# since VS2015 vsnprintf is built-in
path = os.path.join(self._source_subfolder, "src", "lcms2_internal.h")
tools.replace_in_file(path, "# define vsnprintf _vsnprintf", "")
if self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= "16":
if (self.settings.compiler == "Visual Studio" and compiler_version >= "16") or \
(str(self.settings.compiler) == "msvc" and compiler_version >= "192"):
# since VS2019, don't need to specify the WindowsTargetPlatformVersion
path = os.path.join(self._source_subfolder, "Projects", "VC2015", "lcms2_static", "lcms2_static.vcxproj")
tools.replace_in_file(path, "<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>", "")
if self.settings.os == "Android" and tools.os_info.is_windows:
if self.settings.os == "Android" and self._settings_build.os == "Windows":
# remove escape for quotation marks, to make ndk on windows happy
tools.replace_in_file(os.path.join(self._source_subfolder, "configure"),
"s/[ `~#$^&*(){}\\\\|;'\\\''\"<>?]/\\\\&/g",
Expand All @@ -76,14 +87,23 @@ def _build_visual_studio(self):
vc_sln_subdir = "VC2015"
with tools.chdir(os.path.join(self._source_subfolder, "Projects", vc_sln_subdir )):
target = "lcms2_DLL" if self.options.shared else "lcms2_static"
upgrade_project = Version(self.settings.compiler.version) > "12"
if self.settings.compiler == "Visual Studio" and \
tools.Version(self.settings.compiler.version) <= "12":
upgrade_project = False
else:
upgrade_project = True
# Enable LTO when CFLAGS contains -GL
if any(re.finditer("(^| )[/-]GL($| )", tools.get_env("CFLAGS", ""))):
lto = "true"
else:
lto = "false"
properties = {
# Enable LTO when CFLAGS contains -GL
"WholeProgramOptimization": "true" if any(re.finditer("(^| )[/-]GL($| )", tools.get_env("CFLAGS", ""))) else "false",
"WholeProgramOptimization": lto,
}
# run build
msbuild = MSBuild(self)
msbuild.build("lcms2.sln", targets=[target], platforms={"x86": "Win32"}, upgrade_project=upgrade_project, properties=properties)
msbuild.build("lcms2.sln", targets=[target], platforms={"x86": "Win32"},
upgrade_project=upgrade_project, properties=properties)

def _configure_autotools(self):
if self._autotools:
Expand All @@ -99,17 +119,9 @@ def _configure_autotools(self):
self._autotools.configure(args=args, configure_dir=self._source_subfolder)
return self._autotools

@property
def _user_info_build(self):
# If using the experimental feature with different context for host and
# build, the 'user_info' attributes of the 'build_requires' packages
# will be located into the 'user_info_build' object. In other cases they
# will be located into the 'deps_user_info' object.
return getattr(self, "user_info_build", None) or self.deps_user_info

def build(self):
self._patch_sources()
if self.settings.compiler == "Visual Studio":
if self._is_msvc:
self._build_visual_studio()
else:
shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB,
Expand All @@ -121,7 +133,7 @@ def build(self):

def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
if self.settings.compiler == "Visual Studio":
if self._is_msvc:
self.copy(pattern="*.h", src=os.path.join(self._source_subfolder, "include"), dst="include", keep_path=True)
if self.options.shared:
self.copy(pattern="*.lib", src=os.path.join(self._source_subfolder, "bin"), dst="lib", keep_path=False)
Expand All @@ -132,29 +144,22 @@ def package(self):
else:
autotools = self._configure_autotools()
autotools.install()
# remove entire share directory
tools.rmdir(os.path.join(self.package_folder, "share"))
# remove pkgconfig
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
# remove la files
la = os.path.join(self.package_folder, "lib", "liblcms2.la")
if os.path.isfile(la):
os.unlink(la)
# remove binaries
for bin_program in ["tificc", "linkicc", "transicc", "psicc", "jpgicc"]:
for ext in ["", ".exe"]:
try:
os.remove(os.path.join(self.package_folder, "bin", bin_program + ext))
except:
pass
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
# remove utilities
if self.settings.os == "Windows" and self.options.shared:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*[!.dll]")
else:
tools.rmdir(os.path.join(self.package_folder, "bin"))

def package_info(self):
if self.settings.compiler == "Visual Studio":
self.cpp_info.libs = ["lcms2" if self.options.shared else "lcms2_static"]
if self.options.shared:
self.cpp_info.defines.append("CMS_DLL")
else:
self.cpp_info.libs = ["lcms2"]
self.cpp_info.names["pkg_config"] = "lcms2"
self.cpp_info.set_property("pkg_config_name", "lcms2")
suffix = "_static" if self._is_msvc and not self.options.shared else ""
self.cpp_info.libs = ["lcms2{}".format(suffix)]
if self._is_msvc and self.options.shared:
self.cpp_info.defines.append("CMS_DLL")
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs.append("m")

self.cpp_info.names["pkg_config"] = "lcms2"