From e48032727ff3cef330a10448139627f566a029f4 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Mon, 24 May 2021 11:01:23 +0200 Subject: [PATCH] (#5581) argtable3: bump argtable3/3.2.0 + cmake target --- recipes/argtable3/all/conandata.yml | 6 ++ recipes/argtable3/all/conanfile.py | 43 ++++++++++++-- .../all/patches/3.2.0-0001-cmake-fixes.patch | 59 +++++++++++++++++++ .../argtable3/all/test_package/CMakeLists.txt | 10 +++- .../argtable3/all/test_package/conanfile.py | 2 +- .../argtable3/all/test_package/test_package.c | 2 +- recipes/argtable3/config.yml | 2 + 7 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 recipes/argtable3/all/patches/3.2.0-0001-cmake-fixes.patch diff --git a/recipes/argtable3/all/conandata.yml b/recipes/argtable3/all/conandata.yml index c574a6f578c9c4..fee3576463e96a 100644 --- a/recipes/argtable3/all/conandata.yml +++ b/recipes/argtable3/all/conandata.yml @@ -1,8 +1,14 @@ sources: + "3.2.0": + url: "https://github.com/argtable/argtable3/archive/refs/tags/v3.2.0.7402e6e.tar.gz" + sha256: "e692ce51fb51dc750b47ef0ef2941573c8c49195aa2ddc48cb369239c400efa7" "3.1.5": url: "https://github.com/argtable/argtable3/archive/v3.1.5.1c1bb23.tar.gz" sha256: "e2435562ece10bbf52c21811fe6ec25a3574054886cb56d483e5c17451329bb4" patches: + "3.2.0": + - patch_file: "patches/3.2.0-0001-cmake-fixes.patch" + base_path: "source_subfolder" "3.1.5": - patch_file: "patches/3.1.5-0001-cmake-fixes.patch" base_path: "source_subfolder" diff --git a/recipes/argtable3/all/conanfile.py b/recipes/argtable3/all/conanfile.py index 5370b9fa9271a8..13c8fc1b470dd9 100644 --- a/recipes/argtable3/all/conanfile.py +++ b/recipes/argtable3/all/conanfile.py @@ -1,6 +1,8 @@ from conans import CMake, ConanFile, tools -import glob import os +import textwrap + +required_conan_version = ">=1.33.0" class Argtable3Conan(ConanFile): @@ -39,8 +41,7 @@ def configure(self): del self.settings.compiler.cppstd def source(self): - tools.get(**self.conan_data["sources"][self.version]) - os.rename(glob.glob("argtable3-*")[0], self._source_subfolder) + tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) def _configure_cmake(self): if self._cmake: @@ -58,6 +59,27 @@ def build(self): cmake = self._configure_cmake() cmake.build() + @property + def _module_subfolder(self): + return os.path.join("lib", "cmake") + + @property + def _module_file_rel_path(self): + return os.path.join(self._module_subfolder, + "conan-official-{}-targets.cmake".format(self.name)) + + @staticmethod + def _create_cmake_module_alias_targets(module_file, targets): + content = "" + for alias, aliased in targets.items(): + content += textwrap.dedent("""\ + if(TARGET {aliased} AND NOT TARGET {alias}) + add_library({alias} INTERFACE IMPORTED) + set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) + endif() + """.format(alias=alias, aliased=aliased)) + tools.save(module_file, content) + def package(self): self.copy("LICENSE", src=self._source_subfolder, dst="licenses") cmake = self._configure_cmake() @@ -66,11 +88,22 @@ def package(self): tools.rmdir(os.path.join(self.package_folder, "cmake")) tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + target_name = "argtable3" if self.options.shared else "argtable3_static" + self._create_cmake_module_alias_targets( + os.path.join(self.package_folder, self._module_file_rel_path), + {target_name: "argtable3::argtable3"} + ) + def package_info(self): self.cpp_info.libs = ["argtable3" if self.options.shared else "argtable3_static"] if not self.options.shared: if self.settings.os == "Linux": self.cpp_info.system_libs.append("m") - # FIXME: the cmake targets are exported without namespace + self.cpp_info.filenames["cmake_find_package"] = "Argtable3" - self.cpp_info.filenames["cmake_find_package_config"] = "Argtable3" + self.cpp_info.filenames["cmake_find_package_multi"] = "Argtable3" + + self.cpp_info.builddirs.append(self._module_subfolder) + self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path] + self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] + diff --git a/recipes/argtable3/all/patches/3.2.0-0001-cmake-fixes.patch b/recipes/argtable3/all/patches/3.2.0-0001-cmake-fixes.patch new file mode 100644 index 00000000000000..79ff2d7ad82ba6 --- /dev/null +++ b/recipes/argtable3/all/patches/3.2.0-0001-cmake-fixes.patch @@ -0,0 +1,59 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -93,7 +93,7 @@ + endif() + + add_subdirectory(src) +-add_subdirectory(examples) ++#add_subdirectory(examples) + + if(ARGTABLE3_ENABLE_TESTS) + enable_testing() +--- src/CMakeLists.txt ++++ src/CMakeLists.txt +@@ -57,7 +57,7 @@ + endif() + + add_definitions(-D_XOPEN_SOURCE=700) +- ++if(BUILD_SHARED_LIBS) + if(WIN32) + set(COMPANY_NAME "The Argtable3 Project") + set(FILE_DESC "ANSI C command-line parsing library") +@@ -75,13 +75,13 @@ + add_library(argtable3 SHARED ${ARGTABLE3_SRC_FILES}) + endif() + target_include_directories(argtable3 PRIVATE ${PROJECT_SOURCE_DIR}/src) +- +-add_library(argtable3_static STATIC ${ARGTABLE3_SRC_FILES}) +-target_include_directories(argtable3_static PRIVATE ${PROJECT_SOURCE_DIR}/src) +- +-set_target_properties(argtable3 argtable3_static PROPERTIES ++set_target_properties(argtable3 PROPERTIES + VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} + SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) ++target_include_directories(argtable3 PRIVATE ${PROJECT_SOURCE_DIR}/src) ++else() ++add_library(argtable3_static STATIC ${ARGTABLE3_SRC_FILES}) ++endif() + + include(GNUInstallDirs) + if(UNIX OR MSYS OR MINGW) +@@ -89,14 +89,16 @@ + elseif(WIN32) + set(ARGTABLE3_INSTALL_CMAKEDIR "cmake") + endif() +- ++if(BUILD_SHARED_LIBS) + install(TARGETS argtable3 + EXPORT ${ARGTABLE3_PACKAGE_NAME}Config + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) ++else() + install(TARGETS argtable3_static + EXPORT ${ARGTABLE3_PACKAGE_NAME}Config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) ++endif() + install(FILES "${PROJECT_SOURCE_DIR}/src/argtable3.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(EXPORT ${ARGTABLE3_PACKAGE_NAME}Config DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR}) diff --git a/recipes/argtable3/all/test_package/CMakeLists.txt b/recipes/argtable3/all/test_package/CMakeLists.txt index 3a403dc404b416..fab7dc3090af10 100644 --- a/recipes/argtable3/all/test_package/CMakeLists.txt +++ b/recipes/argtable3/all/test_package/CMakeLists.txt @@ -2,7 +2,13 @@ cmake_minimum_required(VERSION 3.1) project(test_package C) include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup() +conan_basic_setup(TARGETS) + +find_package(Argtable3 REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +if(TARGET argtable3) + target_link_libraries(${PROJECT_NAME} argtable3) +else() + target_link_libraries(${PROJECT_NAME} argtable3_static) +endif() diff --git a/recipes/argtable3/all/test_package/conanfile.py b/recipes/argtable3/all/test_package/conanfile.py index 848a9ab4347a5e..9ea88425d278e7 100644 --- a/recipes/argtable3/all/test_package/conanfile.py +++ b/recipes/argtable3/all/test_package/conanfile.py @@ -4,7 +4,7 @@ class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + generators = "cmake", "cmake_find_package_multi" def build(self): cmake = CMake(self) diff --git a/recipes/argtable3/all/test_package/test_package.c b/recipes/argtable3/all/test_package/test_package.c index b094ac5c788db1..b144621bb58d02 100644 --- a/recipes/argtable3/all/test_package/test_package.c +++ b/recipes/argtable3/all/test_package/test_package.c @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) }; int exitcode = 0; - char progname[] = "util.exe"; + char *progname = argv[0]; int nerrors; nerrors = arg_parse(argc,argv,argtable); diff --git a/recipes/argtable3/config.yml b/recipes/argtable3/config.yml index 991b5cdd0f2f07..e33f13d2032a59 100644 --- a/recipes/argtable3/config.yml +++ b/recipes/argtable3/config.yml @@ -1,3 +1,5 @@ versions: + "3.2.0": + folder: "all" "3.1.5": folder: "all"