Skip to content

cmake: add native cross-platform build support - #6

Closed
csp256 wants to merge 2 commits into
hpax:masterfrom
csp256:cmake-support
Closed

csp256 wants to merge 2 commits into
hpax:masterfrom
csp256:cmake-support

Conversation

@csp256

@csp256 csp256 commented Sep 2, 2026

Copy link
Copy Markdown

Summary

  • add a native static/shared CMake library target for Windows, Linux, macOS,
    FreeBSD, and generic POSIX systems
  • mirror the autotools feature checks and generate config.h and
    baudrates.h without requiring a shell
  • support examples, CTest, installation, add_subdirectory(), and an installed
    libserialport::libserialport package target
  • make the timing test portable to MSVC and define explicit static-library API
    semantics for MSVC consumers
  • add Linux, macOS, and Windows CI matrices for static and shared builds,
    tests, examples, installation, and an installed-package consumer

Fixes #5.

Local validation

On Windows x64 with Visual Studio 2022/MSVC, both static and shared
configurations built the library and all six examples, passed the timing CTest,
installed successfully, and built an external consumer through
find_package(libserialport CONFIG).

The GitHub Actions matrix provides the corresponding Linux, macOS, and Windows
validation for this branch.

AI assistance disclosure

I used an AI coding assistant to adapt the existing build requirements and help
prepare the CI/package tests. I reviewed the changes and performed the Windows
validation described above.

Chris Parker added 2 commits September 1, 2026 18:59
Build and install static or shared libserialport targets on the supported platforms, mirror the autotools feature checks, generate baudrates without a shell, and provide examples, CTest, package exports, and Linux/macOS/Windows CI.

Signed-off-by: Chris Parker <chris.parker@polarissensor.com>
Signed-off-by: Chris Parker <chris.parker@polarissensor.com>
@csp256

csp256 commented Sep 2, 2026

Copy link
Copy Markdown
Author

Fork CI completed successfully for all six CMake configurations (Linux, macOS, and Windows; static and shared): https://github.com/csp256/libserialport/actions/runs/33573598516

@hpax

hpax commented Sep 2, 2026

Copy link
Copy Markdown
Owner

I'm going to hold off on this just a little bit, not because I think it's wrong (on the contrary), it just will conflict with some local pending work I have.

@hpax

hpax commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Hi, I have refactored and forward-ported your changes to the best of my ability (I'm not very familiar with cmake yet.) Would you be willing to see if the current master branch works as expected for you?

@hpax

hpax commented Sep 4, 2026

Copy link
Copy Markdown
Owner

I should have said: it is on the branch cmake-support at the moment.

@csp256

csp256 commented Sep 8, 2026

Copy link
Copy Markdown
Author

I'm finally back in the office after a long weekend. Will investigate today.

@csp256

csp256 commented Sep 8, 2026

Copy link
Copy Markdown
Author

It works on Mac, Ubuntu, and Windows. Made a few changes on https://github.com/csp256/libserialport/tree/cmake-support-followups

CI was only testing in Release, so the asserts were compiled out. I added that back in.

This revealed that in test_timing.c:45–46 the timing bounds are too tight, because the thread still has to be scheduled after a 1 second sleep. I didn't change this.

I made it omit CMAKE_BUILD_TYPE on Windows to suppress an expected warning.

Mac's handling of version metadata is different, so I changed it. This resulted in bumping CMake minimum to 3.17

I also install relocatable .pc metadata with static-link dependencies, with tests, so there is static/shared pkg-config support.

@csp256

csp256 commented Sep 9, 2026

Copy link
Copy Markdown
Author

Looks like this got pushed into main, so I'll close.

@csp256 csp256 closed this Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add native cross-platform CMake support

2 participants