From 3d7293651483130af9e8c5fe685d28b226baa99b Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Wed, 4 Jun 2025 08:47:07 +0200 Subject: [PATCH 01/16] Ignore clangd specific files --- .gitignore | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index 34f3852..3d04163 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,7 @@ opt # ctags tags + +# clangd specific files +.cache +compile_commands.json -- 1.7.1 From 12a8de0daba0816227c7010fc1b84d0abf70a500 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Mon, 27 May 2024 15:37:05 +0200 Subject: [PATCH 02/16] .editorconfig: fix insert_final_newline option This option must be set to true to comply with the current style. --- .editorconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/.editorconfig b/.editorconfig index 40392cd..afa4632 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [*] end_of_line = lf trim_trailing_whitespace = true -insert_final_newline = false +insert_final_newline = true [{CMakeLists.txt,*.cmake}] indent_style = space -- 1.7.1 From cfaec73e0a5ad9d05d62f1f5c393ab1c59ba771b Mon Sep 17 00:00:00 2001 From: Aurelien Jarno Date: Tue, 13 May 2025 23:40:40 +0200 Subject: [PATCH 03/16] C++ wrapper: get rid of the Boost dependency The C++ wrapper relies on boost::shared_ptr, likely due to the lack of a standard smart pointer at the time of the C++ wrapper implementation. However, std::shared_ptr has been available by default in GCC since version 6.1, and even with GCC 4.7 when explicitely using the -std=c++11 option. This commit replaces all usages of boost::shared_ptr with std::shared_ptr, eliminating the dependency on the Boost library. Since the smart pointer is only used in private member variables and both types have the same size, this change does not affect the ABI. Signed-off-by: Aurelien Jarno --- CMakeLists.txt | 2 +- README.build | 2 +- examples/CMakeLists.txt | 1 - ftdipp/CMakeLists.txt | 4 +--- ftdipp/ftdi.hpp | 8 ++++---- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5494357..385952e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ find_package ( LibUSB REQUIRED ) include_directories ( ${LIBUSB_INCLUDE_DIR} ) # Find Boost -if (FTDIPP OR BUILD_TESTS) +if (BUILD_TESTS) find_package( Boost REQUIRED ) endif() diff --git a/README.build b/README.build index e130ca0..54c253f 100644 --- a/README.build +++ b/README.build @@ -14,7 +14,7 @@ earlier, it is recommended you build libusbx-1.0.14 or later). sudo apt-get install libconfuse-dev (for ftdi-eeprom) (yum install libconfuse-devel) sudo apt-get install swig python-dev (for python bindings) (yum install swig python-devel) -sudo apt-get install libboost-all-dev (for C++ binding and unit test) (yum install boost-devel) +sudo apt-get install libboost-all-dev (for unit test) (yum install boost-devel) 3) Clone the git repository mkdir libftdi diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9ec7bff..bda84e0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -38,7 +38,6 @@ endif(NOT MINGW) # libftdi++ examples if( FTDIPP ) include_directories(BEFORE ${PROJECT_SOURCE_DIR}/ftdipp - ${Boost_INCLUDE_DIRS} ) # Target diff --git a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt index 360a831..71e6055 100644 --- a/ftdipp/CMakeLists.txt +++ b/ftdipp/CMakeLists.txt @@ -8,8 +8,6 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src ) -include_directories(${Boost_INCLUDE_DIRS}) - # Shared library add_library(ftdipp1 SHARED ${cpp_sources}) @@ -20,7 +18,7 @@ set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSIO set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) # Dependencies -target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES}) +target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES}) install ( TARGETS ftdipp1 RUNTIME DESTINATION bin diff --git a/ftdipp/ftdi.hpp b/ftdipp/ftdi.hpp index f569cce..2458327 100644 --- a/ftdipp/ftdi.hpp +++ b/ftdipp/ftdi.hpp @@ -31,7 +31,7 @@ on this file might be covered by the GNU General Public License. #include #include -#include +#include #include namespace Ftdi @@ -145,7 +145,7 @@ protected: private: class Private; - boost::shared_ptr d; + std::shared_ptr d; }; /*! \brief Device EEPROM. @@ -168,7 +168,7 @@ public: private: class Private; - boost::shared_ptr d; + std::shared_ptr d; }; /*! \brief Device list. @@ -214,7 +214,7 @@ public: private: class Private; - boost::shared_ptr d; + std::shared_ptr d; }; } -- 1.7.1 From 7676fb59ecd9fac9e5ea39439905c923ee7ee8c9 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Thu, 10 Apr 2025 12:45:10 +0200 Subject: [PATCH 04/16] python/CMakeLists.txt: rework policy CMP0078 Switch to a new behaviour and use the pyftdi1 target directly. --- python/CMakeLists.txt | 24 +++++++----------------- 1 files changed, 7 insertions(+), 17 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 9358419..0708851 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,9 +1,3 @@ -# swig_add_library behavior changed in cmake 3.13 to no longer set -# SWIG_MODULE__REAL_NAME, so restore the old behavior. -if ( POLICY CMP0078 ) - cmake_policy( SET CMP0078 OLD ) -endif () - # workaround for cmake bug #0013449 if ( NOT DEFINED CMAKE_FIND_ROOT_PATH OR NOT CMAKE_VERSION VERSION_LESS 3.0.0 ) find_package ( SWIG REQUIRED ) @@ -27,20 +21,16 @@ if ( DOCUMENTATION ) # manually add dependency for new cmake / swig versions set_property(SOURCE ftdi1.i PROPERTY DEPENDS doc_i) endif() -if(NOT CMAKE_VERSION VERSION_LESS 3.8.0) - swig_add_library ( ftdi1 LANGUAGE python SOURCES ftdi1.i ) -else () - swig_add_module ( ftdi1 python ftdi1.i ) -endif() -swig_link_libraries ( ftdi1 ftdi1 ) +swig_add_library ( pyftdi1 LANGUAGE python SOURCES ftdi1.i ) +swig_link_libraries ( pyftdi1 ftdi1 ) if ( LINK_PYTHON_LIBRARY ) - swig_link_libraries ( ftdi1 ${PYTHON_LIBRARIES} ) + swig_link_libraries ( pyftdi1 ${PYTHON_LIBRARIES} ) elseif( APPLE ) - set_target_properties ( ${SWIG_MODULE_ftdi1_REAL_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" ) + set_target_properties ( pyftdi1 PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" ) endif () -set_target_properties ( ${SWIG_MODULE_ftdi1_REAL_NAME} PROPERTIES NO_SONAME ON ) +set_target_properties ( pyftdi1 PROPERTIES NO_SONAME ON ) execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib', vars={'platbase': '${CMAKE_INSTALL_PREFIX}'} ) )" OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH @@ -52,7 +42,7 @@ file ( RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTH set ( PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH} ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/ftdi1.py DESTINATION ${PYTHON_MODULE_PATH} ) -install ( TARGETS ${SWIG_MODULE_ftdi1_REAL_NAME} LIBRARY DESTINATION ${PYTHON_MODULE_PATH} ) +install ( TARGETS pyftdi1 LIBRARY DESTINATION ${PYTHON_MODULE_PATH} ) if ( DOCUMENTATION ) # Run doxygen to only generate the xml @@ -75,7 +65,7 @@ if ( DOCUMENTATION ) COMMENT "Python API bindings documentation" DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i ) - add_dependencies( ${SWIG_MODULE_ftdi1_REAL_NAME} doc_i ) + add_dependencies( pyftdi1 doc_i ) endif ( DOCUMENTATION ) -- 1.7.1 From 18499a2fa496c20e5e35590bb89eb701fa9fdfea Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Wed, 11 Jun 2025 14:50:04 +0200 Subject: [PATCH 05/16] Ignore VSCode temp folder --- .gitignore | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index 3d04163..9f1af71 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,6 @@ tags # clangd specific files .cache compile_commands.json + +# VSCode +.vscode -- 1.7.1 From 2a992306c0acf938b29fa0cd5fbc160e24424209 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Wed, 11 Jun 2025 11:54:16 +0200 Subject: [PATCH 06/16] Add SHAREDLIBS option This option is needed to still produce .so files when building static libs only. --- CMakeLists.txt | 49 +++++++++++++++++++++++++++++-------------- CMakeOptions.txt | 1 + ftdi_eeprom/CMakeLists.txt | 3 ++ ftdipp/CMakeLists.txt | 40 +++++++++++++++++------------------ src/CMakeLists.txt | 39 +++++++++++++++++------------------ 5 files changed, 75 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 385952e..ce9ccb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,22 +190,38 @@ endif () set ( LIBFTDI_INCLUDE_DIR ${includedir} ) set ( LIBFTDI_INCLUDE_DIRS ${LIBFTDI_INCLUDE_DIR} ) -set ( LIBFTDI_LIBRARY ftdi1 ) -set ( LIBFTDI_LIBRARIES ${LIBFTDI_LIBRARY} ) -list ( APPEND LIBFTDI_LIBRARIES ${LIBUSB_LIBRARIES} ) -set ( LIBFTDI_STATIC_LIBRARY ftdi1.a ) -set ( LIBFTDI_STATIC_LIBRARIES ${LIBFTDI_STATIC_LIBRARY} ) -list ( APPEND LIBFTDI_STATIC_LIBRARIES ${LIBUSB_LIBRARIES} ) -if ( FTDIPP ) - set ( LIBFTDIPP_LIBRARY ftdipp1 ) - set ( LIBFTDIPP_LIBRARIES ${LIBFTDIPP_LIBRARY} ) - list ( APPEND LIBFTDIPP_LIBRARIES ${LIBUSB_LIBRARIES} ) -endif () -set ( LIBFTDI_LIBRARY_DIRS ${libdir} ) -set ( LIBFTDI_ROOT_DIR ${prefix} ) -set ( LIBFTDI_VERSION_STRING ${VERSION_STRING} ) -set ( LIBFTDI_VERSION_MAJOR ${MAJOR_VERSION} ) -set ( LIBFTDI_VERSION_MINOR ${MINOR_VERSION} ) + +# Set up library variables based on what's being built +if(SHAREDLIBS) + set(LIBFTDI_LIBRARY ftdi1) + set(LIBFTDI_LIBRARIES ${LIBFTDI_LIBRARY}) + list(APPEND LIBFTDI_LIBRARIES ${LIBUSB_LIBRARIES}) +endif() + +if(STATICLIBS) + set(LIBFTDI_STATIC_LIBRARY ftdi1.a) + set(LIBFTDI_STATIC_LIBRARIES ${LIBFTDI_STATIC_LIBRARY}) + list(APPEND LIBFTDI_STATIC_LIBRARIES ${LIBUSB_LIBRARIES}) +endif() + +if(FTDIPP) + if(SHAREDLIBS) + set(LIBFTDIPP_LIBRARY ftdipp1) + set(LIBFTDIPP_LIBRARIES ${LIBFTDIPP_LIBRARY}) + list(APPEND LIBFTDIPP_LIBRARIES ${LIBUSB_LIBRARIES}) + endif() + if(STATICLIBS) + set(LIBFTDIPP_STATIC_LIBRARY ftdipp1.a) + set(LIBFTDIPP_STATIC_LIBRARIES ${LIBFTDIPP_STATIC_LIBRARY}) + list(APPEND LIBFTDIPP_STATIC_LIBRARIES ${LIBUSB_LIBRARIES}) + endif() +endif() + +set(LIBFTDI_LIBRARY_DIRS ${libdir}) +set(LIBFTDI_ROOT_DIR ${prefix}) +set(LIBFTDI_VERSION_STRING ${VERSION_STRING}) +set(LIBFTDI_VERSION_MAJOR ${MAJOR_VERSION}) +set(LIBFTDI_VERSION_MINOR ${MINOR_VERSION}) set ( LIBFTDI_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIBFTDI_CMAKE_CONFIG_DIR}/UseLibFTDI1.cmake ) @@ -241,6 +257,7 @@ include(CPack) message (STATUS "Summary of build options: + Build shared libs: ${SHAREDLIBS} Build static libs: ${STATICLIBS} Build C++ bindings: ${FTDIPP} Build Python bindings: ${PYTHON_BINDINGS} diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 07b5887..c20743c 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -1,4 +1,5 @@ option ( STATICLIBS "Build static libraries" ON ) +option ( SHAREDLIBS "Build shared/dynamic libraries" ON ) option ( BUILD_TESTS "Build unit tests with Boost Unit Test framework" OFF ) option ( DOCUMENTATION "Generate API documentation with Doxygen" OFF ) option ( EXAMPLES "Build example programs" ON ) diff --git a/ftdi_eeprom/CMakeLists.txt b/ftdi_eeprom/CMakeLists.txt index 525421e..3432d4c 100644 --- a/ftdi_eeprom/CMakeLists.txt +++ b/ftdi_eeprom/CMakeLists.txt @@ -40,5 +40,8 @@ target_link_libraries ( ftdi_eeprom ftdi1 ${CONFUSE_LIBRARIES} ) if ( LIBINTL_FOUND ) target_link_libraries ( ftdi_eeprom ${LIBINTL_LIBRARIES} ) endif () +if ( NOT SHAREDLIBS AND STATICLIBS ) + target_link_libraries ( ftdi_eeprom ${LIBUSB_LIBRARIES} ) +endif () install ( TARGETS ftdi_eeprom DESTINATION bin ) install ( FILES example.conf DESTINATION ${CMAKE_INSTALL_DOCDIR} ) diff --git a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt index 71e6055..4172d75 100644 --- a/ftdipp/CMakeLists.txt +++ b/ftdipp/CMakeLists.txt @@ -9,36 +9,34 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ) # Shared library -add_library(ftdipp1 SHARED ${cpp_sources}) - -math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases -set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3) - -# Prevent clobbering each other during the build -set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) - -# Dependencies -target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES}) - -install ( TARGETS ftdipp1 +if ( SHAREDLIBS ) + add_library(ftdipp1 SHARED ${cpp_sources}) + math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases + set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3) + # Prevent clobbering each other during the build + set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) + # Dependencies + target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES}) + install(TARGETS ftdipp1 RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) + ) +endif() # Static library if ( STATICLIBS ) add_library(ftdipp1-static STATIC ${cpp_sources}) set_target_properties(ftdipp1-static PROPERTIES OUTPUT_NAME "ftdipp1") set_target_properties(ftdipp1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) - - install ( TARGETS ftdipp1-static - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT staticlibs + target_link_libraries(ftdipp1-static ftdi1-static ${LIBUSB_LIBRARIES}) + install(TARGETS ftdipp1-static + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT staticlibs ) -endif () +endif() -install ( FILES ${cpp_headers} - DESTINATION include/${PROJECT_NAME} - COMPONENT headers +install(FILES ${cpp_headers} + DESTINATION include/${PROJECT_NAME} + COMPONENT headers ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e145af1..5798ab0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,35 +21,34 @@ configure_file(ftdi_version_i.h.in "${CMAKE_CURRENT_BINARY_DIR}/ftdi_version_i.h set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" ) set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" ) -add_library(ftdi1 SHARED ${c_sources}) - -math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases -set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2) -# Prevent clobbering each other during the build -set_target_properties ( ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1 ) - - -# Dependencies -target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES}) - -install ( TARGETS ftdi1 +# Shared library +if ( SHAREDLIBS ) + add_library(ftdi1 SHARED ${c_sources}) + math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases + set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2) + # Prevent clobbering each other during the build + set_target_properties(ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) + target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES}) + install(TARGETS ftdi1 RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) + ) +endif() +# Static library if ( STATICLIBS ) add_library(ftdi1-static STATIC ${c_sources}) target_link_libraries(ftdi1-static ${LIBUSB_LIBRARIES}) set_target_properties(ftdi1-static PROPERTIES OUTPUT_NAME "ftdi1") set_target_properties(ftdi1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) - install ( TARGETS ftdi1-static - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT staticlibs + install(TARGETS ftdi1-static + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT staticlibs ) -endif () +endif() -install ( FILES ${c_headers} - DESTINATION include/${PROJECT_NAME} - COMPONENT headers +install(FILES ${c_headers} + DESTINATION include/${PROJECT_NAME} + COMPONENT headers ) -- 1.7.1 From c4962c38a1ab470fbdc835c231567bd582eb5a5a Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 10 Apr 2024 07:15:40 -0700 Subject: [PATCH 07/16] msvc: fix warnings by using all enum values in case statements --- src/ftdi.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index 534e3dd..b773303 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -2918,8 +2918,12 @@ static unsigned char type2bit(unsigned char type, enum ftdi_chip_type chip) } } case TYPE_230X: /* FT230X is only UART */ + case TYPE_AM: + case TYPE_BM: + case TYPE_4232H: default: return 0; } + /* fallback */ return 0; } @@ -4625,7 +4629,7 @@ int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr, switch (ftdi->type) { case TYPE_BM: - case TYPE_2232C: + case TYPE_2232C: chip_type_location = 0x14; break; case TYPE_2232H: @@ -4635,6 +4639,9 @@ int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr, case TYPE_232H: chip_type_location = 0x1e; break; + case TYPE_AM: + case TYPE_R: + case TYPE_230X: default: ftdi_error_return(-4, "Device can't access unprotected area"); } -- 1.7.1 From c2b7c25e1272222c1719daea5761093fbc9c3010 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 10 Apr 2024 07:15:41 -0700 Subject: [PATCH 08/16] msvc: fix shadowed variable warning --- src/ftdi_stream.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ftdi_stream.c b/src/ftdi_stream.c index 4229d94..d146afd 100644 --- a/src/ftdi_stream.c +++ b/src/ftdi_stream.c @@ -245,13 +245,13 @@ ftdi_readstream(struct ftdi_context *ftdi, (ftdi->usb_read_timeout % 1000) * 1000 }; struct timeval now; - int err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout); - if (err == LIBUSB_ERROR_INTERRUPTED) + int xfer_err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout); + if (xfer_err == LIBUSB_ERROR_INTERRUPTED) /* restart interrupted events */ - err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout); + xfer_err = libusb_handle_events_timeout(ftdi->usb_ctx, &timeout); if (!state.result) { - state.result = err; + state.result = xfer_err; } if (state.activity == 0) state.result = 1; -- 1.7.1 From d31e3d5697eacbe87cd310b5bce615f3d8426cc0 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 10 Apr 2024 07:15:43 -0700 Subject: [PATCH 09/16] cmake: fix elseif statement --- CMakeLists.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce9ccb4..1f187e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ endif () if(NOT APPLE) if(CMAKE_SIZEOF_VOID_P EQUAL 4) SET(PACK_ARCH "") - else(CMAKE_SIZEOF_VOID_P EQUAL 8) + elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) SET(PACK_ARCH .x86_64) endif(CMAKE_SIZEOF_VOID_P EQUAL 4) else(NOT APPLE) -- 1.7.1 From d96dbea887373f26755e9873b4ab020f922b7c3b Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 10 Apr 2024 07:15:47 -0700 Subject: [PATCH 10/16] fix unit var warning if ftdi_read_eeprom_location returned error, data would not be initialized --- src/ftdi.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index b773303..de07d6e 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -3521,7 +3521,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) i = 0x40; } if ((ftdi->type == TYPE_230X) && (i >= 0x40) && (i < 0x50)) { - uint16_t data; + uint16_t data = 0; if (ftdi_read_eeprom_location(ftdi, i, &data)) { fprintf(stderr, "Reading Factory Configuration Data failed\n"); i = 0x50; -- 1.7.1 From 2e714eec137f86ca1950457d8226d8cb9b71c495 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 10 Apr 2024 07:15:48 -0700 Subject: [PATCH 11/16] msvc: quiet uninteresting warnings --- src/CMakeLists.txt | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5798ab0..ae51242 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,33 @@ message(STATUS "Detected git snapshot version: ${SNAPSHOT_VERSION}") configure_file(ftdi_version_i.h.in "${CMAKE_CURRENT_BINARY_DIR}/ftdi_version_i.h" @ONLY) +if(MSVC) + # Disable some overly-verbose warnings activated by -Wall + + # '': function not inlined + add_compile_options(/wd4710) + + # function '' selected for automatic inline expansion + add_compile_options(/wd4711) + + # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified + add_compile_options(/wd5045) + + # '': '4' bytes padding added after data member '' + add_compile_options(/wd4820) + + # conversion from '' to '', possible loss of data + add_compile_options(/wd4242 /wd4244 /wd4267) + + # Disable warning on unsafe string functions + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + + if(MSVC_VERSION GREATER_EQUAL 1913) + # Disable warnings from system headers + add_compile_options(/external:anglebrackets /external:W0) + endif() +endif() + # Targets set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" ) set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" ) -- 1.7.1 From 5e67403c4fb5536a2effe2e91181dd73a2cff91b Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Wed, 10 Apr 2024 07:15:49 -0700 Subject: [PATCH 12/16] cmake: fix building static lib on windows/msvc include(GNUInstallDirs) is required to populate CMAKE_INSTALL_LIBDIR [TJ: Patch partially applied: Dropped the lib rename part from ftdi1.a to ftdi1-static] --- CMakeLists.txt | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f187e4..3ee49c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,8 @@ if(NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) file(GENERATE OUTPUT .gitignore CONTENT "*") endif() +include(GNUInstallDirs) + add_definitions(-Wall) include(CMakeOptions.txt) @@ -170,6 +172,9 @@ if(${UNIX}) endif(${UNIX}) if(${WIN32}) set(libdir ${CMAKE_INSTALL_PREFIX}/bin) + if(STATICLIBS) + list(APPEND libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) + endif() endif(${WIN32}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libftdi1.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1.pc @ONLY) -- 1.7.1 From 019f48462836c9f3a0a1f113a351395ddcf99640 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Thu, 12 Jun 2025 23:13:02 +0200 Subject: [PATCH 13/16] CMake: auto-format all CMake files Use CLion 2025.1 to auto-format all CMake files, bringing formatting consistency to those files. (the open source cmake-format tool didn't see any git activity in four years) No other changes were done, "git diff -b" looks way more harmless. --- CMakeLists.txt | 300 ++++++++++++++++---------------- CMakeOptions.txt | 18 +- doc/CMakeLists.txt | 44 +++--- examples/CMakeLists.txt | 32 ++-- examples/cmake_example/CMakeLists.txt | 14 +- ftdi_eeprom/CMakeLists.txt | 58 +++--- ftdipp/CMakeLists.txt | 56 +++--- packages/CMakeLists.txt | 28 ++-- python/CMakeLists.txt | 116 +++++++------- python/examples/CMakeLists.txt | 8 +- src/CMakeLists.txt | 100 ++++++------ 11 files changed, 387 insertions(+), 387 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ee49c6..105f83a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,21 +14,21 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Target link properties INTERFACE_LINK_OPTIONS, INTERFACE_LINK_DIRECTORIES # and INTERFACE_LINK_DEPENDS are now transitive over private dependencies # of static libraries -if(POLICY CMP0099) - cmake_policy(SET CMP0099 NEW) -endif() +if (POLICY CMP0099) + cmake_policy(SET CMP0099 NEW) +endif () # CMake -if("${CMAKE_BUILD_TYPE}" STREQUAL "") - set(CMAKE_BUILD_TYPE RelWithDebInfo) -endif("${CMAKE_BUILD_TYPE}" STREQUAL "") +if ("${CMAKE_BUILD_TYPE}" STREQUAL "") + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif ("${CMAKE_BUILD_TYPE}" STREQUAL "") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -if(NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) - # Auto-create a .gitignore in the out-of-source build directory. - file(GENERATE OUTPUT .gitignore CONTENT "*") -endif() +if (NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + # Auto-create a .gitignore in the out-of-source build directory. + file(GENERATE OUTPUT .gitignore CONTENT "*") +endif () include(GNUInstallDirs) @@ -38,18 +38,18 @@ include(CMakeOptions.txt) # Debug build message("-- Build type: ${CMAKE_BUILD_TYPE}") -if(${CMAKE_BUILD_TYPE} STREQUAL Debug) - add_definitions(-DDEBUG) -endif(${CMAKE_BUILD_TYPE} STREQUAL Debug) +if (${CMAKE_BUILD_TYPE} STREQUAL Debug) + add_definitions(-DDEBUG) +endif (${CMAKE_BUILD_TYPE} STREQUAL Debug) # Find libusb -find_package ( LibUSB REQUIRED ) -include_directories ( ${LIBUSB_INCLUDE_DIR} ) +find_package(LibUSB REQUIRED) +include_directories(${LIBUSB_INCLUDE_DIR}) # Find Boost if (BUILD_TESTS) - find_package( Boost REQUIRED ) -endif() + find_package(Boost REQUIRED) +endif () # Set components set(CPACK_COMPONENTS_ALL sharedlibs staticlibs headers) @@ -58,124 +58,124 @@ set(CPACK_COMPONENT_STATICLIBS_DISPLAY_NAME "Static libraries") set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers") set(CPACK_COMPONENT_SHAREDLIBS_DESCRIPTION -"Shared library for general use.") + "Shared library for general use.") set(CPACK_COMPONENT_STATICLIBS_DESCRIPTION -"Static library, good if you want to embed libftdi1 in your application.") + "Static library, good if you want to embed libftdi1 in your application.") set(CPACK_COMPONENT_HEADERS_DESCRIPTION -"C/C++ header files.") + "C/C++ header files.") set(CPACK_COMPONENT_SHAREDLIBS_GROUP "Development") set(CPACK_COMPONENT_STATICLIBS_GROUP "Development") -set(CPACK_COMPONENT_HEADERS_GROUP "Development") +set(CPACK_COMPONENT_HEADERS_GROUP "Development") # guess LIB_SUFFIX, don't take debian multiarch into account -if ( NOT DEFINED LIB_SUFFIX ) - if( CMAKE_SYSTEM_NAME MATCHES "Linux" - AND NOT CMAKE_CROSSCOMPILING - AND NOT EXISTS "/etc/debian_version" - AND NOT EXISTS "/etc/arch-release" ) - if ( "${CMAKE_SIZEOF_VOID_P}" EQUAL "8" ) - set ( LIB_SUFFIX 64 ) +if (NOT DEFINED LIB_SUFFIX) + if (CMAKE_SYSTEM_NAME MATCHES "Linux" + AND NOT CMAKE_CROSSCOMPILING + AND NOT EXISTS "/etc/debian_version" + AND NOT EXISTS "/etc/arch-release") + if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + set(LIB_SUFFIX 64) + endif () endif () - endif () endif () -if(NOT APPLE) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) +if (NOT APPLE) + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + SET(PACK_ARCH "") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + SET(PACK_ARCH .x86_64) + endif (CMAKE_SIZEOF_VOID_P EQUAL 4) +else (NOT APPLE) SET(PACK_ARCH "") - elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) - SET(PACK_ARCH .x86_64) - endif(CMAKE_SIZEOF_VOID_P EQUAL 4) -else(NOT APPLE) - SET(PACK_ARCH "") -endif(NOT APPLE) +endif (NOT APPLE) # Package information -set(CPACK_PACKAGE_VERSION ${VERSION_STRING}) -set(CPACK_PACKAGE_CONTACT "Intra2net AG ") -set(CPACK_PACKAGE_DESCRIPTION "libftdi1 library.") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${CPACK_PACKAGE_DESCRIPTION}) +set(CPACK_PACKAGE_VERSION ${VERSION_STRING}) +set(CPACK_PACKAGE_CONTACT "Intra2net AG ") +set(CPACK_PACKAGE_DESCRIPTION "libftdi1 library.") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${CPACK_PACKAGE_DESCRIPTION}) # Package settings -if ( UNIX ) - set(CPACK_GENERATOR "DEB;RPM") - set(CPACK_CMAKE_GENERATOR "Unix Makefiles") - set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) - set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}${PACK_ARCH}) +if (UNIX) + set(CPACK_GENERATOR "DEB;RPM") + set(CPACK_CMAKE_GENERATOR "Unix Makefiles") + set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) + set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}${PACK_ARCH}) endif () -if ( WIN32 ) - set ( CPACK_GENERATOR "NSIS" ) - set ( CPACK_CMAKE_GENERATOR "MinGW Makefiles" ) - set ( CPACK_PACKAGE_NAME "${PROJECT_NAME}" ) - set ( CPACK_PACKAGE_VENDOR "" ) - set ( CPACK_PACKAGE_INSTALL_DIRECTORY "libftdi1" ) - set ( CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32") - set ( CPACK_NSIS_DISPLAY_NAME "libftdi1" ) - set ( CPACK_NSIS_MODIFY_PATH ON ) +if (WIN32) + set(CPACK_GENERATOR "NSIS") + set(CPACK_CMAKE_GENERATOR "MinGW Makefiles") + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") + set(CPACK_PACKAGE_VENDOR "") + set(CPACK_PACKAGE_INSTALL_DIRECTORY "libftdi1") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32") + set(CPACK_NSIS_DISPLAY_NAME "libftdi1") + set(CPACK_NSIS_MODIFY_PATH ON) endif () -set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) +set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) -set(CPACK_SOURCE_GENERATOR TGZ) -set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;~$;build/") -set(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}) +set(CPACK_SOURCE_GENERATOR TGZ) +set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;~$;build/") +set(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}) # Subdirectories -if ( UNIX ) - set ( CPACK_SET_DESTDIR ON ) +if (UNIX) + set(CPACK_SET_DESTDIR ON) endif () # "make dist" target set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${VERSION_STRING}) add_custom_target(dist - COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD - | bzip2 > ${PROJECT_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2 - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD + | bzip2 > ${PROJECT_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(src) add_subdirectory(packages) -if ( DOCUMENTATION ) - add_subdirectory(doc) -endif ( DOCUMENTATION ) +if (DOCUMENTATION) + add_subdirectory(doc) +endif (DOCUMENTATION) -if ( FTDIPP ) - project(libftdi1 C CXX) - add_subdirectory(ftdipp) -endif ( FTDIPP ) +if (FTDIPP) + project(libftdi1 C CXX) + add_subdirectory(ftdipp) +endif (FTDIPP) -if ( PYTHON_BINDINGS ) - add_subdirectory(python) -endif ( PYTHON_BINDINGS ) +if (PYTHON_BINDINGS) + add_subdirectory(python) +endif (PYTHON_BINDINGS) -if ( FTDI_EEPROM ) - add_subdirectory(ftdi_eeprom) -endif ( FTDI_EEPROM ) +if (FTDI_EEPROM) + add_subdirectory(ftdi_eeprom) +endif (FTDI_EEPROM) -if ( EXAMPLES ) - add_subdirectory(examples) -endif ( EXAMPLES ) +if (EXAMPLES) + add_subdirectory(examples) +endif (EXAMPLES) -if ( BUILD_TESTS ) - project(libftdi1 C CXX) - add_subdirectory(test) -endif ( BUILD_TESTS ) +if (BUILD_TESTS) + project(libftdi1 C CXX) + add_subdirectory(test) +endif (BUILD_TESTS) # PkgConfig -set(prefix ${CMAKE_INSTALL_PREFIX}) +set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) -set(includedir ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}) - -if(${UNIX}) - set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) -endif(${UNIX}) -if(${WIN32}) - set(libdir ${CMAKE_INSTALL_PREFIX}/bin) - if(STATICLIBS) - list(APPEND libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) - endif() -endif(${WIN32}) +set(includedir ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}) + +if (${UNIX}) + set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) +endif (${UNIX}) +if (${WIN32}) + set(libdir ${CMAKE_INSTALL_PREFIX}/bin) + if (STATICLIBS) + list(APPEND libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) + endif () +endif (${WIN32}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libftdi1.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1.pc @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libftdipp1.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libftdipp1.pc @ONLY) @@ -183,44 +183,44 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libftdi1.pc ${CMAKE_CURRENT_BINARY_DIR DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) if (UNIX OR MINGW) - configure_file ( libftdi1-config.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config @ONLY ) - install ( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config - DESTINATION bin ) + configure_file(libftdi1-config.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config @ONLY) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config + DESTINATION bin) endif () # config script install path -if ( NOT DEFINED LIBFTDI_CMAKE_CONFIG_DIR ) - set ( LIBFTDI_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/libftdi1 ) +if (NOT DEFINED LIBFTDI_CMAKE_CONFIG_DIR) + set(LIBFTDI_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/libftdi1) endif () -set ( LIBFTDI_INCLUDE_DIR ${includedir} ) -set ( LIBFTDI_INCLUDE_DIRS ${LIBFTDI_INCLUDE_DIR} ) +set(LIBFTDI_INCLUDE_DIR ${includedir}) +set(LIBFTDI_INCLUDE_DIRS ${LIBFTDI_INCLUDE_DIR}) # Set up library variables based on what's being built -if(SHAREDLIBS) - set(LIBFTDI_LIBRARY ftdi1) - set(LIBFTDI_LIBRARIES ${LIBFTDI_LIBRARY}) - list(APPEND LIBFTDI_LIBRARIES ${LIBUSB_LIBRARIES}) -endif() - -if(STATICLIBS) - set(LIBFTDI_STATIC_LIBRARY ftdi1.a) - set(LIBFTDI_STATIC_LIBRARIES ${LIBFTDI_STATIC_LIBRARY}) - list(APPEND LIBFTDI_STATIC_LIBRARIES ${LIBUSB_LIBRARIES}) -endif() - -if(FTDIPP) - if(SHAREDLIBS) - set(LIBFTDIPP_LIBRARY ftdipp1) - set(LIBFTDIPP_LIBRARIES ${LIBFTDIPP_LIBRARY}) - list(APPEND LIBFTDIPP_LIBRARIES ${LIBUSB_LIBRARIES}) - endif() - if(STATICLIBS) - set(LIBFTDIPP_STATIC_LIBRARY ftdipp1.a) - set(LIBFTDIPP_STATIC_LIBRARIES ${LIBFTDIPP_STATIC_LIBRARY}) - list(APPEND LIBFTDIPP_STATIC_LIBRARIES ${LIBUSB_LIBRARIES}) - endif() -endif() +if (SHAREDLIBS) + set(LIBFTDI_LIBRARY ftdi1) + set(LIBFTDI_LIBRARIES ${LIBFTDI_LIBRARY}) + list(APPEND LIBFTDI_LIBRARIES ${LIBUSB_LIBRARIES}) +endif () + +if (STATICLIBS) + set(LIBFTDI_STATIC_LIBRARY ftdi1.a) + set(LIBFTDI_STATIC_LIBRARIES ${LIBFTDI_STATIC_LIBRARY}) + list(APPEND LIBFTDI_STATIC_LIBRARIES ${LIBUSB_LIBRARIES}) +endif () + +if (FTDIPP) + if (SHAREDLIBS) + set(LIBFTDIPP_LIBRARY ftdipp1) + set(LIBFTDIPP_LIBRARIES ${LIBFTDIPP_LIBRARY}) + list(APPEND LIBFTDIPP_LIBRARIES ${LIBUSB_LIBRARIES}) + endif () + if (STATICLIBS) + set(LIBFTDIPP_STATIC_LIBRARY ftdipp1.a) + set(LIBFTDIPP_STATIC_LIBRARIES ${LIBFTDIPP_STATIC_LIBRARY}) + list(APPEND LIBFTDIPP_STATIC_LIBRARIES ${LIBUSB_LIBRARIES}) + endif () +endif () set(LIBFTDI_LIBRARY_DIRS ${libdir}) set(LIBFTDI_ROOT_DIR ${prefix}) @@ -228,39 +228,39 @@ set(LIBFTDI_VERSION_STRING ${VERSION_STRING}) set(LIBFTDI_VERSION_MAJOR ${MAJOR_VERSION}) set(LIBFTDI_VERSION_MINOR ${MINOR_VERSION}) -set ( LIBFTDI_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIBFTDI_CMAKE_CONFIG_DIR}/UseLibFTDI1.cmake ) +set(LIBFTDI_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIBFTDI_CMAKE_CONFIG_DIR}/UseLibFTDI1.cmake) include(CMakePackageConfigHelpers) -configure_package_config_file ( - cmake/LibFTDI1Config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1Config.cmake - INSTALL_DESTINATION ${LIBFTDI_CMAKE_CONFIG_DIR} - PATH_VARS - LIBFTDI_USE_FILE - LIBFTDI_ROOT_DIR - LIBFTDI_INCLUDE_DIR - LIBFTDI_INCLUDE_DIRS - LIBFTDI_LIBRARY_DIRS - NO_CHECK_REQUIRED_COMPONENTS_MACRO +configure_package_config_file( + cmake/LibFTDI1Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1Config.cmake + INSTALL_DESTINATION ${LIBFTDI_CMAKE_CONFIG_DIR} + PATH_VARS + LIBFTDI_USE_FILE + LIBFTDI_ROOT_DIR + LIBFTDI_INCLUDE_DIR + LIBFTDI_INCLUDE_DIRS + LIBFTDI_LIBRARY_DIRS + NO_CHECK_REQUIRED_COMPONENTS_MACRO ) -write_basic_package_version_file ( - LibFTDI1ConfigVersion.cmake - VERSION ${LIBFTDI_VERSION_STRING} - COMPATIBILITY AnyNewerVersion +write_basic_package_version_file( + LibFTDI1ConfigVersion.cmake + VERSION ${LIBFTDI_VERSION_STRING} + COMPATIBILITY AnyNewerVersion ) -install ( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1ConfigVersion.cmake - cmake/UseLibFTDI1.cmake - DESTINATION ${LIBFTDI_CMAKE_CONFIG_DIR} +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1ConfigVersion.cmake + cmake/UseLibFTDI1.cmake + DESTINATION ${LIBFTDI_CMAKE_CONFIG_DIR} ) include(CPack) -message (STATUS "Summary of build options: +message(STATUS "Summary of build options: Build shared libs: ${SHAREDLIBS} Build static libs: ${STATICLIBS} diff --git a/CMakeOptions.txt b/CMakeOptions.txt index c20743c..b4d3cfa 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -1,9 +1,9 @@ -option ( STATICLIBS "Build static libraries" ON ) -option ( SHAREDLIBS "Build shared/dynamic libraries" ON ) -option ( BUILD_TESTS "Build unit tests with Boost Unit Test framework" OFF ) -option ( DOCUMENTATION "Generate API documentation with Doxygen" OFF ) -option ( EXAMPLES "Build example programs" ON ) -option ( FTDIPP "Build C++ binding library libftdi1++" OFF ) -option ( FTDI_EEPROM "Build ftdi_eeprom" ON ) -option ( PYTHON_BINDINGS "Build python bindings via swig" OFF ) -option ( LINK_PYTHON_LIBRARY "Link against python libraries" OFF ) +option(STATICLIBS "Build static libraries" ON) +option(SHAREDLIBS "Build shared/dynamic libraries" ON) +option(BUILD_TESTS "Build unit tests with Boost Unit Test framework" OFF) +option(DOCUMENTATION "Generate API documentation with Doxygen" OFF) +option(EXAMPLES "Build example programs" ON) +option(FTDIPP "Build C++ binding library libftdi1++" OFF) +option(FTDI_EEPROM "Build ftdi_eeprom" ON) +option(PYTHON_BINDINGS "Build python bindings via swig" OFF) +option(LINK_PYTHON_LIBRARY "Link against python libraries" OFF) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 983301d..8e83711 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,26 +1,26 @@ -find_package ( Doxygen REQUIRED ) + find_package(Doxygen REQUIRED) -# Copy doxy.config.in -configure_file( - ${PROJECT_SOURCE_DIR}/doc/Doxyfile.in - ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile -) + # Copy doxy.config.in + configure_file( + ${PROJECT_SOURCE_DIR}/doc/Doxyfile.in + ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + ) -configure_file( - ${PROJECT_SOURCE_DIR}/doc/Doxyfile.xml.in - ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.xml -) + configure_file( + ${PROJECT_SOURCE_DIR}/doc/Doxyfile.xml.in + ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.xml + ) -# Run doxygen -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html - COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile - COMMENT "Generating API documentation" - DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers} -) + # Run doxygen + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + COMMENT "Generating API documentation" + DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers} + ) -add_custom_target( - docs ALL - COMMENT "Documentation target docs" - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html -) + add_custom_target( + docs ALL + COMMENT "Documentation target docs" + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html + ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index bda84e0..08e1e53 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,6 +1,6 @@ # Includes -include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} +include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ) # Targets @@ -15,9 +15,9 @@ add_executable(baud_test baud_test.c) add_executable(stream_test stream_test.c) add_executable(eeprom eeprom.c) add_executable(async async.c) -if(NOT MINGW) - add_executable(purge_test purge_test.c) -endif(NOT MINGW) +if (NOT MINGW) + add_executable(purge_test purge_test.c) +endif (NOT MINGW) # Linkage target_link_libraries(simple ftdi1) @@ -31,21 +31,21 @@ target_link_libraries(baud_test ftdi1) target_link_libraries(stream_test ftdi1) target_link_libraries(eeprom ftdi1) target_link_libraries(async ftdi1) -if(NOT MINGW) - target_link_libraries(purge_test ftdi1) -endif(NOT MINGW) +if (NOT MINGW) + target_link_libraries(purge_test ftdi1) +endif (NOT MINGW) # libftdi++ examples -if( FTDIPP ) - include_directories(BEFORE ${PROJECT_SOURCE_DIR}/ftdipp - ) +if (FTDIPP) + include_directories(BEFORE ${PROJECT_SOURCE_DIR}/ftdipp + ) - # Target - add_executable(find_all_pp find_all_pp.cpp) + # Target + add_executable(find_all_pp find_all_pp.cpp) - # Linkage - target_link_libraries(find_all_pp ftdipp1) -endif( FTDIPP ) + # Linkage + target_link_libraries(find_all_pp ftdipp1) +endif (FTDIPP) # Source includes include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src) diff --git a/examples/cmake_example/CMakeLists.txt b/examples/cmake_example/CMakeLists.txt index 7d60693..acd3880 100644 --- a/examples/cmake_example/CMakeLists.txt +++ b/examples/cmake_example/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) -project ( example C ) +project(example C) -find_package ( LibFTDI1 NO_MODULE REQUIRED ) -include ( ${LIBFTDI_USE_FILE} ) +find_package(LibFTDI1 NO_MODULE REQUIRED) +include(${LIBFTDI_USE_FILE}) -add_executable ( example main.c ) -target_link_libraries( example ${LIBFTDI_LIBRARIES} ) +add_executable(example main.c) +target_link_libraries(example ${LIBFTDI_LIBRARIES}) -install ( TARGETS example - DESTINATION bin +install(TARGETS example + DESTINATION bin ) diff --git a/ftdi_eeprom/CMakeLists.txt b/ftdi_eeprom/CMakeLists.txt index 3432d4c..3958b66 100644 --- a/ftdi_eeprom/CMakeLists.txt +++ b/ftdi_eeprom/CMakeLists.txt @@ -1,47 +1,47 @@ -find_package ( Confuse REQUIRED ) -find_package ( Libintl ) +find_package(Confuse REQUIRED) +find_package(Libintl) # determine docdir include(GNUInstallDirs) -if(NOT CMAKE_INSTALL_DOCDIR) - if(WIN32) - set(CMAKE_INSTALL_DOCDIR .) - else(WIN32) - set(CMAKE_INSTALL_DOCDIR ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}) - endif(WIN32) -endif(NOT CMAKE_INSTALL_DOCDIR) +if (NOT CMAKE_INSTALL_DOCDIR) + if (WIN32) + set(CMAKE_INSTALL_DOCDIR .) + else (WIN32) + set(CMAKE_INSTALL_DOCDIR ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}) + endif (WIN32) +endif (NOT CMAKE_INSTALL_DOCDIR) message(STATUS "Building ftdi_eeprom") -include_directories ( ${CONFUSE_INCLUDE_DIRS} ) -list ( APPEND libs ${CONFUSE_LIBRARIES} ) +include_directories(${CONFUSE_INCLUDE_DIRS}) +list(APPEND libs ${CONFUSE_LIBRARIES}) -if ( LIBINTL_FOUND ) - include_directories ( ${LIBINTL_INCLUDE_DIR} ) - list ( APPEND libs ${LIBINTL_LIBRARIES} ) +if (LIBINTL_FOUND) + include_directories(${LIBINTL_INCLUDE_DIR}) + list(APPEND libs ${LIBINTL_LIBRARIES}) endif () # Version defines -set ( EEPROM_MAJOR_VERSION 0 ) -set ( EEPROM_MINOR_VERSION 17 ) -set ( EEPROM_VERSION_STRING ${EEPROM_MAJOR_VERSION}.${EEPROM_MINOR_VERSION} ) +set(EEPROM_MAJOR_VERSION 0) +set(EEPROM_MINOR_VERSION 17) +set(EEPROM_VERSION_STRING ${EEPROM_MAJOR_VERSION}.${EEPROM_MINOR_VERSION}) -include_directories ( BEFORE ${PROJECT_SOURCE_DIR}/src ) -include_directories ( BEFORE ${CMAKE_CURRENT_BINARY_DIR} ) +include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src) +include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) configure_file( - ftdi_eeprom_version.h.in - ${CMAKE_CURRENT_BINARY_DIR}/ftdi_eeprom_version.h + ftdi_eeprom_version.h.in + ${CMAKE_CURRENT_BINARY_DIR}/ftdi_eeprom_version.h ) -add_executable ( ftdi_eeprom main.c ) -target_link_libraries ( ftdi_eeprom ftdi1 ${CONFUSE_LIBRARIES} ) -if ( LIBINTL_FOUND ) - target_link_libraries ( ftdi_eeprom ${LIBINTL_LIBRARIES} ) +add_executable(ftdi_eeprom main.c) +target_link_libraries(ftdi_eeprom ftdi1 ${CONFUSE_LIBRARIES}) +if (LIBINTL_FOUND) + target_link_libraries(ftdi_eeprom ${LIBINTL_LIBRARIES}) endif () -if ( NOT SHAREDLIBS AND STATICLIBS ) - target_link_libraries ( ftdi_eeprom ${LIBUSB_LIBRARIES} ) +if (NOT SHAREDLIBS AND STATICLIBS) + target_link_libraries(ftdi_eeprom ${LIBUSB_LIBRARIES}) endif () -install ( TARGETS ftdi_eeprom DESTINATION bin ) -install ( FILES example.conf DESTINATION ${CMAKE_INSTALL_DOCDIR} ) +install(TARGETS ftdi_eeprom DESTINATION bin) +install(FILES example.conf DESTINATION ${CMAKE_INSTALL_DOCDIR}) diff --git a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt index 4172d75..272b8f6 100644 --- a/ftdipp/CMakeLists.txt +++ b/ftdipp/CMakeLists.txt @@ -1,40 +1,40 @@ # Targets -set(cpp_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.cpp CACHE INTERNAL "List of cpp sources" ) -set(cpp_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.hpp CACHE INTERNAL "List of cpp headers" ) +set(cpp_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.cpp CACHE INTERNAL "List of cpp sources") +set(cpp_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.hpp CACHE INTERNAL "List of cpp headers") # Includes include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/src ) # Shared library -if ( SHAREDLIBS ) - add_library(ftdipp1 SHARED ${cpp_sources}) - math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases - set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3) - # Prevent clobbering each other during the build - set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) - # Dependencies - target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES}) - install(TARGETS ftdipp1 - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +if (SHAREDLIBS) + add_library(ftdipp1 SHARED ${cpp_sources}) + math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases + set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3) + # Prevent clobbering each other during the build + set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) + # Dependencies + target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES}) + install(TARGETS ftdipp1 + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif () # Static library -if ( STATICLIBS ) - add_library(ftdipp1-static STATIC ${cpp_sources}) - set_target_properties(ftdipp1-static PROPERTIES OUTPUT_NAME "ftdipp1") - set_target_properties(ftdipp1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) - target_link_libraries(ftdipp1-static ftdi1-static ${LIBUSB_LIBRARIES}) - install(TARGETS ftdipp1-static - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT staticlibs - ) -endif() +if (STATICLIBS) + add_library(ftdipp1-static STATIC ${cpp_sources}) + set_target_properties(ftdipp1-static PROPERTIES OUTPUT_NAME "ftdipp1") + set_target_properties(ftdipp1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) + target_link_libraries(ftdipp1-static ftdi1-static ${LIBUSB_LIBRARIES}) + install(TARGETS ftdipp1-static + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT staticlibs + ) +endif () install(FILES ${cpp_headers} DESTINATION include/${PROJECT_NAME} diff --git a/packages/CMakeLists.txt b/packages/CMakeLists.txt index 204bbe0..ea4a171 100644 --- a/packages/CMakeLists.txt +++ b/packages/CMakeLists.txt @@ -1,21 +1,21 @@ # Debian -if("${PACKAGE}" STREQUAL "Debian") +if ("${PACKAGE}" STREQUAL "Debian") - # Settings - set(REVISION 0) - set(CPACK_GENERATOR "DEB" PARENT_SCOPE) - set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-${REVISION} PARENT_SCOPE) + # Settings + set(REVISION 0) + set(CPACK_GENERATOR "DEB" PARENT_SCOPE) + set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-${REVISION} PARENT_SCOPE) - # Dependencies - set(CPACK_DEBIAN_PACKAGE_DEPENDS "libusb-1.0-0" PARENT_SCOPE) - set(DEBIAN_PACKAGE_BUILDS_DEPENDS "cmake, libusb2-dev" PARENT_SCOPE) + # Dependencies + set(CPACK_DEBIAN_PACKAGE_DEPENDS "libusb-1.0-0" PARENT_SCOPE) + set(DEBIAN_PACKAGE_BUILDS_DEPENDS "cmake, libusb2-dev" PARENT_SCOPE) - # Bundles - message("-- Installing udev rules to /etc/udev/rules.d") - install(FILES 99-libftdi.rules - DESTINATION /etc/udev/rules.d) + # Bundles + message("-- Installing udev rules to /etc/udev/rules.d") + install(FILES 99-libftdi.rules + DESTINATION /etc/udev/rules.d) -endif("${PACKAGE}" STREQUAL "Debian") +endif ("${PACKAGE}" STREQUAL "Debian") # General RPM rules -set(CPACK_RPM_PACKAGE_DEPENDS "libusb1" PARENT_SCOPE) +set(CPACK_RPM_PACKAGE_DEPENDS "libusb1" PARENT_SCOPE) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0708851..d496c3f 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,75 +1,75 @@ # workaround for cmake bug #0013449 -if ( NOT DEFINED CMAKE_FIND_ROOT_PATH OR NOT CMAKE_VERSION VERSION_LESS 3.0.0 ) - find_package ( SWIG REQUIRED ) +if (NOT DEFINED CMAKE_FIND_ROOT_PATH OR NOT CMAKE_VERSION VERSION_LESS 3.0.0) + find_package(SWIG REQUIRED) else () - find_program ( SWIG_EXECUTABLE NAMES swig2.0 swig ) - if ( SWIG_EXECUTABLE ) - set ( SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake ) - set ( SWIG_FOUND TRUE ) - endif () + find_program(SWIG_EXECUTABLE NAMES swig2.0 swig) + if (SWIG_EXECUTABLE) + set(SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake) + set(SWIG_FOUND TRUE) + endif () endif () -find_package ( PythonInterp REQUIRED ) -find_package ( PythonLibs REQUIRED ) +find_package(PythonInterp REQUIRED) +find_package(PythonLibs REQUIRED) -include ( UseSWIG ) -include_directories ( BEFORE ${PROJECT_SOURCE_DIR}/src ) -include_directories ( ${PYTHON_INCLUDE_DIRS} ) -link_directories ( ${CMAKE_CURRENT_BINARY_DIR}/../src ) +include(UseSWIG) +include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src) +include_directories(${PYTHON_INCLUDE_DIRS}) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../src) -if ( DOCUMENTATION ) - set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND}) - # manually add dependency for new cmake / swig versions - set_property(SOURCE ftdi1.i PROPERTY DEPENDS doc_i) -endif() -swig_add_library ( pyftdi1 LANGUAGE python SOURCES ftdi1.i ) -swig_link_libraries ( pyftdi1 ftdi1 ) +if (DOCUMENTATION) + set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND}) + # manually add dependency for new cmake / swig versions + set_property(SOURCE ftdi1.i PROPERTY DEPENDS doc_i) +endif () +swig_add_library(pyftdi1 LANGUAGE python SOURCES ftdi1.i) +swig_link_libraries(pyftdi1 ftdi1) -if ( LINK_PYTHON_LIBRARY ) - swig_link_libraries ( pyftdi1 ${PYTHON_LIBRARIES} ) -elseif( APPLE ) - set_target_properties ( pyftdi1 PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" ) +if (LINK_PYTHON_LIBRARY) + swig_link_libraries(pyftdi1 ${PYTHON_LIBRARIES}) +elseif (APPLE) + set_target_properties(pyftdi1 PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") endif () -set_target_properties ( pyftdi1 PROPERTIES NO_SONAME ON ) +set_target_properties(pyftdi1 PROPERTIES NO_SONAME ON) -execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib', vars={'platbase': '${CMAKE_INSTALL_PREFIX}'} ) )" - OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE ) +execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib', vars={'platbase': '${CMAKE_INSTALL_PREFIX}'} ) )" + OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE) -get_filename_component ( _ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE ) -file ( RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH} ) +get_filename_component(_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) +file(RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) -set ( PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH} ) +set(PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH}) -install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/ftdi1.py DESTINATION ${PYTHON_MODULE_PATH} ) -install ( TARGETS pyftdi1 LIBRARY DESTINATION ${PYTHON_MODULE_PATH} ) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftdi1.py DESTINATION ${PYTHON_MODULE_PATH}) +install(TARGETS pyftdi1 LIBRARY DESTINATION ${PYTHON_MODULE_PATH}) -if ( DOCUMENTATION ) - # Run doxygen to only generate the xml - add_custom_command ( OUTPUT ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml - COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/doc/Doxyfile.xml - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - COMMENT "Generating ftdi_8c.xml" - DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers} - ) +if (DOCUMENTATION) + # Run doxygen to only generate the xml + add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml + COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/doc/Doxyfile.xml + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + COMMENT "Generating ftdi_8c.xml" + DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers} + ) - # generate .i from doxygen .xml - add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n - ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml - ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i - COMMENT "Generating ftdi1_doc.i from ftdi_8c.xml" - DEPENDS ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml - ) - add_custom_target ( doc_i - COMMENT "Python API bindings documentation" - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i - ) - add_dependencies( pyftdi1 doc_i ) + # generate .i from doxygen .xml + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n + ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml + ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i + COMMENT "Generating ftdi1_doc.i from ftdi_8c.xml" + DEPENDS ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml + ) + add_custom_target(doc_i + COMMENT "Python API bindings documentation" + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i + ) + add_dependencies(pyftdi1 doc_i) -endif ( DOCUMENTATION ) +endif (DOCUMENTATION) -set ( LIBFTDI_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULE_PATH} ) -set ( LIBFTDI_PYTHON_MODULE_PATH ${LIBFTDI_PYTHON_MODULE_PATH} PARENT_SCOPE ) # for ftdiconfig.cmake +set(LIBFTDI_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULE_PATH}) +set(LIBFTDI_PYTHON_MODULE_PATH ${LIBFTDI_PYTHON_MODULE_PATH} PARENT_SCOPE) # for ftdiconfig.cmake -add_subdirectory ( examples ) +add_subdirectory(examples) diff --git a/python/examples/CMakeLists.txt b/python/examples/CMakeLists.txt index 232595f..904fd4e 100644 --- a/python/examples/CMakeLists.txt +++ b/python/examples/CMakeLists.txt @@ -1,4 +1,4 @@ -install ( FILES simple.py complete.py cbus.py - DESTINATION share/libftdi/examples - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ -) + install(FILES simple.py complete.py cbus.py + DESTINATION share/libftdi/examples + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae51242..7e81bea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,79 +1,79 @@ # Includes include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ) # Version information set(SNAPSHOT_VERSION "unknown") execute_process(COMMAND git describe - OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT - RESULT_VARIABLE GIT_DESCRIBE_RESULT - OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT + RESULT_VARIABLE GIT_DESCRIBE_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE ) -if(${GIT_DESCRIBE_RESULT} STREQUAL 0) - set(SNAPSHOT_VERSION ${GIT_DESCRIBE_OUTPUT}) +if (${GIT_DESCRIBE_RESULT} STREQUAL 0) + set(SNAPSHOT_VERSION ${GIT_DESCRIBE_OUTPUT}) endif () message(STATUS "Detected git snapshot version: ${SNAPSHOT_VERSION}") configure_file(ftdi_version_i.h.in "${CMAKE_CURRENT_BINARY_DIR}/ftdi_version_i.h" @ONLY) -if(MSVC) - # Disable some overly-verbose warnings activated by -Wall +if (MSVC) + # Disable some overly-verbose warnings activated by -Wall - # '': function not inlined - add_compile_options(/wd4710) + # '': function not inlined + add_compile_options(/wd4710) - # function '' selected for automatic inline expansion - add_compile_options(/wd4711) + # function '' selected for automatic inline expansion + add_compile_options(/wd4711) - # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified - add_compile_options(/wd5045) + # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified + add_compile_options(/wd5045) - # '': '4' bytes padding added after data member '' - add_compile_options(/wd4820) + # '': '4' bytes padding added after data member '' + add_compile_options(/wd4820) - # conversion from '' to '', possible loss of data - add_compile_options(/wd4242 /wd4244 /wd4267) + # conversion from '' to '', possible loss of data + add_compile_options(/wd4242 /wd4244 /wd4267) - # Disable warning on unsafe string functions - add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + # Disable warning on unsafe string functions + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) - if(MSVC_VERSION GREATER_EQUAL 1913) - # Disable warnings from system headers - add_compile_options(/external:anglebrackets /external:W0) - endif() -endif() + if (MSVC_VERSION GREATER_EQUAL 1913) + # Disable warnings from system headers + add_compile_options(/external:anglebrackets /external:W0) + endif () +endif () # Targets -set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" ) -set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" ) +set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources") +set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers") # Shared library -if ( SHAREDLIBS ) - add_library(ftdi1 SHARED ${c_sources}) - math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases - set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2) - # Prevent clobbering each other during the build - set_target_properties(ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) - target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES}) - install(TARGETS ftdi1 - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +if (SHAREDLIBS) + add_library(ftdi1 SHARED ${c_sources}) + math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatibility with previous releases + set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2) + # Prevent clobbering each other during the build + set_target_properties(ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) + target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES}) + install(TARGETS ftdi1 + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif () # Static library -if ( STATICLIBS ) - add_library(ftdi1-static STATIC ${c_sources}) - target_link_libraries(ftdi1-static ${LIBUSB_LIBRARIES}) - set_target_properties(ftdi1-static PROPERTIES OUTPUT_NAME "ftdi1") - set_target_properties(ftdi1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) - install(TARGETS ftdi1-static - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT staticlibs - ) -endif() +if (STATICLIBS) + add_library(ftdi1-static STATIC ${c_sources}) + target_link_libraries(ftdi1-static ${LIBUSB_LIBRARIES}) + set_target_properties(ftdi1-static PROPERTIES OUTPUT_NAME "ftdi1") + set_target_properties(ftdi1-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) + install(TARGETS ftdi1-static + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT staticlibs + ) +endif () install(FILES ${c_headers} DESTINATION include/${PROJECT_NAME} -- 1.7.1 From f554d7cd432d3056b1ca62bf09cc4003bf307912 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Thu, 12 Jun 2025 23:18:55 +0200 Subject: [PATCH 14/16] Ignore JetBrains IDE files --- .gitignore | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index 9f1af71..4d57cba 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,6 @@ compile_commands.json # VSCode .vscode + +# CLion +.idea/ -- 1.7.1 From eaf42c00bfab5d6bbd8106b11a697ff4f2d7659f Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Fri, 13 Jun 2025 09:59:39 +0200 Subject: [PATCH 15/16] ftdi_eeprom: fix static build Link to ftdi1-static if only STATICLIBS is enabled. --- ftdi_eeprom/CMakeLists.txt | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/ftdi_eeprom/CMakeLists.txt b/ftdi_eeprom/CMakeLists.txt index 3958b66..38147b5 100644 --- a/ftdi_eeprom/CMakeLists.txt +++ b/ftdi_eeprom/CMakeLists.txt @@ -36,7 +36,12 @@ configure_file( ) add_executable(ftdi_eeprom main.c) -target_link_libraries(ftdi_eeprom ftdi1 ${CONFUSE_LIBRARIES}) +if (NOT SHAREDLIBS AND STATICLIBS) + target_link_libraries(ftdi_eeprom ftdi1-static) +else() + target_link_libraries(ftdi_eeprom ftdi1) +endif () +target_link_libraries(ftdi_eeprom ${CONFUSE_LIBRARIES}) if (LIBINTL_FOUND) target_link_libraries(ftdi_eeprom ${LIBINTL_LIBRARIES}) endif () -- 1.7.1 From f7ed9dd371f9387ed5b715a4f316eea9f85de48d Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Mon, 23 Jun 2025 14:44:13 +0200 Subject: [PATCH 16/16] python/CMakeLists.txt: rework Python development files detection Both the FindPythonInterp and FindPythonLibs modules were removed. Use find_package(Python3 COMPONENTS Interpreter Development) to find both the interpreter and the library. The old modules have been deprecated since CMake 3.12. Resolves the following warning: CMake Warning (dev) at python/CMakeLists.txt:11 (find_package): Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules are removed. Run "cmake --help-policy CMP0148" for policy details. Use the cmake_policy command to set the policy and suppress this warning. --- python/CMakeLists.txt | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index d496c3f..d312fae 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -8,12 +8,11 @@ else () set(SWIG_FOUND TRUE) endif () endif () -find_package(PythonInterp REQUIRED) -find_package(PythonLibs REQUIRED) +find_package(Python3 COMPONENTS Interpreter Development) include(UseSWIG) include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src) -include_directories(${PYTHON_INCLUDE_DIRS}) +include_directories(${Python3_INCLUDE_DIRS}) link_directories(${CMAKE_CURRENT_BINARY_DIR}/../src) if (DOCUMENTATION) @@ -32,7 +31,7 @@ endif () set_target_properties(pyftdi1 PROPERTIES NO_SONAME ON) -execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib', vars={'platbase': '${CMAKE_INSTALL_PREFIX}'} ) )" +execute_process(COMMAND ${Python3_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib', vars={'platbase': '${CMAKE_INSTALL_PREFIX}'} ) )" OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -55,7 +54,7 @@ if (DOCUMENTATION) # generate .i from doxygen .xml add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i COMMENT "Generating ftdi1_doc.i from ftdi_8c.xml" -- 1.7.1