Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli11: Compile by default, add header_only option #25741

Merged
merged 8 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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