Skip to content

Commit

Permalink
Improve and fix bugs in Conanfile
Browse files Browse the repository at this point in the history
- Fix issues with Conanfile - create a package which can be consumed by
  downstream Conan packages
- TODO: Add standard Conan workflow instructions to README
  • Loading branch information
Jacob Crabill authored and pboettch committed Nov 27, 2023
1 parent 349cba9 commit 704a545
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ endif ()
# Basic project definition #
]==============================================================================================]

# TODO: CMake >= 3.19 can use string(JSON VERSION GET "${METADATA}" "version") to load from JSON
set(PROJECT_VERSION 2.4.0)

# TODO: Version 3, rename the project and namespace to something more compact
project(nlohmann_json_schema_validator
VERSION 2.3.0
VERSION ${PROJECT_VERSION}
DESCRIPTION "Json validator for nlohmann::json library"
HOMEPAGE_URL "https://github.com/pboettch/json-schema-validator"
LANGUAGES CXX)
Expand Down
56 changes: 33 additions & 23 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import re
from conans import load, tools, ConanFile, CMake

from conan import ConanFile
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
from conans.tools import load
from conans import tools as ctools

def get_version():
try:
Expand All @@ -20,52 +23,59 @@ class JsonSchemaValidatorConan(ConanFile):
version = get_version()
url = 'https://github.com/pboettch/json-schema-validator'
license = 'MIT'

settings = 'os', 'compiler', 'build_type', 'arch'

options = {
'shared': [True, False],
'fPIC': [True, False],
'build_examples': [True, False],
'build_tests': [True, False]
'build_tests': [True, False],
'test_coverage': [True, False],
}

default_options = {
'shared': False,
'fPIC': True,
'build_examples': True,
'build_tests': False
'build_tests': False,
'test_coverage': False,
}
generators = "CMakeDeps"

generators = 'CMakeDeps', 'CMakeToolchain', 'VirtualBuildEnv', 'VirtualRunEnv'

exports_sources = [
'CMakeLists.txt',
'nlohmann_json_schema_validatorConfig.cmake.in',
'conanfile.py',
'cmake/*',
'src/*',
'app/*',
'example/*',
'test/*',
]
requires = (

requires = [
'nlohmann_json/3.11.2'
)
_cmake = None

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions['JSON_VALIDATOR_BUILD_EXAMPLES'] = self.options.build_examples
self._cmake.definitions['JSON_VALIDATOR_BUILD_TESTS'] = self.options.build_tests
self._cmake.configure()
return self._cmake
]

def generate(self):
tc = CMakeToolchain(self)
tc.variables['JSON_VALIDATOR_BUILD_EXAMPLES'] = self.options.build_examples
tc.variables['JSON_VALIDATOR_BUILD_TESTS'] = self.options.build_tests
tc.variables['JSON_VALIDATOR_SHARED_LIBS '] = self.options.shared
tc.variables['JSON_VALIDATOR_TEST_COVERAGE '] = self.options.test_coverage
tc.generate()

def layout(self):
build_type = str(self.settings.build_type).lower()
self.folders.build = "build-{}".format(build_type)
cmake_layout(self)

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.verbose = True
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()

def package_info(self):
Expand All @@ -74,7 +84,7 @@ def package_info(self):

libdir = os.path.join(self.package_folder, "lib")
self.cpp_info.libdirs = [libdir]
self.cpp_info.libs += tools.collect_libs(self, libdir)
self.cpp_info.libs += ctools.collect_libs(self, libdir)

bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
Expand Down

0 comments on commit 704a545

Please sign in to comment.