Skip to content

Commit

Permalink
[libftdi1] Fix, cleanup, C++ binding, test port (microsoft#40862)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt authored Sep 13, 2024
1 parent 9f11f2d commit 4c2b54e
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 79 deletions.
19 changes: 19 additions & 0 deletions ports/libftdi1/cmake-version.diff
Original file line number Diff line number Diff line change
@@ -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)

12 changes: 12 additions & 0 deletions ports/libftdi1/disable-config-script.diff
Original file line number Diff line number Diff line change
@@ -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 )
13 changes: 0 additions & 13 deletions ports/libftdi1/libconfuse-fix.patch

This file was deleted.

12 changes: 12 additions & 0 deletions ports/libftdi1/libdir.diff
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 39 additions & 0 deletions ports/libftdi1/libftdipp1.diff
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions ports/libftdi1/libusb-fix.patch

This file was deleted.

16 changes: 16 additions & 0 deletions ports/libftdi1/libusb.diff
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions ports/libftdi1/linkage.diff
Original file line number Diff line number Diff line change
@@ -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})
66 changes: 48 additions & 18 deletions ports/libftdi1/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,74 @@ vcpkg_download_distfile(ARCHIVE

vcpkg_extract_source_archive(
SOURCE_PATH
ARCHIVE ${ARCHIVE}
ARCHIVE "${ARCHIVE}"
SOURCE_BASE 1.5
PATCHES
libusb-fix.patch
libconfuse-fix.patch
win32.patch
cmake-version.diff
disable-config-script.diff
linkage.diff
libdir.diff
libftdipp1.diff
libusb.diff
)

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(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${options}
-DBUILD_TESTS=OFF
-DCMAKE_CXX_STANDARD=11
-DDOCUMENTATION=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
-DLIB_SUFFIX=
"-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}"
-DPYTHON_BINDINGS=OFF
-DSTATICLIBS=${STATICLIBS}
)

vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_fixup_pkgconfig()

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")
endif()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/libftdi1)

vcpkg_fixup_pkgconfig()
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()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
if(NOT "cpp" IN_LIST FEATURES)
file(REMOVE "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libftdipp1.pc" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libftdipp1.pc")
endif()

vcpkg_copy_pdbs()
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()

file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
vcpkg_install_copyright(FILE_LIST ${file_list})
21 changes: 17 additions & 4 deletions ports/libftdi1/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"name": "libftdi1",
"version": "1.5",
"port-version": 4,
"port-version": 5,
"description": "FTDI USB driver with bitbang mode",
"homepage": "https://www.intra2net.com/en/developer/libftdi/",
"license": "LGPL-2.1-only AND MIT",
"dependencies": [
"libconfuse",
"libusb",
{
"name": "libusb",
"default-features": false
},
{
"name": "vcpkg-cmake",
"host": true
Expand All @@ -14,5 +18,14 @@
"name": "vcpkg-cmake-config",
"host": true
}
]
],
"features": {
"cpp": {
"description": "C++ bindings",
"license": "GPL-2.0-only WITH eCos-exception-2.0",
"dependencies": [
"boost-smart-ptr"
]
}
}
}
28 changes: 0 additions & 28 deletions ports/libftdi1/win32.patch

This file was deleted.

6 changes: 6 additions & 0 deletions ports/libusb/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ endif()

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}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING")
2 changes: 1 addition & 1 deletion ports/libusb/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libusb",
"version": "1.0.27",
"port-version": 1,
"port-version": 2,
"description": "a cross-platform library to access USB devices",
"homepage": "https://github.com/libusb/libusb",
"license": "LGPL-2.1-or-later",
Expand Down
10 changes: 10 additions & 0 deletions scripts/test_ports/vcpkg-ci-libftdi1/portfile.cmake
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 13 additions & 0 deletions scripts/test_ports/vcpkg-ci-libftdi1/project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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})
7 changes: 7 additions & 0 deletions scripts/test_ports/vcpkg-ci-libftdi1/project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "ftdi.hpp"

int main()
{
auto *context = new Ftdi::Context();
return 0;
}
Loading

0 comments on commit 4c2b54e

Please sign in to comment.