This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cargs: migrate to Conan v2 (conan-io#18704)
* cargs: migrate to Conan v2 * cargs: restore VirtualRunEnv in test_package * cargs: fix packaging of DLLs
- Loading branch information
1 parent
7fefb3f
commit 7b7615b
Showing
6 changed files
with
100 additions
and
56 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,68 +1,86 @@ | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
|
||
required_conan_version = ">=1.33.0" | ||
from conan import ConanFile | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.files import copy, get | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class CargsConan(ConanFile): | ||
name = "cargs" | ||
description = "A lightweight getopt replacement that works on Linux, " \ | ||
"Windows and macOS. Command line argument parser library" \ | ||
" for C/C++. Can be used to parse argv and argc parameters." | ||
url = "https://github.com/conan-io/conan-center-index" | ||
description = ( | ||
"A lightweight getopt replacement that works on Linux, " | ||
"Windows and macOS. Command line argument parser library" | ||
" for C/C++. Can be used to parse argv and argc parameters." | ||
) | ||
license = "MIT" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://likle.github.io/cargs/" | ||
topics = ("cargs", "cross-platform", "windows", "macos", "osx", "linux", | ||
"getopt", "getopt-long", "command-line-parser", "command-line", | ||
"arguments", "argument-parser") | ||
exports_sources = ["CMakeLists.txt"] | ||
generators = "cmake" | ||
|
||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {'shared': False, 'fPIC': True} | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
@property | ||
def _build_subfolder(self): | ||
return "build_subfolder" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
} | ||
|
||
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): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def validate(self): | ||
if self.settings.compiler.get_safe("cppstd"): | ||
check_min_cppstd(self, 11) | ||
|
||
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): | ||
tc = CMakeToolchain(self) | ||
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared | ||
tc.generate() | ||
tc = CMakeDeps(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.definitions["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared and self.settings.os == "Windows" | ||
cmake.configure(build_folder=self._build_subfolder) | ||
cmake.configure() | ||
cmake.build(target="cargs") | ||
|
||
def package(self): | ||
include_dir = os.path.join(self._source_subfolder, 'include') | ||
lib_dir = os.path.join(self._build_subfolder, "lib") | ||
bin_dir = os.path.join(self._build_subfolder, "bin") | ||
|
||
self.copy("LICENSE.md", dst="licenses", src=self._source_subfolder) | ||
self.copy("cargs.h", dst="include", src=include_dir) | ||
self.copy(pattern="*.a", dst="lib", src=lib_dir, keep_path=False) | ||
self.copy(pattern="*.lib", dst="lib", src=lib_dir, keep_path=False) | ||
self.copy(pattern="*.dylib", dst="lib", src=lib_dir, keep_path=False) | ||
self.copy(pattern="*.so*", dst="lib", src=lib_dir, keep_path=False, | ||
symlinks=True) | ||
self.copy(pattern="*.dll", dst="bin", src=bin_dir, keep_path=False) | ||
copy(self, "LICENSE.md", | ||
dst=os.path.join(self.package_folder, "licenses"), | ||
src=self.source_folder) | ||
copy(self, "cargs.h", | ||
dst=os.path.join(self.package_folder, "include"), | ||
src=os.path.join(self.source_folder, "include")) | ||
for pattern in ["*.a", "*.so*", "*.dylib", "*.lib"]: | ||
copy(self, pattern, | ||
dst=os.path.join(self.package_folder, "lib"), | ||
src=self.build_folder, | ||
keep_path=False) | ||
copy(self, "*.dll", | ||
dst=os.path.join(self.package_folder, "bin"), | ||
src=self.build_folder, | ||
keep_path=False) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = tools.collect_libs(self) | ||
self.cpp_info.libs = ["cargs"] |
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,9 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package) | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package LANGUAGES C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
find_package(cargs REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE cargs::cargs) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) |
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,16 +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.settings): | ||
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,16 @@ | ||
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.settings): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |