Skip to content

Commit fd4c0c3

Browse files
committed
conan v2 support
1 parent 47e115a commit fd4c0c3

File tree

8 files changed

+174
-67
lines changed

8 files changed

+174
-67
lines changed

recipes/baical-p7/all/CMakeLists.txt

-7
This file was deleted.

recipes/baical-p7/all/conandata.yml

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ sources:
22
"5.6":
33
url: "http://baical.net/files/libP7Client_v5.6.zip"
44
sha256: "7503bdf739b9c2aea297b49fa0aa0162b7090830aee1cbd4cf7be5d3c75600de"
5+
patches:
6+
"5.6":
7+
- patch_file: "patches/0001-fix-cmake.patch"
8+
patch_description: "Fix CMakeLists"
9+
patch_type: "conan"

recipes/baical-p7/all/conanfile.py

+40-42
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from conan import ConanFile
2+
from conan.errors import ConanInvalidConfiguration
3+
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
4+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
15
import os
2-
from conans import ConanFile, CMake, tools
3-
from conans.errors import ConanInvalidConfiguration
46

5-
required_conan_version = ">=1.29.1"
7+
required_conan_version = ">=1.53.0"
8+
69

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

20-
_cmake = None
18+
settings = "os", "arch", "compiler", "build_type"
19+
options = {
20+
"shared": [True, False],
21+
"fPIC": [True, False],
22+
}
23+
default_options = {
24+
"shared": False,
25+
"fPIC": True,
26+
}
2127

22-
@property
23-
def _source_subfolder(self):
24-
return "source_subfolder"
28+
def export_sources(self):
29+
export_conandata_patches(self)
2530

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

3035
def configure(self):
3136
if self.options.shared:
32-
del self.options.fPIC
37+
self.options.rm_safe("fPIC")
38+
39+
def layout(self):
40+
cmake_layout(self, src_folder="src")
41+
42+
def validate(self):
3343
if self.settings.os not in ["Linux", "Windows"]:
3444
raise ConanInvalidConfiguration("P7 only supports Windows and Linux at this time")
3545

3646
def source(self):
37-
tools.get(**self.conan_data["sources"][self.version], destination= self._source_subfolder)
47+
get(self, **self.conan_data["sources"][self.version])
3848

39-
def _configure_cmake(self):
40-
if self._cmake:
41-
return self._cmake
42-
self._cmake = CMake(self)
43-
self._cmake.definitions["P7_TESTS_BUILD"] = False
44-
self._cmake.definitions["P7_BUILD_SHARED"] = self.options.shared
45-
self._cmake.definitions["P7_EXAMPLES_BUILD"] = False
46-
self._cmake.configure()
47-
return self._cmake
49+
def generate(self):
50+
tc = CMakeToolchain(self)
51+
tc.variables["P7_TESTS_BUILD"] = False
52+
tc.cache_variables["P7_BUILD_SHARED"] = self.options.shared
53+
tc.variables["P7_EXAMPLES_BUILD"] = False
54+
tc.generate()
4855

4956
def build(self):
50-
cmake = self._configure_cmake()
57+
apply_conandata_patches(self)
58+
cmake = CMake(self)
59+
cmake.configure()
5160
cmake.build()
5261

5362
def package(self):
54-
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
55-
self.copy(pattern="*", dst="include", src=os.path.join(self._source_subfolder, "Headers"))
56-
cmake = self._configure_cmake()
63+
copy(self, "License.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
64+
cmake = CMake(self)
5765
cmake.install()
58-
tools.remove_files_by_mask(os.path.join(self.package_folder, "include"), "*.cmake")
5966

6067
def package_info(self):
61-
self.cpp_info.names["cmake_find_package"] = "p7"
62-
self.cpp_info.names["cmake_find_package_multi"] = "p7"
63-
64-
if self.options.shared:
65-
self.cpp_info.components["p7"].name = "p7-shared"
66-
self.cpp_info.components["p7"].libs = ["p7-shared"]
67-
else:
68-
self.cpp_info.components["p7"].name = "p7"
69-
self.cpp_info.components["p7"].libs = ["p7"]
70-
71-
if self.settings.os == "Linux":
72-
self.cpp_info.components["p7"].system_libs .extend(["rt", "pthread"])
73-
if self.settings.os == "Windows":
74-
self.cpp_info.components["p7"].system_libs .append("Ws2_32")
68+
self.cpp_info.libs = ["p7-shared" if self.options.shared else "p7"]
69+
if self.settings.os in ["Linux", "FreeBSD"]:
70+
self.cpp_info.system_libs.extend(["rt", "pthread"])
71+
elif self.settings.os == "Windows":
72+
self.cpp_info.system_libs.append("ws2_32")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
--- a/CMakeLists.txt
2+
+++ b/CMakeLists.txt
3+
@@ -1,6 +1,6 @@
4+
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
5+
6+
-#project(p7lib)
7+
+project(p7lib)
8+
9+
#>>Build options **********************************************************************
10+
option(P7_TESTS_BUILD "Build test" OFF)
11+
@@ -25,7 +25,6 @@ if(NOT DEFINED ROOT_P7_PATH)
12+
set(ROOT_P7_PATH ${PROJECT_SOURCE_DIR} CACHE INTERNAL "")
13+
set(PATH_P7 ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
14+
set(PATH_P7_API "${PROJECT_SOURCE_DIR}/Headers" CACHE INTERNAL "")
15+
-else(expression)
16+
endif(NOT DEFINED ROOT_P7_PATH)
17+
18+
if(MSVC)
19+
--- a/Sources/CMakeLists.txt
20+
+++ b/Sources/CMakeLists.txt
21+
@@ -7,7 +7,7 @@ include_directories(${PATH_SHARED_PLATFORM})
22+
include_directories(${PATH_P7_API})
23+
24+
if(WIN32)
25+
- set(P7_PLATFORM_LIBS Ws2_32)
26+
+ set(P7_PLATFORM_LIBS ws2_32)
27+
elseif(UNIX)
28+
set(P7_PLATFORM_LIBS rt pthread)
29+
else()
30+
@@ -16,29 +16,38 @@ endif()
31+
32+
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} P7_SOURCES)
33+
34+
+if(NOT P7_BUILD_SHARED)
35+
add_library(${PROJECT_NAME} STATIC ${P7_SOURCES})
36+
target_link_libraries(${PROJECT_NAME} PUBLIC ${P7_PLATFORM_LIBS})
37+
+endif()
38+
39+
if(P7_BUILD_SHARED)
40+
add_library(${PROJECT_NAME}-shared SHARED ${P7_SOURCES})
41+
target_link_libraries(${PROJECT_NAME}-shared ${P7_PLATFORM_LIBS})
42+
endif()
43+
44+
+if(NOT P7_BUILD_SHARED)
45+
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
46+
+endif()
47+
48+
if(P7_BUILD_SHARED)
49+
set_property(TARGET ${PROJECT_NAME}-shared PROPERTY POSITION_INDEPENDENT_CODE ON)
50+
endif()
51+
52+
53+
+if(NOT P7_BUILD_SHARED)
54+
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/")
55+
+endif()
56+
if(P7_BUILD_SHARED)
57+
target_include_directories(${PROJECT_NAME}-shared PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/")
58+
endif()
59+
60+
+if(NOT P7_BUILD_SHARED)
61+
target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/")
62+
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Shared/")
63+
+endif()
64+
65+
+if(NOT P7_BUILD_SHARED)
66+
if(WIN32)
67+
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Shared/Platforms/Windows_x86/")
68+
elseif(UNIX)
69+
@@ -51,14 +60,15 @@ install(TARGETS ${PROJECT_NAME}
70+
RUNTIME DESTINATION bin
71+
)
72+
73+
-if(P7_BUILD_SHARED)
74+
+else()
75+
install(TARGETS ${PROJECT_NAME}-shared
76+
ARCHIVE DESTINATION lib
77+
LIBRARY DESTINATION lib
78+
RUNTIME DESTINATION bin)
79+
endif()
80+
+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../Headers/ DESTINATION include FILES_MATCHING PATTERN "*.h")
81+
82+
-if(COMMAND set_ide_folder)
83+
+if(0)
84+
set_ide_folder(${PROJECT_NAME})
85+
if(P7_BUILD_SHARED)
86+
set_ide_folder(${PROJECT_NAME}-shared)
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(test_package CXX)
2+
project(test_package LANGUAGES CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
6-
7-
find_package(p7 REQUIRED CONFIG)
4+
find_package(baical-p7 REQUIRED CONFIG)
85

96
add_executable(${PROJECT_NAME} test_package.cpp)
10-
11-
if(P7_SHARED)
12-
target_link_libraries(${PROJECT_NAME} p7::p7-shared)
13-
else()
14-
target_link_libraries(${PROJECT_NAME} p7::p7)
15-
endif()
7+
target_link_libraries(${PROJECT_NAME} PRIVATE baical-p7::baical-p7)
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import CMake, cmake_layout
24
import os
35

46

57
class TestPackageConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake", "cmake_find_package_multi"
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
817

918
def build(self):
1019
cmake = CMake(self)
11-
cmake.definitions["P7_SHARED"] = self.options["baical-p7"].shared
1220
cmake.configure()
1321
cmake.build()
1422

1523
def test(self):
16-
if not tools.cross_building(self.settings):
17-
bin_path = os.path.join("bin", "test_package")
18-
self.run(bin_path, run_environment=True)
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)