forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(conan-io#18987) libid3tag: migrate to Conan v2
* libid3tag: migrate to Conan v2 * libid3tag: use AutotoolsDeps * libid3tag: disable shared build on armv8 * libid3tag: zlib/[>=1.2.11 <2] * libid3tag: replace legacy VS project with CMakeLists.txt * libid3tag: fix autotools package() * libid3tag: make the armv8 check specific to cross-building * Update recipes/libid3tag/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * libid3tag: add missing import --------- Co-authored-by: Uilian Ries <[email protected]>
- Loading branch information
1 parent
3bcb2f1
commit d173be7
Showing
6 changed files
with
152 additions
and
101 deletions.
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,21 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(libid3tag LANGUAGES C) | ||
|
||
file(GLOB SOURCES "*.c" "*.h") | ||
add_library(libid3tag ${SOURCES} ${HEADERS}) | ||
target_include_directories(libid3tag PRIVATE msvc++) | ||
|
||
# https://github.com/markjeee/libid3tag/blob/master/msvc%2B%2B/libid3tag.dsp#L43-L44 | ||
target_compile_options(libid3tag PRIVATE /W2 "$<$<CONFIG:Debug>:/Od;/GZ>" "$<$<CONFIG:Release>:/O2>") | ||
target_compile_definitions(libid3tag PRIVATE HAVE_CONFIG_H "$<$<CONFIG:Debug>:DEBUG;>" "$<$<CONFIG:Release>:NDEBUG>") | ||
set_property(TARGET libid3tag PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
|
||
find_package(ZLIB REQUIRED CONFIG) | ||
target_link_libraries(libid3tag PRIVATE ZLIB::ZLIB) | ||
|
||
install(TARGETS libid3tag | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION bin | ||
) | ||
install(FILES id3tag.h DESTINATION include) |
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 |
---|---|---|
@@ -1,124 +1,121 @@ | ||
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild | ||
from conans.errors import ConanInvalidConfiguration | ||
import os | ||
import shutil | ||
|
||
required_conan_version = ">=1.33.0" | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.build import cross_building | ||
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout | ||
from conan.tools.env import VirtualBuildEnv | ||
from conan.tools.files import chdir, copy, get, rm, replace_in_file | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps | ||
from conan.tools.layout import basic_layout | ||
from conan.tools.microsoft import is_msvc | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class LibId3TagConan(ConanFile): | ||
name = "libid3tag" | ||
description = "ID3 tag manipulation library." | ||
topics = ("conan", "mad", "id3", "MPEG", "audio", "decoder") | ||
license = "GPL-2.0-or-later" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://www.underbit.com/products/mad/" | ||
license = "GPL-2.0-or-later" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
generator = "pkg_config", "visual_studio" | ||
topics = ("mad", "id3", "MPEG", "audio", "decoder") | ||
|
||
_autotools = None | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": 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: | ||
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 requirements(self): | ||
self.requires("zlib/1.2.11") | ||
def layout(self): | ||
if is_msvc(self): | ||
cmake_layout(self, src_folder="src") | ||
else: | ||
basic_layout(self, src_folder="src") | ||
|
||
@property | ||
def _is_msvc(self): | ||
return self.settings.compiler == "Visual Studio" or ( | ||
self.settings.compiler == "clang" and self.settings.os == "Windows" | ||
) | ||
def requirements(self): | ||
self.requires("zlib/[>=1.2.11 <2]") | ||
|
||
def validate(self): | ||
if self._is_msvc and self.options.shared: | ||
raise ConanInvalidConfiguration("libid3tag does not support shared library for MSVC") | ||
|
||
@property | ||
def _settings_build(self): | ||
return getattr(self, "settings_build", self.settings) | ||
if cross_building(self) and self.settings.arch == "armv8" and self.options.shared: | ||
# https://github.com/conan-io/conan-center-index/pull/18987#issuecomment-1668243831 | ||
raise ConanInvalidConfiguration("shared library cross-building is not supported for armv8") | ||
|
||
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") | ||
|
||
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): | ||
if is_msvc(self): | ||
tc = CMakeToolchain(self) | ||
tc.preprocessor_definitions["ID3TAG_EXPORT"] = "__declspec(dllexport)" if self.options.shared else "" | ||
tc.generate() | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
else: | ||
venv = VirtualBuildEnv(self) | ||
venv.generate() | ||
tc = AutotoolsToolchain(self) | ||
tc.generate() | ||
deps = AutotoolsDeps(self) | ||
deps.generate() | ||
|
||
def build(self): | ||
if self._is_msvc: | ||
self._build_msvc() | ||
if is_msvc(self): | ||
# https://github.com/markjeee/libid3tag/blob/master/id3tag.h#L355-L358 | ||
replace_in_file(self, os.path.join(self.source_folder, "id3tag.h"), | ||
"extern char", "ID3TAG_EXPORT extern char") | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
else: | ||
self._build_autotools() | ||
|
||
def _build_msvc(self): | ||
kwargs = {} | ||
with tools.chdir(os.path.join(self._source_subfolder, "msvc++")): | ||
# cl : Command line error D8016: '/ZI' and '/Gy-' command-line options are incompatible | ||
tools.replace_in_file("libid3tag.dsp", "/ZI ", "") | ||
if self.settings.compiler == "clang": | ||
tools.replace_in_file("libid3tag.dsp", "CPP=cl.exe", "CPP=clang-cl.exe") | ||
tools.replace_in_file("libid3tag.dsp", "RSC=rc.exe", "RSC=llvm-rc.exe") | ||
kwargs["toolset"] = "ClangCl" | ||
if self.settings.arch == "x86_64": | ||
tools.replace_in_file("libid3tag.dsp", "Win32", "x64") | ||
with tools.vcvars(self.settings): | ||
self.run("devenv /Upgrade libid3tag.dsp") | ||
msbuild = MSBuild(self) | ||
msbuild.build(project_file="libid3tag.vcxproj", **kwargs) | ||
|
||
def _configure_autotools(self): | ||
if not self._autotools: | ||
if self.options.shared: | ||
args = ["--disable-static", "--enable-shared"] | ||
else: | ||
args = ["--disable-shared", "--enable-static"] | ||
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) | ||
self._autotools.configure(args=args, configure_dir=self._source_subfolder) | ||
return self._autotools | ||
|
||
@property | ||
def _user_info_build(self): | ||
return getattr(self, "user_info_build", self.deps_user_info) | ||
|
||
def _build_autotools(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")) | ||
autotools = self._configure_autotools() | ||
autotools.make() | ||
|
||
def _install_autotools(self): | ||
autotools = self._configure_autotools() | ||
autotools.install() | ||
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") | ||
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), os.path.dirname(gnu_config), self.source_folder) | ||
with chdir(self, self.source_folder): | ||
autotools = Autotools(self) | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def package(self): | ||
self.copy("COPYRIGHT", dst="licenses", src=self._source_subfolder) | ||
self.copy("COPYING", dst="licenses", src=self._source_subfolder) | ||
self.copy("CREDITS", dst="licenses", src=self._source_subfolder) | ||
if self._is_msvc: | ||
self.copy(pattern="*.lib", dst="lib", src=self._source_subfolder, keep_path=False) | ||
self.copy(pattern="id3tag.h", dst="include", src=self._source_subfolder) | ||
for license_file in ["COPYRIGHT", "COPYING", "CREDITS"]: | ||
copy(self, license_file, self.source_folder, os.path.join(self.package_folder, "licenses")) | ||
if is_msvc(self): | ||
cmake = CMake(self) | ||
cmake.install() | ||
else: | ||
self._install_autotools() | ||
with chdir(self, self.source_folder): | ||
autotools = Autotools(self) | ||
autotools.install() | ||
rm(self, "*.la", self.package_folder, recursive=True) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["libid3tag" if self._is_msvc else "id3tag"] | ||
if is_msvc(self): | ||
self.cpp_info.libs = ["libid3tag"] | ||
self.cpp_info.defines.append("ID3TAG_EXPORT=" + ("__declspec(dllimport)" if self.options.shared else "")) | ||
else: | ||
self.cpp_info.libs = ["id3tag"] |
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 |
---|---|---|
@@ -1,8 +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() | ||
find_package(libid3tag REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE libid3tag::libid3tag) |
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 |
---|---|---|
@@ -1,17 +1,26 @@ | ||
from conans import ConanFile, CMake, tools | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
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): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_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,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/) |
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,17 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
|
||
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): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |