Skip to content

Commit

Permalink
(conan-io#5581) argtable3: bump argtable3/3.2.0 + cmake target
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Jun 21, 2021
1 parent e73c349 commit e480327
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 9 deletions.
6 changes: 6 additions & 0 deletions recipes/argtable3/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
43 changes: 38 additions & 5 deletions recipes/argtable3/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -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]

59 changes: 59 additions & 0 deletions recipes/argtable3/all/patches/3.2.0-0001-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -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})
10 changes: 8 additions & 2 deletions recipes/argtable3/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion recipes/argtable3/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion recipes/argtable3/all/test_package/test_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions recipes/argtable3/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"3.2.0":
folder: "all"
"3.1.5":
folder: "all"

0 comments on commit e480327

Please sign in to comment.