Skip to content

Commit

Permalink
(#25741) cli11: Compile by default, add header_only option
Browse files Browse the repository at this point in the history
* CLI11: Compile by default, add header_only option

* Fix package_type handling

* Better package_type handling

* Update recipes/cli11/all/conanfile.py

* Make Conan 1 happy

* Pass libs to cpp_info only when supported

Signed-off-by: Uilian Ries <[email protected]>

* Header-only true by default

Signed-off-by: Uilian Ries <[email protected]>

* Fix libdirs

Signed-off-by: Uilian Ries <[email protected]>

---------

Signed-off-by: Uilian Ries <[email protected]>
Co-authored-by: Abril Rincón Blanco <[email protected]>
Co-authored-by: Uilian Ries <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent 7293916 commit 9cbd329
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions recipes/cli11/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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
from conan.tools.scm import Version
import os

required_conan_version = ">=1.52.0"
Expand All @@ -12,20 +13,39 @@ class CLI11Conan(ConanFile):
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/CLIUtils/CLI11"
topics = "cli-parser", "cpp11", "no-dependencies", "cli", "header-only"
topics = "cli-parser", "cpp11", "no-dependencies", "cli"
package_type = "header-library"
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

options = {
"header_only": [True, False]
}
default_options = {
"header_only": True
}

@property
def _min_cppstd(self):
return "11"

@property
def _supports_compilation(self):
return Version(self.version) >= "2.3"

def configure(self):
if not self._supports_compilation:
# TODO: Back to config_options after Conan 1 freeze
del self.options.header_only
elif not self.options.header_only:
self.package_type = "static-library"

def layout(self):
cmake_layout(self, src_folder="src")

def package_id(self):
self.info.clear()
if not self._supports_compilation or self.info.options.header_only:
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
Expand All @@ -36,6 +56,8 @@ def source(self):

def generate(self):
tc = CMakeToolchain(self)
if self._supports_compilation:
tc.variables["CLI11_PRECOMPILED"] = not self.options.header_only
tc.variables["CLI11_BUILD_EXAMPLES"] = False
tc.variables["CLI11_BUILD_TESTS"] = False
tc.variables["CLI11_BUILD_DOCS"] = False
Expand All @@ -59,6 +81,11 @@ def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

if self._supports_compilation and not self.options.get_safe("header_only"):
self.cpp_info.libdirs = ["lib"]
self.cpp_info.libs = ["CLI11"]
self.cpp_info.defines = ["CLI11_COMPILE"]

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")
Expand Down
2 changes: 1 addition & 1 deletion recipes/cli11/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(CLI11 REQUIRED CONFIG)
Expand Down

0 comments on commit 9cbd329

Please sign in to comment.