-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cli11: conan v2 support * Fix for test_v1_package * Apply suggestions from code review Co-authored-by: Uilian Ries <uilianries@gmail.com> * Update recipes/cli11/all/test_v1_package/CMakeLists.txt Co-authored-by: toge <toge.mail@gmail.com> Co-authored-by: Uilian Ries <uilianries@gmail.com> Co-authored-by: toge <toge.mail@gmail.com>
- Loading branch information
1 parent
c936e6a
commit 2fc42d1
Showing
5 changed files
with
80 additions
and
29 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 |
---|---|---|
@@ -1,45 +1,64 @@ | ||
from conans import ConanFile, CMake, tools | ||
from conan import ConanFile | ||
from conan.tools.files import get, copy, rmdir | ||
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout | ||
from conan.tools.build import check_min_cppstd | ||
import os | ||
|
||
required_conan_version = ">=1.43.0" | ||
required_conan_version = ">=1.52.0" | ||
|
||
class CLI11Conan(ConanFile): | ||
name = "cli11" | ||
homepage = "https://github.com/CLIUtils/CLI11" | ||
description = "A command line parser for C++11 and beyond." | ||
topics = ("cli-parser", "cpp11", "no-dependencies", "cli", "header-only") | ||
topics = "cli-parser", "cpp11", "no-dependencies", "cli", "header-only" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
license = "BSD-3-Clause" | ||
settings = "os", "compiler", "build_type", "arch" | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
def _min_cppstd(self): | ||
return "11" | ||
|
||
def validate(self): | ||
if self.settings.compiler.get_safe("cppstd"): | ||
check_min_cppstd(self, self._min_cppstd) | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
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], destination=self.source_folder, strip_root=True) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["CLI11_BUILD_EXAMPLES"] = False | ||
tc.variables["CLI11_BUILD_TESTS"] = False | ||
tc.variables["CLI11_BUILD_DOCS"] = False | ||
tc.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
self.copy("LICENSE", dst="licenses", src=self._source_subfolder) | ||
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) | ||
cmake = CMake(self) | ||
cmake.definitions["CLI11_BUILD_EXAMPLES"] = False | ||
cmake.definitions["CLI11_BUILD_TESTS"] = False | ||
cmake.definitions["CLI11_BUILD_DOCS"] = False | ||
cmake.configure(source_folder=self._source_subfolder) | ||
cmake.install() | ||
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) | ||
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
# since 2.1.1 | ||
tools.rmdir(os.path.join(self.package_folder, "share")) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
|
||
def package_id(self): | ||
self.info.header_only() | ||
self.info.clear() | ||
|
||
def package_info(self): | ||
self.cpp_info.set_property("cmake_target_name", "CLI11::CLI11") | ||
self.cpp_info.set_property("cmake_file_name", "CLI11") | ||
self.cpp_info.set_property("cmake_target_name", "CLI11::CLI11") | ||
self.cpp_info.set_property("pkg_config_name", "CLI11") | ||
|
||
# TODO: to remove in conan v2 once cmake_find_package_* generators removed | ||
self.cpp_info.names["cmake_find_package"] = "CLI11" | ||
self.cpp_info.names["cmake_find_package_multi"] = "CLI11" | ||
self.cpp_info.names["pkg_config"] = "CLI11" |
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,11 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
cmake_minimum_required(VERSION 3.8) | ||
project(test_package CXX) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
find_package(CLI11 REQUIRED CONFIG) | ||
|
||
add_executable(${CMAKE_PROJECT_NAME} test_package.cpp) | ||
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY CXX_STANDARD 11) | ||
target_link_libraries(${CMAKE_PROJECT_NAME} CLI11::CLI11) | ||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE CLI11::CLI11) | ||
|
||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_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,17 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake_find_package_multi", "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.bindirs[0], "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.8) | ||
project(test_package LANGUAGES CXX) | ||
|
||
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 @@ | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake_find_package_multi", "cmake" | ||
|
||
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) |