mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
[conan] Fix the Conan package for multiple static library use
This commit is contained in:
parent
2e1ce37faa
commit
49e000b505
@ -49,7 +49,7 @@ class BuilderSettings(object):
|
|||||||
def reference(self):
|
def reference(self):
|
||||||
""" Read project version from branch create Conan reference
|
""" Read project version from branch create Conan reference
|
||||||
"""
|
"""
|
||||||
return os.getenv("CONAN_REFERENCE", "Catch2/{}".format(self._version))
|
return os.getenv("CONAN_REFERENCE", "catch2/{}".format(self._version))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def channel(self):
|
def channel(self):
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
cmake_minimum_required(VERSION 3.2.0)
|
cmake_minimum_required(VERSION 3.2.0)
|
||||||
project(test_package CXX)
|
project(test_package CXX)
|
||||||
|
|
||||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
# We set it only for the convenience of calling the executable
|
||||||
conan_basic_setup(TARGETS)
|
# in the package test function
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
|
|
||||||
find_package(Catch2 REQUIRED CONFIG)
|
find_package(Catch2 REQUIRED CONFIG)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||||
target_link_libraries(${PROJECT_NAME} CONAN_PKG::Catch2Main)
|
# Note: Conan 1.21 doesn't support granular target generation yet.
|
||||||
|
# The Main library would be included into the unified target.
|
||||||
|
# It's controlled by the `with_main` option in the recipe.
|
||||||
|
target_link_libraries(${PROJECT_NAME} Catch2::Catch2)
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
|
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
|
||||||
|
@ -6,7 +6,7 @@ import os
|
|||||||
|
|
||||||
class TestPackageConan(ConanFile):
|
class TestPackageConan(ConanFile):
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
generators = "cmake"
|
generators = "cmake_find_package_multi"
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
cmake = CMake(self)
|
cmake = CMake(self)
|
||||||
@ -14,6 +14,6 @@ class TestPackageConan(ConanFile):
|
|||||||
cmake.build()
|
cmake.build()
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
assert os.path.isfile(os.path.join(self.deps_cpp_info["Catch2"].rootpath, "licenses", "LICENSE.txt"))
|
assert os.path.isfile(os.path.join(self.deps_cpp_info["catch2"].rootpath, "licenses", "LICENSE.txt"))
|
||||||
bin_path = os.path.join("bin", "test_package")
|
bin_path = os.path.join("bin", "test_package")
|
||||||
self.run("%s -s" % bin_path, run_environment=True)
|
self.run("%s -s" % bin_path, run_environment=True)
|
||||||
|
16
conanfile.py
16
conanfile.py
@ -3,16 +3,20 @@ from conans import ConanFile, CMake
|
|||||||
|
|
||||||
|
|
||||||
class CatchConan(ConanFile):
|
class CatchConan(ConanFile):
|
||||||
name = "Catch2"
|
name = "catch2"
|
||||||
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
|
description = "A modern, C++-native, framework for unit-tests, TDD and BDD"
|
||||||
topics = ("conan", "catch2", "unit-test", "tdd", "bdd")
|
topics = ("conan", "catch2", "unit-test", "tdd", "bdd")
|
||||||
url = "https://github.com/catchorg/Catch2"
|
url = "https://github.com/catchorg/Catch2"
|
||||||
homepage = url
|
homepage = url
|
||||||
license = "BSL-1.0"
|
license = "BSL-1.0"
|
||||||
|
|
||||||
exports = "LICENSE.txt"
|
exports = "LICENSE.txt"
|
||||||
exports_sources = ("src/*", "CMakeLists.txt", "CMake/*", "extras/*")
|
exports_sources = ("src/*", "CMakeLists.txt", "CMake/*", "extras/*")
|
||||||
|
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
generators = "cmake"
|
|
||||||
|
options = {"with_main": [True, False]}
|
||||||
|
default_options = {"with_main": True}
|
||||||
|
|
||||||
def _configure_cmake(self):
|
def _configure_cmake(self):
|
||||||
cmake = CMake(self)
|
cmake = CMake(self)
|
||||||
@ -31,7 +35,11 @@ class CatchConan(ConanFile):
|
|||||||
cmake = self._configure_cmake()
|
cmake = self._configure_cmake()
|
||||||
cmake.install()
|
cmake.install()
|
||||||
|
|
||||||
|
def package_id(self):
|
||||||
|
del self.info.options.with_main
|
||||||
|
|
||||||
def package_info(self):
|
def package_info(self):
|
||||||
self.cpp_info.libs = ['Catch2Main', 'Catch2']
|
self.cpp_info.libs = [
|
||||||
|
'Catch2Main', 'Catch2'] if self.options.with_main else ['Catch2']
|
||||||
self.cpp_info.names["cmake_find_package"] = "Catch2"
|
self.cpp_info.names["cmake_find_package"] = "Catch2"
|
||||||
self.cpp_info.names["cmake_find_package_multi"] = "Catch2"
|
self.cpp_info.names["cmake_find_package_multi"] = "Catch2"
|
||||||
|
Loading…
Reference in New Issue
Block a user