-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#21892) [mocknetworkaccessmanager] add recipe for 0.12.0
* [mocknetworkaccessmanager] add recipe for 0.12.0 * Check the C++ standard version is at least C++11 * Change package_type from header-only to library * Add link to patch source * Add a check for the OS, only Macos is supported for now. * Disable shared builds * Reenable other platforms * Remove Linux support for now This reverts commit b5bec55. * Fix Linux build * Increase the minimum C++ standard to 17 * Apply suggestions from code review Co-authored-by: Uilian Ries <[email protected]> * Apply suggestions from code review Co-authored-by: Uilian Ries <[email protected]> * Update recipes/mocknetworkaccessmanager/all/conanfile.py Co-authored-by: Uilian Ries <[email protected]> * Apply suggestions from code review Co-authored-by: Uilian Ries <[email protected]> * Fix requires for qt6 * Remove whenGet() from test_package.cpp * Revert "Remove whenGet() from test_package.cpp" This reverts commit 4a1d57b. * Use QCoreApplication --------- Co-authored-by: Uilian Ries <[email protected]>
- Loading branch information
1 parent
7b0ac71
commit 9814982
Showing
8 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
sources: | ||
"0.12.0": | ||
url: "https://gitlab.com/julrich/MockNetworkAccessManager/-/archive/0.12.0/MockNetworkAccessManager-0.12.0.tar.gz" | ||
sha256: "ac9ffb5e6e5ccdc1b7c76da7a92b5d845ec12eb48a39b0423005da4f6431b09f" | ||
patches: | ||
"0.12.0": | ||
- patch_file: "patches/0.12.0-0001-add-install-step.patch" | ||
patch_description: "Add install step" | ||
patch_type: "conan" | ||
patch_source: "https://gitlab.com/julrich/MockNetworkAccessManager/-/merge_requests/75" | ||
- patch_file: "patches/0.12.0-0002-fix-target-without-location.patch" | ||
patch_description: "Fix target without location" | ||
patch_type: "conan" | ||
patch_source: "https://gitlab.com/julrich/MockNetworkAccessManager/-/merge_requests/75" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.52.0" | ||
|
||
|
||
class MockNetworkAccessManagerConan(ConanFile): | ||
name = "mocknetworkaccessmanager" | ||
description = "Mocking network communication for Qt applications" | ||
license = "MIT" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://gitlab.com/julrich/MockNetworkAccessManager" | ||
topics = ("qt", "mock", "network", "QNetworkAccessManager", "unit test", "test") | ||
package_type = "static-library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"fPIC": [True, False], | ||
"with_qt": [5, 6], | ||
} | ||
default_options = { | ||
"fPIC": True, | ||
"with_qt": 5, | ||
} | ||
|
||
def export_sources(self): | ||
export_conandata_patches(self) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def requirements(self): | ||
if self.options.with_qt == 5: | ||
self.requires("qt/5.15.12", transitive_headers=True) | ||
else: | ||
self.requires("qt/6.6.1", transitive_headers=True) | ||
|
||
def validate(self): | ||
if self.settings.compiler.get_safe("cppstd"): | ||
check_min_cppstd(self, "11") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["BUILD_TESTING"] = False | ||
tc.variables["FORCE_QT5"] = self.options.with_qt == 5 | ||
tc.generate() | ||
tc = CMakeDeps(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
apply_conandata_patches(self) | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["MockNetworkAccessManager"] |
15 changes: 15 additions & 0 deletions
15
recipes/mocknetworkaccessmanager/all/patches/0.12.0-0001-add-install-step.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 61ed3ed..6d0de20 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -107,3 +107,10 @@ add_library( MockNetworkAccessManager STATIC EXCLUDE_FROM_ALL "MockNetworkAccess | ||
target_include_directories( MockNetworkAccessManager PUBLIC "${PROJECT_SOURCE_DIR}" ) | ||
target_link_libraries( MockNetworkAccessManager Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ) | ||
|
||
+install(TARGETS MockNetworkAccessManager | ||
+ LIBRARY DESTINATION lib | ||
+ ARCHIVE DESTINATION lib) | ||
+ | ||
+install(FILES "${PROJECT_SOURCE_DIR}/MockNetworkAccessManager.hpp" | ||
+ DESTINATION include) | ||
+ |
20 changes: 20 additions & 0 deletions
20
recipes/mocknetworkaccessmanager/all/patches/0.12.0-0002-fix-target-without-location.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
commit e28d1f3868db8c7f5ff654a205d80d5d7ed203c4 | ||
Author: Martin Delille <[email protected]> | ||
Date: Fri Jan 19 18:06:56 2024 +0100 | ||
|
||
Fix target without LOCATION property | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 6d0de20..dbfbed3 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -26,8 +26,7 @@ if( NOT Qt5_FOUND OR NOT Qt6_FOUND ) | ||
find_package( Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network ) | ||
endif() | ||
|
||
-get_target_property( QTCORE_LOCATION Qt${QT_VERSION_MAJOR}::Core LOCATION ) | ||
-get_filename_component( QT_BIN_DIR ${QTCORE_LOCATION} DIRECTORY ) | ||
+get_filename_component(QT_BIN_DIR "$<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::Core>" ABSOLUTE) | ||
set( CMAKE_MSVCIDE_RUN_PATH ${QT_BIN_DIR} ) | ||
set_property( DIRECTORY "." APPEND PROPERTY COMPILE_DEFINITIONS "QT_DEPRECATED_WARNINGS" ) | ||
|
8 changes: 8 additions & 0 deletions
8
recipes/mocknetworkaccessmanager/all/test_package/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package LANGUAGES CXX) | ||
|
||
find_package(mocknetworkaccessmanager REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE mocknetworkaccessmanager::mocknetworkaccessmanager) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) |
26 changes: 26 additions & 0 deletions
26
recipes/mocknetworkaccessmanager/all/test_package/conanfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
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.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
15 changes: 15 additions & 0 deletions
15
recipes/mocknetworkaccessmanager/all/test_package/test_package.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <QCoreApplication> | ||
|
||
#include "MockNetworkAccessManager.hpp" | ||
|
||
int main(int argc, char *argv[]) { | ||
QCoreApplication app(argc, argv); | ||
MockNetworkAccess::Manager< QNetworkAccessManager > mnam; | ||
|
||
mnam.whenGet( QUrl( "http://example.com/hello" ) ) | ||
.has( MockNetworkAccess::Predicates::HeaderMatching( QNetworkRequest::UserAgentHeader, | ||
QRegularExpression( ".*MyNetworkClient/.*" ) ) ) | ||
.reply().withBody( QJsonDocument::fromJson( "{\"hello\":\"world\"}" ) ); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.12.0": | ||
folder: all |