Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[faker-cxx] add new port #38583

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ports/faker-cxx/CMakeLists.txt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c0c1473..72e6244 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@ if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /permissive- /bigobj")
else ()
set(CMAKE_CXX_FLAGS
- "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wconversion -Wformat -Werror"
+ "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wconversion -Wformat"
)
endif ()

@@ -130,9 +130,8 @@ install(EXPORT ${LIBRARY_NAME}-targets
if (APPLE OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_LESS 12))

- add_subdirectory(externals/fmt)
- set(FMT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/fmt/include")
- target_link_libraries(${LIBRARY_NAME} PRIVATE fmt)
+ find_package(fmt CONFIG REQUIRED)
+ target_link_libraries(${LIBRARY_NAME} PRIVATE fmt::fmt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require find_dependency in exported config. Is it present?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I am that proficient in CMake - for Apple clang builds, fmt will be included via vcpkg, too. But can you give me an example from another project on what I might be missing here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for Apple clang builds, fmt will be included via vcpkg, too.

I don't understand what this means.

can you give me an example from another project on what I might be missing here?

It is hard to find a minimal example but maybe soci comes close enough.
Making soci use unofficial::sqlite3::sqlite3 here:

--- a/cmake/dependencies/SQLite3.cmake
+++ b/cmake/dependencies/SQLite3.cmake
@@ -1,5 +1,6 @@
set(SQLITE3_FIND_QUIETLY TRUE)
-find_package(SQLite3)
+find_package(SQLITE3 NAMES unofficial-sqlite3 CONFIG REQUIRED)
+set(SQLITE3_LIBRARIES unofficial::sqlite3::sqlite3)
boost_external_report(SQLite3 INCLUDE_DIR LIBRARIES)

makes $<LINK_ONLY:unofficial::sqlite3::sqlite3> appearing in the INTERFACE_LINK_LIBRARIES of the exported CMake config, so downstream usage will need to know what this target means. And that's why the same patch carries a change to the config file template:

--- a/cmake/resources/SOCIConfig.cmake.in
+++ b/cmake/resources/SOCIConfig.cmake.in
@@ -1,3 +1,11 @@
@PACKAGE_INIT@
+include(CMakeFindDependencyMacro)
+if("@WITH_MYSQL@")
+ find_dependency(unofficial-libmysql)
+endif()
+if("@WITH_SQLITE3@")
+ find_dependency(unofficial-sqlite3)
+endif()
+
include(${CMAKE_CURRENT_LIST_DIR}/SOCITargets.cmake)

endif ()

if (BUILD_FAKER_TESTS)
22 changes: 22 additions & 0 deletions ports/faker-cxx/FormatHelper.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/src/common/FormatHelper.h b/src/common/FormatHelper.h
index 6356ee9..8541469 100644
--- a/src/common/FormatHelper.h
+++ b/src/common/FormatHelper.h
@@ -5,7 +5,7 @@
#include <string>
#include <vector>

-#if defined(__APPLE__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__))
+#if defined(__APPLE__) || defined(__ANDROID__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__))
#include <fmt/format.h>
#else
#include <format>
@@ -16,7 +16,7 @@ namespace faker
class FormatHelper
{
public:
-#if defined(__APPLE__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__))
+#if defined(__APPLE__) || defined(__ANDROID__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__))
template <typename... Args>
static std::string format(fmt::format_string<Args...> fmt, Args&&... args)
{
13 changes: 13 additions & 0 deletions ports/faker-cxx/Helper.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/include/faker-cxx/Helper.h b/include/faker-cxx/Helper.h
index 51d5eab..c17e41c 100644
--- a/include/faker-cxx/Helper.h
+++ b/include/faker-cxx/Helper.h
@@ -89,7 +89,7 @@ public:
{
throw std::invalid_argument{"Data is empty."};
}
- T item;
+ T item{};
std::sample(data.begin(), data.end(), &item, 1, pseudoRandomGenerator);
return item;
}
29 changes: 29 additions & 0 deletions ports/faker-cxx/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
if(VCPKG_TARGET_IS_WINDOWS)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO cieslarmichal/faker-cxx
REF "v${VERSION}"
SHA512 0ad3550d45df2adda70ad64fc1afffc2d39f6644e46029b6b3f0fd42eed071b55daeee9da7456b8b75e1da566bd0d1605518722b2831dba31bf9787506ecfa9d
HEAD_REF master
PATCHES
CMakeLists.txt.patch
FormatHelper.h.patch
Helper.h.patch
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DBUILD_FAKER_TESTS=OFF
)

vcpkg_cmake_install()

vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/faker-cxx)

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
4 changes: 4 additions & 0 deletions ports/faker-cxx/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
faker-cxx provides CMake targets:

find_package(faker-cxx CONFIG REQUIRED)
target_link_libraries(main PRIVATE faker-cxx::faker-cxx)
19 changes: 19 additions & 0 deletions ports/faker-cxx/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "faker-cxx",
"version-string": "v1.0.0",
"description": "C++ Faker library for generating fake (but realistic) data.",
"homepage": "https://github.com/cieslarmichal/faker-cxx",
"license": "MIT",
"supports": "!android",
"dependencies": [
"fmt",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
4 changes: 4 additions & 0 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2592,6 +2592,10 @@
"baseline": "2.4.0",
"port-version": 2
},
"faker-cxx": {
"baseline": "v1.0.0",
"port-version": 0
},
"fameta-counter": {
"baseline": "2021-02-13",
"port-version": 0
Expand Down
9 changes: 9 additions & 0 deletions versions/f-/faker-cxx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "572cbf1a47f1b4bf14d0ef9b2ae2f06b241e7ffe",
"version-string": "v1.0.0",
"port-version": 0
}
]
}