[libftdi1] Fix, cleanup, C++ binding, test port (#40862)

This commit is contained in:
Kai Pastor 2024-09-13 04:28:25 +02:00 committed by GitHub
parent 9f11f2df35
commit 4c2b54e052
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 286 additions and 81 deletions

View File

@ -0,0 +1,19 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5aecafc..4158267 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,5 @@
# Project
+cmake_minimum_required(VERSION 3.5)
project(libftdi1 C)
set(MAJOR_VERSION 1)
set(MINOR_VERSION 5)
@@ -11,8 +12,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif("${CMAKE_BUILD_TYPE}" STREQUAL "")
-set(CMAKE_COLOR_MAKEFILE ON)
-cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
add_definitions(-Wall)

View File

@ -0,0 +1,12 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4158267..61828d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -170,6 +170,7 @@ install(FILES ${CMAKE_BINARY_DIR}/libftdi1.pc ${CMAKE_BINARY_DIR}/libftdipp1.pc
DESTINATION lib${LIB_SUFFIX}/pkgconfig)
if (UNIX OR MINGW)
+elseif (0)
configure_file ( libftdi1-config.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config @ONLY )
install ( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config
DESTINATION bin )

View File

@ -1,13 +0,0 @@
diff --git a/cmake/FindConfuse.cmake b/cmake/FindConfuse.cmake
index f6af7d5..e24d72f 100755
--- a/cmake/FindConfuse.cmake
+++ b/cmake/FindConfuse.cmake
@@ -46,7 +46,7 @@ find_path ( CONFUSE_INCLUDE_DIR
set ( CONFUSE_INCLUDE_DIRS ${CONFUSE_INCLUDE_DIR} )
find_library ( CONFUSE_LIBRARY
- NAMES confuse
+ NAMES libconfuse
)
set ( CONFUSE_LIBRARIES ${CONFUSE_LIBRARY} )

View File

@ -0,0 +1,12 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa5b3bf..5963df0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -166,6 +166,7 @@ endif(${UNIX})
if(${WIN32})
set(libdir ${CMAKE_INSTALL_PREFIX}/bin)
endif(${WIN32})
+set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
configure_file(${CMAKE_SOURCE_DIR}/libftdi1.pc.in ${CMAKE_BINARY_DIR}/libftdi1.pc @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/libftdipp1.pc.in ${CMAKE_BINARY_DIR}/libftdipp1.pc @ONLY)

View File

@ -0,0 +1,39 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4158267..64ad5b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -135,7 +135,7 @@ endif ()
add_subdirectory(src)
if ( FTDIPP )
- project(libftdipp1 C CXX)
+ enable_language(CXX)
add_subdirectory(ftdipp)
endif ()
if ( PYTHON_BINDINGS )
@@ -192,6 +192,7 @@ list ( APPEND LIBFTDI_STATIC_LIBRARIES ${LIBUSB_LIBRARIES} )
if ( FTDIPP )
set ( LIBFTDIPP_LIBRARY ftdipp1 )
set ( LIBFTDIPP_LIBRARIES ${LIBFTDIPP_LIBRARY} )
+ list ( APPEND LIBFTDI_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} )
list ( APPEND LIBFTDIPP_LIBRARIES ${LIBUSB_LIBRARIES} )
endif ()
set ( LIBFTDI_LIBRARY_DIRS ${libdir} )
@@ -203,6 +204,7 @@ set ( LIBFTDI_ROOT_DIR ${prefix} )
set ( LIBFTDI_VERSION_STRING ${VERSION_STRING} )
set ( LIBFTDI_VERSION_MAJOR ${MAJOR_VERSION} )
set ( LIBFTDI_VERSION_MINOR ${MINOR_VERSION} )
+set ( LIBFTDIPP_LIBRARIES ${LIBFTDIPP_LIBRARY} ${LIBFTDI_LIBRARIES})
set ( LIBFTDI_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIBFTDI_CMAKE_CONFIG_DIR}/UseLibFTDI1.cmake )
diff --git a/libftdipp1.pc.in b/libftdipp1.pc.in
index 8158f38..b4fff0a 100644
--- a/libftdipp1.pc.in
+++ b/libftdipp1.pc.in
@@ -8,4 +8,4 @@ Description: C++ wrapper for libftdi1
Requires: libftdi1
Version: @VERSION@
Libs: -L${libdir} -lftdipp1
-Cflags: -I${includedir}
+Cflags: -I${includedir} -I${prefix}/include

View File

@ -1,13 +0,0 @@
diff --git a/cmake/FindUSB1.cmake b/cmake/FindUSB1.cmake
index b90e297..6cc97a0 100755
--- a/cmake/FindUSB1.cmake
+++ b/cmake/FindUSB1.cmake
@@ -26,7 +26,7 @@ else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
PATH_SUFFIXES libusb-1.0
PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS})
- FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
+ FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0 libusb-1.0
PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS})
include(FindPackageHandleStandardArgs)

View File

@ -0,0 +1,16 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5c812c..7fb66f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,10 @@ if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
endif(${CMAKE_BUILD_TYPE} STREQUAL Debug)
# find libusb
-find_package ( USB1 REQUIRED )
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
+set(LIBUSB_INCLUDE_DIR "${LIBUSB_INCLUDE_DIRS}")
+set(LIBUSB_LIBRARIES "${LIBUSB_LINK_LIBRARIES}")
include_directories ( ${LIBUSB_INCLUDE_DIR} )
# Find Boost

View File

@ -0,0 +1,49 @@
diff --git a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt
index fac5bcc..8a20a04 100644
--- a/ftdipp/CMakeLists.txt
+++ b/ftdipp/CMakeLists.txt
@@ -11,6 +11,11 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}
include_directories(${Boost_INCLUDE_DIRS})
+if(WIN32)
+ set(BUILD_SHARED_LIBS OFF)
+ set(STATICLIBS ON)
+endif()
+if(BUILD_SHARED_LIBS)
# Shared library
add_library(ftdipp1 SHARED ${cpp_sources})
@@ -28,6 +33,7 @@ install ( TARGETS ftdipp1
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
)
+endif()
# Static library
if ( STATICLIBS )
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 17b3617..087fba8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,8 +19,12 @@ configure_file(ftdi_version_i.h.in "${CMAKE_CURRENT_BINARY_DIR}/ftdi_version_i.h
# Targets
set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" )
+if(WIN32)
+ set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/exports.def CACHE INTERNAL "List of c sources" )
+endif()
set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" )
+if(BUILD_SHARED_LIBS)
add_library(ftdi1 SHARED ${c_sources})
math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases
@@ -37,6 +41,7 @@ install ( TARGETS ftdi1
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
)
+endif()
if ( STATICLIBS )
add_library(ftdi1-static STATIC ${c_sources})

View File

@ -6,44 +6,74 @@ vcpkg_download_distfile(ARCHIVE
vcpkg_extract_source_archive( vcpkg_extract_source_archive(
SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE} ARCHIVE "${ARCHIVE}"
SOURCE_BASE 1.5 SOURCE_BASE 1.5
PATCHES PATCHES
libusb-fix.patch cmake-version.diff
libconfuse-fix.patch disable-config-script.diff
win32.patch linkage.diff
libdir.diff
libftdipp1.diff
libusb.diff
) )
file(COPY "${CMAKE_CURRENT_LIST_DIR}/exports.def" DESTINATION "${SOURCE_PATH}/src") file(COPY "${CMAKE_CURRENT_LIST_DIR}/exports.def" DESTINATION "${SOURCE_PATH}/src")
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" STATICLIBS)
vcpkg_check_features(OUT_FEATURE_OPTIONS options
FEATURES
cpp FTDIPP
)
vcpkg_find_acquire_program(PKGCONFIG)
vcpkg_cmake_configure( vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}" SOURCE_PATH "${SOURCE_PATH}"
OPTIONS OPTIONS
${options}
-DBUILD_TESTS=OFF -DBUILD_TESTS=OFF
-DCMAKE_CXX_STANDARD=11
-DDOCUMENTATION=OFF -DDOCUMENTATION=OFF
-DEXAMPLES=OFF -DEXAMPLES=OFF
-DPYTHON_BINDINGS=OFF
-DLINK_PYTHON_LIBRARY=OFF
-DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=ON
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=ON
-DCMAKE_DISABLE_FIND_PACKAGE_Libintl=ON
-DCMAKE_DISABLE_FIND_PACKAGE_PythonLibs=ON
-DCMAKE_DISABLE_FIND_PACKAGE_PythonInterp=ON
-DFTDI_EEPROM=OFF -DFTDI_EEPROM=OFF
-DLIB_SUFFIX=
"-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}"
-DPYTHON_BINDINGS=OFF
-DSTATICLIBS=${STATICLIBS}
) )
vcpkg_cmake_install() vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/libftdi1)
vcpkg_fixup_pkgconfig() vcpkg_fixup_pkgconfig()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share") if(NOT VCPKG_BUILD_TYPE)
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/cmake/libftdi1/LibFTDI1Config.cmake" "${CURRENT_PACKAGES_DIR}/debug/lib/cmake/libftdi1/LibFTDI1Config-debug.cmake")
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") endif()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/libftdi1)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/LibFTDI1Config.cmake" "/lib/cmake/${PORT}/" "/share/${PORT}/")
if(NOT VCPKG_BUILD_TYPE)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/LibFTDI1Config-debug.cmake" "/debug/lib/cmake/${PORT}/" "/share/${PORT}/")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/LibFTDI1Config-debug.cmake" "{_IMPORT_PREFIX}" "{VCPKG_IMPORT_PREFIX}")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/LibFTDI1Config-debug.cmake" "{VCPKG_IMPORT_PREFIX}/debug/include/" "{VCPKG_IMPORT_PREFIX}/include/")
file(READ "${CURRENT_PACKAGES_DIR}/share/${PORT}/LibFTDI1Config.cmake" release_config)
file(WRITE "${CURRENT_PACKAGES_DIR}/share/${PORT}/LibFTDI1Config.cmake" "
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES \"^[Dd][Ee][Bb][Uu][Gg]\$\")
include(\"\${CMAKE_CURRENT_LIST_DIR}/LibFTDI1Config-debug.cmake\")
return()
endif()
${release_config}"
)
endif() endif()
vcpkg_copy_pdbs() file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")
if(NOT "cpp" IN_LIST FEATURES)
file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libftdipp1.pc" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libftdipp1.pc")
endif()
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) set(file_list "${SOURCE_PATH}/COPYING.LIB")
if("cpp" IN_LIST FEATURES)
set(file_list "${SOURCE_PATH}/LICENSE" "${SOURCE_PATH}/COPYING.LIB" "${SOURCE_PATH}/COPYING.GPL")
endif()
vcpkg_install_copyright(FILE_LIST ${file_list})

View File

@ -1,11 +1,15 @@
{ {
"name": "libftdi1", "name": "libftdi1",
"version": "1.5", "version": "1.5",
"port-version": 4, "port-version": 5,
"description": "FTDI USB driver with bitbang mode", "description": "FTDI USB driver with bitbang mode",
"homepage": "https://www.intra2net.com/en/developer/libftdi/",
"license": "LGPL-2.1-only AND MIT",
"dependencies": [ "dependencies": [
"libconfuse", {
"libusb", "name": "libusb",
"default-features": false
},
{ {
"name": "vcpkg-cmake", "name": "vcpkg-cmake",
"host": true "host": true
@ -14,5 +18,14 @@
"name": "vcpkg-cmake-config", "name": "vcpkg-cmake-config",
"host": true "host": true
} }
] ],
"features": {
"cpp": {
"description": "C++ bindings",
"license": "GPL-2.0-only WITH eCos-exception-2.0",
"dependencies": [
"boost-smart-ptr"
]
}
}
} }

View File

@ -1,28 +0,0 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 17b3617..f9a8e59 100755
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -18,9 +18,14 @@ message(STATUS "Detected git snapshot version: ${SNAPSHOT_VERSION}")
configure_file(ftdi_version_i.h.in "${CMAKE_CURRENT_BINARY_DIR}/ftdi_version_i.h" @ONLY)
# Targets
+if(WIN32)
+set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/exports.def CACHE INTERNAL "List of c sources" )
+else()
set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" )
+endif()
set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" )
+if(BUILD_SHARED_LIBS)
add_library(ftdi1 SHARED ${c_sources})
math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases
@@ -38,7 +43,7 @@ install ( TARGETS ftdi1
ARCHIVE DESTINATION lib${LIB_SUFFIX}
)
-if ( STATICLIBS )
+else()
add_library(ftdi1-static STATIC ${c_sources})
target_link_libraries(ftdi1-static ${LIBUSB_LIBRARIES})
set_target_properties(ftdi1-static PROPERTIES OUTPUT_NAME "ftdi1")

View File

@ -64,5 +64,11 @@ endif()
vcpkg_fixup_pkgconfig() vcpkg_fixup_pkgconfig()
# -Wl,-framework,... is poorly handled in CMake
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libusb-1.0.pc" " -Wl,-framework," " -framework " IGNORE_UNCHANGED)
if(NOT VCPKG_BUILD_TYPE)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libusb-1.0.pc" " -Wl,-framework," " -framework " IGNORE_UNCHANGED)
endif()
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING")

View File

@ -1,7 +1,7 @@
{ {
"name": "libusb", "name": "libusb",
"version": "1.0.27", "version": "1.0.27",
"port-version": 1, "port-version": 2,
"description": "a cross-platform library to access USB devices", "description": "a cross-platform library to access USB devices",
"homepage": "https://github.com/libusb/libusb", "homepage": "https://github.com/libusb/libusb",
"license": "LGPL-2.1-or-later", "license": "LGPL-2.1-or-later",

View File

@ -0,0 +1,10 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
vcpkg_find_acquire_program(PKGCONFIG)
vcpkg_cmake_configure(
SOURCE_PATH "${CURRENT_PORT_DIR}/project"
OPTIONS
"-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}"
)
vcpkg_cmake_build()

View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.29)
project(libftdi1-test CXX)
set(CMAKE_CXX_STANDARD 11)
add_executable(main main.cpp)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libftdipp1 IMPORTED_TARGET REQUIRED libftdipp1)
target_link_libraries(main PRIVATE PkgConfig::libftdipp1)
# subdir to scope side effects
add_subdirectory(cmake-usage)

View File

@ -0,0 +1,6 @@
# not modern
find_package(LIBFTDI1 NAMES LibFTDI1 REQUIRED)
include("${LIBFTDI_USE_FILE}")
add_executable(cmake-usage ../main.cpp)
target_link_libraries(cmake-usage PRIVATE ${LIBFTDIPP_LIBRARIES})

View File

@ -0,0 +1,7 @@
#include "ftdi.hpp"
int main()
{
auto *context = new Ftdi::Context();
return 0;
}

View File

@ -0,0 +1,17 @@
{
"name": "vcpkg-ci-libftdi1",
"version-string": "ci",
"description": "Validates libftdi1",
"dependencies": [
{
"name": "libftdi1",
"features": [
"cpp"
]
},
{
"name": "vcpkg-cmake",
"host": true
}
]
}

View File

@ -4514,7 +4514,7 @@
}, },
"libftdi1": { "libftdi1": {
"baseline": "1.5", "baseline": "1.5",
"port-version": 4 "port-version": 5
}, },
"libfuse": { "libfuse": {
"baseline": "3.16.2", "baseline": "3.16.2",
@ -5218,7 +5218,7 @@
}, },
"libusb": { "libusb": {
"baseline": "1.0.27", "baseline": "1.0.27",
"port-version": 1 "port-version": 2
}, },
"libusb-win32": { "libusb-win32": {
"baseline": "1.2.6.0", "baseline": "1.2.6.0",

View File

@ -1,5 +1,10 @@
{ {
"versions": [ "versions": [
{
"git-tree": "6142799716042c18d993c9624ca8675d32cf97df",
"version": "1.5",
"port-version": 5
},
{ {
"git-tree": "ef6feb3ad01d1d2483c5a369fd4e6bf3587ff52d", "git-tree": "ef6feb3ad01d1d2483c5a369fd4e6bf3587ff52d",
"version": "1.5", "version": "1.5",

View File

@ -1,5 +1,10 @@
{ {
"versions": [ "versions": [
{
"git-tree": "0f2e2537b1adc23e54eb130e497433f0c377d7b4",
"version": "1.0.27",
"port-version": 2
},
{ {
"git-tree": "da092fa023f47e3307d55a85bafb31a9c801b715", "git-tree": "da092fa023f47e3307d55a85bafb31a9c801b715",
"version": "1.0.27", "version": "1.0.27",