Skip to content

Commit

Permalink
conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Jan 22, 2023
1 parent 47e115a commit fc344f2
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 67 deletions.
7 changes: 0 additions & 7 deletions recipes/baical-p7/all/CMakeLists.txt

This file was deleted.

5 changes: 5 additions & 0 deletions recipes/baical-p7/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ sources:
"5.6":
url: "http://baical.net/files/libP7Client_v5.6.zip"
sha256: "7503bdf739b9c2aea297b49fa0aa0162b7090830aee1cbd4cf7be5d3c75600de"
patches:
"5.6":
- patch_file: "patches/0001-fix-cmake.patch"
patch_description: "Fix CMakeLists"
patch_type: "conan"
82 changes: 40 additions & 42 deletions recipes/baical-p7/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
import os
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.29.1"
required_conan_version = ">=1.53.0"


class BaicalP7Conan(ConanFile):
name = "baical-p7"
Expand All @@ -11,64 +14,59 @@ class BaicalP7Conan(ConanFile):
homepage = "http://baical.net/p7.html"
topics = ("p7", "baical", "logging", "telemetry")
description = "Baical P7 client"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
exports_sources = "CMakeLists.txt"
generators = "cmake"

_cmake = None
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _source_subfolder(self):
return "source_subfolder"
def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

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

def validate(self):
if self.settings.os not in ["Linux", "Windows"]:
raise ConanInvalidConfiguration("P7 only supports Windows and Linux at this time")

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination= self._source_subfolder)
get(self, **self.conan_data["sources"][self.version])

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["P7_TESTS_BUILD"] = False
self._cmake.definitions["P7_BUILD_SHARED"] = self.options.shared
self._cmake.definitions["P7_EXAMPLES_BUILD"] = False
self._cmake.configure()
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["P7_TESTS_BUILD"] = False
tc.cache_variables["P7_BUILD_SHARED"] = self.options.shared
tc.variables["P7_EXAMPLES_BUILD"] = False
tc.generate()

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

def package(self):
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*", dst="include", src=os.path.join(self._source_subfolder, "Headers"))
cmake = self._configure_cmake()
copy(self, "LICENSE.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.remove_files_by_mask(os.path.join(self.package_folder, "include"), "*.cmake")

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "p7"
self.cpp_info.names["cmake_find_package_multi"] = "p7"

if self.options.shared:
self.cpp_info.components["p7"].name = "p7-shared"
self.cpp_info.components["p7"].libs = ["p7-shared"]
else:
self.cpp_info.components["p7"].name = "p7"
self.cpp_info.components["p7"].libs = ["p7"]

if self.settings.os == "Linux":
self.cpp_info.components["p7"].system_libs .extend(["rt", "pthread"])
if self.settings.os == "Windows":
self.cpp_info.components["p7"].system_libs .append("Ws2_32")
self.cpp_info.libs = ["p7-shared" if self.options.shared else "p7"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["rt", "pthread"])
elif self.settings.os == "Windows":
self.cpp_info.system_libs.append("ws2_32")
86 changes: 86 additions & 0 deletions recipes/baical-p7/all/patches/0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

-#project(p7lib)
+project(p7lib)

#>>Build options **********************************************************************
option(P7_TESTS_BUILD "Build test" OFF)
@@ -25,7 +25,6 @@ if(NOT DEFINED ROOT_P7_PATH)
set(ROOT_P7_PATH ${PROJECT_SOURCE_DIR} CACHE INTERNAL "")
set(PATH_P7 ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
set(PATH_P7_API "${PROJECT_SOURCE_DIR}/Headers" CACHE INTERNAL "")
-else(expression)
endif(NOT DEFINED ROOT_P7_PATH)

if(MSVC)
--- a/Sources/CMakeLists.txt
+++ b/Sources/CMakeLists.txt
@@ -7,7 +7,7 @@ include_directories(${PATH_SHARED_PLATFORM})
include_directories(${PATH_P7_API})

if(WIN32)
- set(P7_PLATFORM_LIBS Ws2_32)
+ set(P7_PLATFORM_LIBS ws2_32)
elseif(UNIX)
set(P7_PLATFORM_LIBS rt pthread)
else()
@@ -16,29 +16,38 @@ endif()

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} P7_SOURCES)

+if(NOT P7_BUILD_SHARED)
add_library(${PROJECT_NAME} STATIC ${P7_SOURCES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${P7_PLATFORM_LIBS})
+endif()

if(P7_BUILD_SHARED)
add_library(${PROJECT_NAME}-shared SHARED ${P7_SOURCES})
target_link_libraries(${PROJECT_NAME}-shared ${P7_PLATFORM_LIBS})
endif()

+if(NOT P7_BUILD_SHARED)
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
+endif()

if(P7_BUILD_SHARED)
set_property(TARGET ${PROJECT_NAME}-shared PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()


+if(NOT P7_BUILD_SHARED)
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/")
+endif()
if(P7_BUILD_SHARED)
target_include_directories(${PROJECT_NAME}-shared PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/")
endif()

+if(NOT P7_BUILD_SHARED)
target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/")
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Shared/")
+endif()

+if(NOT P7_BUILD_SHARED)
if(WIN32)
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Shared/Platforms/Windows_x86/")
elseif(UNIX)
@@ -51,14 +60,15 @@ install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
)

-if(P7_BUILD_SHARED)
+else()
install(TARGETS ${PROJECT_NAME}-shared
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
endif()
+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../Headers/ DESTINATION include FILES_MATCHING PATTERN "*.h")

-if(COMMAND set_ide_folder)
+if(0)
set_ide_folder(${PROJECT_NAME})
if(P7_BUILD_SHARED)
set_ide_folder(${PROJECT_NAME}-shared)
14 changes: 3 additions & 11 deletions recipes/baical-p7/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(p7 REQUIRED CONFIG)
find_package(baical-p7 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)

if(P7_SHARED)
target_link_libraries(${PROJECT_NAME} p7::p7-shared)
else()
target_link_libraries(${PROJECT_NAME} p7::p7)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE baical-p7::baical-p7)
22 changes: 15 additions & 7 deletions recipes/baical-p7/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.definitions["P7_SHARED"] = self.options["baical-p7"].shared
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/baical-p7/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/baical-p7/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit fc344f2

Please sign in to comment.