Skip to content

Commit 8d9f419

Browse files
committed
refactor: improve Conan v2 support
1 parent be880f1 commit 8d9f419

15 files changed

+196
-246
lines changed

.gitignore

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ build-*/
44
log/
55
.idea
66
cmake-build-debug
7-
/CMakeUserPresets.json
8-
/conan.lock
9-
/conanbuildinfo.txt
10-
/conaninfo.txt
11-
/graph_info.json
7+
CMakeUserPresets.json
8+
conan.lock
9+
conanbuildinfo.txt
10+
conaninfo.txt
11+
graph_info.json

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## v1.1.0
44
- Complete revamp
5-
- Conan support
5+
- Conan v2 support
66

77
## v0.3.2
88

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16)
33
project(spdlog_setup
44
LANGUAGES CXX)
55

6-
set(CMAKE_CXX_STANDARD 20)
6+
set(CMAKE_CXX_STANDARD 17)
77
set(CMAKE_CXX_STANDARD_REQUIRED ON)
88
set(CMAKE_CXX_EXTENSIONS OFF)
99

README.md

+5-126
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,17 @@
33
## Overview
44

55
Header-only [`spdlog`](https://github.com/gabime/spdlog) file-based setup
6-
library for convenience in initializing spdlog. Inspired by
7-
[`spdlog-config`](https://github.com/objectx/spdlog-config) for using
6+
library for convenience in initializing spdlog. It is using
87
[`TOML`](https://github.com/toml-lang/toml) configuration, a format that is
98
simple and easy-to-read.
109

11-
[![Build Status](https://travis-ci.org/guangie88/spdlog_setup.svg?branch=master)](https://travis-ci.org/guangie88/spdlog_setup)
12-
[![Build status](https://ci.appveyor.com/api/projects/status/srek5xih80104eds/branch/master?svg=true)](https://ci.appveyor.com/project/guangie88/spdlog-setup/branch/master)
13-
[![codecov](https://codecov.io/gh/guangie88/spdlog_setup/branch/master/graph/badge.svg)](https://codecov.io/gh/guangie88/spdlog_setup)
14-
1510
## Requirements
1611

17-
Requires at least `CMake 3.3`, `g++-4.9` for Linux, or `MSVC2015` with `MSBuild`
18-
for Windows, providing sufficient C++11 features.
19-
20-
`g++-4.8` will notably fail because of the missing `std::regex` implementation.
21-
`MSVC2013` will fail too as it does not accept `noexcept`, which is used in some
22-
of the functions.
23-
24-
Tested against:
25-
26-
- `g++-4.9`
27-
- `g++-5`
28-
- `g++-6`
29-
- `g++-7`
30-
- `g++-8`
31-
- `clang-3.6`
32-
- `clang-3.7`
33-
- `clang-3.8`
34-
- `clang-3.9`
35-
- `clang-4.0`
36-
- `clang-5.0`
37-
- `clang-6.0`
38-
- `clang-7`
39-
- `cl` (v140 / MSVC2015)
40-
- `cl` (v141 / MSVC2017)
12+
Requires at least `Conan v1.59` or `Conan v2.x`
4113

4214
## Features
4315

44-
- Header-only (check [`How to Install`](#how-to-install) to extract out the
45-
header files).
16+
- Header-only
4617
- Initialization of `spdlog` sinks, patterns and loggers based on `TOML`
4718
configuration file.
4819
- Tag replacement (e.g. "{tagname}-log.txt") within the `TOML` configuration
@@ -53,94 +24,19 @@ Tested against:
5324

5425
See [CHANGELOG.md](./CHANGELOG.md) for more details.
5526

56-
## Repository Checkout
57-
58-
Since this repository has other git-based dependencies as `git` submodules, use
59-
the command:
60-
`git clone --recursive https://github.com/guangie88/spdlog_setup.git` in order
61-
to clone all the submodule dependencies.
62-
63-
If the repository has already been cloned without the submodules, then instead
64-
run: `git submodule update --init --recursive` in order to clone all the
65-
submodule dependencies.
66-
6727
## Dependencies
6828

6929
This repository uses the following external dependencies directly:
7030

7131
- [`Catch`](https://github.com/philsquared/Catch) (only for unit-tests, not
7232
included in installation)
7333
- [`spdlog`](https://github.com/gabime/spdlog)
74-
75-
In addition, the following dependencies are inlined as part of the include:
76-
7734
- [`cpptoml`](https://github.com/skystrife/cpptoml)
7835
- [`fmt`](https://github.com/fmtlib/fmt.git)
7936

8037
## How to Build
8138

82-
This guide prefers a `CMake` out-of-source build style. For build with unit
83-
tests, add `-DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON` during the CMake
84-
configuration.
85-
86-
## How to Install
87-
88-
If a recent enough `spdlog` is already available, and unit tests are not to be
89-
run, it is possible to just copy the `spdlog_setup` directory within `include`
90-
into another solution for header-only include, as long as `spdlog` can be found
91-
in that solution.
92-
93-
If `spdlog` is not available, the installation step of `CMake` can copy out the
94-
entire list of header files required for `spdlog_setup` into the installation
95-
directory, including `spdlog`. To change the installation directory, add
96-
`-DCMAKE_INSTALL_PREFIX=<path-to-install>` during the CMake configuration.
97-
98-
### Linux (`GCC`)
99-
100-
In the root directory after `git` cloning:
101-
102-
#### Debug without Installation
103-
104-
- `mkdir build-debug`
105-
- `cd build-debug`
106-
- `cmake .. -DCMAKE_BUILD_TYPE=Debug -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON`
107-
- `cmake --build .`
108-
109-
Now the unit test executable should be compiled and residing in
110-
`build-debug/spdlog_setup_unit_test`.
111-
112-
#### Release with Installation
113-
114-
- `mkdir build-release`
115-
- `cd build-release`
116-
- `cmake .. -DCMAKE_BUILD_TYPE=Release -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=install`
117-
- `cmake --build . --target install`
118-
119-
Now the unit test executable should be compiled and residing in
120-
`build-release/spdlog_setup_unit_test`.
121-
122-
The header files should be installed in `build-release/install/include`.
123-
124-
### Windows (`MSVC2015` as Example)
125-
126-
Ensure that [`Microsoft Build Tools 2015`](https://www.microsoft.com/en-sg/download/details.aspx?id=48159)
127-
and [`Visual C++ Build Tools 2015`](http://landinghub.visualstudio.com/visual-cpp-build-tools)
128-
(or `Visual Studio 2015`) have been installed.
129-
130-
In the root directory after `git` cloning:
131-
132-
- `mkdir build`
133-
- `cd build`
134-
- `cmake .. -G "Visual Studio 14 Win64" -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=install`
135-
- (Debug) `cmake --build . --config Debug`
136-
- (Release with installation) `cmake --build . --config Release --target install`
137-
138-
Now the unit test executable should be compiled and residing in
139-
140-
- (Debug) `build/Debug/spdlog_setup_unit_test.exe` or
141-
- (Release) `build/Release/spdlog_setup_unit_test.exe`.
142-
143-
The header files should be installed in `build/install/include`.
39+
- `conan build -b mising .`
14440

14541
## Supported Sinks
14642

@@ -391,7 +287,6 @@ level = "trace"
391287

392288
```c++
393289
#include <spdlog_setup/spdlog_setup.hpp>
394-
395290
#include <iostream>
396291
#include <string>
397292

@@ -422,7 +317,6 @@ int main() {
422317

423318
```c++
424319
#include <spdlog_setup/spdlog_setup.hpp>
425-
426320
#include <string>
427321

428322
int main(const int argc, const char * argv[]) {
@@ -475,23 +369,8 @@ all the source code files.
475369
Please try to run
476370
477371
```bash
478-
./run-clang-format.sh
372+
./reformat.sh
479373
```
480374

481375
which will pull the appropriate Docker image to run the formatting command over
482376
the entire repository directory.
483-
484-
If your `docker` command requires `sudo`, then you will need to run it as
485-
486-
```bash
487-
sudo sh ./run-clang-format.sh
488-
```
489-
490-
Alternatively, you could also try to set up your own `clang-format` (currently
491-
this repository uses version 7), and run
492-
493-
```bash
494-
clang-format -i path_to_h_cpp_file
495-
```
496-
497-
over the changed files.

conanfile.py

+69-23
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,73 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
41
from conan import ConanFile
5-
from conan.tools.files import copy
6-
from conan.tools.cmake import CMake, cmake_layout
2+
from conan.errors import ConanInvalidConfiguration
73
from conan.tools.build import check_min_cppstd
4+
from conan.tools.files import copy
5+
from conan.tools.scm import Version
6+
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
7+
8+
import os
9+
10+
required_conan_version = ">=1.52.0"
811

912

1013
class SpdlogSetupConan(ConanFile):
1114
name = "spdlog_setup"
1215
version = "1.1.0"
13-
description = "TOML config for spdlog"
14-
url = "https://github.com/gegles/spdlog_setup"
15-
topics = ("spdlog", "logging", "header-only", "TOML", "cpptoml")
16+
description = "Setup spdlog via a TOML config file"
1617
license = "MIT"
17-
18+
url = "https://github.com/conan-io/conan-center-index"
19+
homepage = "https://github.com/gegles/spdlog_setup"
20+
topics = ('spdlog', 'logging', 'header-only', 'TOML', 'cpptoml')
21+
package_type = "header-library"
1822
settings = "os", "arch", "compiler", "build_type"
1923
exports_sources = "include/*", "test/*", "CMakeLists.txt"
2024
no_copy_source = True
21-
generators = "CMakeToolchain", "CMakeDeps"
25+
default_options = {"fmt/*:header_only": True,
26+
"spdlog/*:header_only": True}
27+
28+
@property
29+
def _min_cppstd(self):
30+
return 17
31+
32+
@property
33+
def _compilers_minimum_version(self):
34+
return {
35+
"Visual Studio": "16",
36+
"msvc": "192",
37+
"gcc": "8",
38+
"clang": "7",
39+
"apple-clang": "12.0",
40+
}
2241

23-
def config_options(self):
24-
self.options["fmt"].header_only = True
25-
self.options["spdlog"].header_only = True
42+
def layout(self):
43+
cmake_layout(self)
2644

2745
def build_requirements(self):
28-
self.test_requires("catch2/[>=3.1.0]")
46+
self.test_requires("catch2/3.3.2")
2947

3048
def requirements(self):
31-
self.requires("cpptoml/[>=0.1.1]")
32-
self.requires("spdlog/[>=1.11.0]")
33-
self.requires("fmt/[>=9.1.0]")
49+
self.requires("cpptoml/0.1.1", transitive_headers=True)
50+
self.requires("spdlog/1.11.0", transitive_headers=True, transitive_libs=True)
51+
self.requires("fmt/9.1.0", transitive_headers=True, transitive_libs=True)
52+
53+
def package_id(self):
54+
self.info.clear()
3455

3556
def validate(self):
36-
check_min_cppstd(self, 17)
57+
if self.settings.compiler.get_safe("cppstd"):
58+
check_min_cppstd(self, self._min_cppstd)
59+
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
60+
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
61+
raise ConanInvalidConfiguration(
62+
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
63+
)
3764

38-
def layout(self):
39-
cmake_layout(self)
65+
def generate(self):
66+
if not self.conf.get("tools.build:skip_test", default=False):
67+
tc = CMakeToolchain(self)
68+
tc.generate()
69+
deps = CMakeDeps(self)
70+
deps.generate()
4071

4172
def build(self):
4273
if not self.conf.get("tools.build:skip_test", default=False):
@@ -46,7 +77,22 @@ def build(self):
4677
cmake.test()
4778

4879
def package(self):
49-
copy(self, "*.hpp", self.source_folder, self.package_folder)
80+
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
81+
copy(
82+
self,
83+
pattern="*.hpp",
84+
dst=os.path.join(self.package_folder, "include"),
85+
src=os.path.join(self.source_folder, "include"),
86+
)
5087

51-
def package_id(self):
52-
self.info.clear()
88+
def package_info(self):
89+
self.cpp_info.bindirs = []
90+
self.cpp_info.libdirs = []
91+
self.cpp_info.set_property("cmake_file_name", "spdlog_setup")
92+
self.cpp_info.set_property("cmake_target_name", "spdlog_setup::spdlog_setup")
93+
94+
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
95+
self.cpp_info.filenames["cmake_find_package"] = "SPDLOG_SETUP"
96+
self.cpp_info.filenames["cmake_find_package_multi"] = "spdlog_setup"
97+
self.cpp_info.names["cmake_find_package"] = "SPDLOG_SETUP"
98+
self.cpp_info.names["cmake_find_package_multi"] = "spdlog_setup"

0 commit comments

Comments
 (0)