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

Library Approach for LIBSTLINK #1437

Draft
wants to merge 10 commits into
base: testing
Choose a base branch
from

Conversation

a-michelis
Copy link

This Pull Request is purely for overview purposes.

This PR attempts to give STLink project a proper library approach, to enable users incorporate libstlink into their projects.

Main changes (in a nutshell)

  • The project now uses libusb-cmake project as its libusb provider, which in turn allows for custom-built libusb, tailored to each system's needs.
  • All included headers have been placed into appropriate stlink sup-folders that are included into the project as system includes, to allow for system-like includes. This change required the change of all inclusions in the project to change from #include "%HEADER%.h" to #include <stlink/%HEADER%.h>
  • Several headers have exposed functionality which could be used by custom software, using extern "C" blocks.

Much needed additions that are missing

  • Changing the logging infrastructure to allow programmatically managed logging, instead of STDOUT logs.
  • Help to accommodate the appropriate cmake modifications for other BSD/*NIX based systems, as well as verify/implement a proper handling of pre-installed libusb.
  • Exhaustive testing
  • Documentation of the exported functions (and of course evaluate whether the overall exposure is excessive or too limited).

A.M.

a-michelis and others added 7 commits October 21, 2024 14:58
Allows download build and include libraries for not-found libusb libraries on *nix and windows, using `libusb-cmake` repo
- searching for both `usb-1.0` or `libusb-1.0` on windows
- Removed code-independed flag from libusb building
- set the header path to the main generated `include` dir, so the header will remain prefixed with `libusb-1.0/` instead of directly accessed
- fixed libusb dll path typo
- marked `LIBUSB_INCLUDE_DIR` and `LIBUSB_LIBRARY` as advanced, upon manual build and inclusion.
- Moved all header files to appropriate subfolders to be context-isolated
- Used `target_include_directories` instead of `include_directories` to better manage which library connects to where, and make this project include-able as a sub-project to bigger projects
- Made all `#include` statements system-level and correctly prefixed
@Nightwalker-87
Copy link
Member

There are a few header dependencies that have not been converted to the new scheme. Thus, as it appears, this results in compilation errors. However I believe this can be easily fixed. I'll continue reviewing afterwards. Yet there are quite a few attempts and improvements I consider very useful.

@Nightwalker-87
Copy link
Member

I'd prefer to keep source and header files together in the same directory respectively, unless there are superior header files without a matching source file, but this should be rather a stylistic issue than a technical one...

@a-michelis
Copy link
Author

a-michelis commented Oct 22, 2024

I'd prefer to keep source and header files together in the same directory respectively, unless there are superior header files without a matching source file, but this should be rather a stylistic issue than a technical one...

I tend to divide the big projects into separate, smaller, target-centric sub-projects, included into the root CMakeLists.txt via add_subdirectory(${PROJECT_SOURCE_DIR}/src/target_name). This usually helps with projects like stlink that generate a toolset rather than one entity -allows for separation of concerns and enables two developers work in two different tools at the same time while avoiding conflicts.

Additionally, I usually separate headers and source files (despite being harder to manage) because it makes it easier to prefix different versions differently if ever needed, or avoid name conflicts, like with Windows and existing libusb.h.
AFAIK, there is no mechanism in CMAKE that allows for "virtual prefixing" of headers, which in turn makes using <stlink/header.h> rather than "header.h" in our sources and headers impossible.

That said, the project's structure is already in place and I'm in no position to enforce such changes, unless they're wanted -in which case I can pay closer attention on what goes where, how and why. :)


Seems like separating sources and headers makes it harder for static analyzers such as cppcheck to properly analyze the project, which is also something to consider in my approach.

@a-michelis
Copy link
Author

Fixing the non-prefixed usb.h made both workflows succeed - i shall remove my branch from the workflows, tho, since it will mess up the main project.

That said, I also added windows (MSVC) on the workflow and that passed as well!

@Nightwalker-87
Copy link
Member

Fixing the non-prefixed usb.h made both workflows succeed - i shall remove my branch from the workflows, tho, since it will mess up the main project.

That said, I also added windows (MSVC) on the workflow and that passed as well!

No, it won't mess up the project in any kind, as long as the merge of a test-failing PR does not take place. Indeed it is even better to have them here to detect possible issues before merging into the testing branch.

@Nightwalker-87
Copy link
Member

Further I've converted this PR into a draft as long as proposed changes are still in discussion.
Remember: Haste makes waste - we are not in a rush. Approaches and ideas should be well considered by taking into account relevant aspects. This does not imply that there is no view to improvements at all.

@Nightwalker-87
Copy link
Member

Any update here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

2 participants