Skip to content

License check - #1289

Merged
dNechita merged 11 commits into
analogdevicesinc:mainfrom
rgetz:rgetz-license-check
Apr 9, 2026
Merged

dNechita merged 11 commits into
analogdevicesinc:mainfrom
rgetz:rgetz-license-check

Conversation

@rgetz

@rgetz rgetz commented May 18, 2025 •

Copy link
Copy Markdown
Contributor
make: add SPDX license audit script for compliance checking

This adds a spdx_check_target() CMake function to validate that all source
files in a target (and its linked static/shared libraries) include a valid
SPDX-License-Identifier tag and hides it behind a new "-DLICENCE_CHECK"
cmake option.

Key features:
 - Recursively gathers all sources linked into a target, even from
   subdirectories or helper libraries.
 - Differentiates between known SPDX-licensed files and those missing tags.
 - Handles relative paths for better readability.
 - Filters out generated or build-directory files (e.g., config.h, yacc/lex
   output).
 - Summarizes licenses used and flags untagged files for manual review.
 - Prints out external libraries which are linked (which needs to be
   checked by hand).

This is especially useful in projects with mixed-license source files,
where build options can change the resulting binaries license. This will
ensure license compliance, auditability, and downstream clarity.

Helps improve:
 - Legal review processes
 - Contributor workflow (by enforcing license hygiene)
 - Automation and SPDX compatibility

Signed-off-by: Robin Getz <rgetz503@gmail.com>

Can now print out things like this:

-- === License Check for : iio ==========
--     MIT: attr.c, backend.c, block.c, buffer.c, channel.c, context.c, device.c, events.c, library.c, mask.c, scan.c, sort.c, stream.c, task.c, utilities.c, xml.c
--     LGPL-2.1-or-later: usb.c, local.c, local-dmabuf.c, local-mmap.c, network.c, network-unix.c, dns_sd.c, dns_sd_avahi.c, lock.c, iiod-client.c, iiod-responder.c
--     Missing SPDX: deps/libini/libini.c
--     External libraries: /usr/lib/x86_64-linux-gnu/libusb-1.0.so, /usr/lib/x86_64-linux-gnu/librt.so, /usr/lib/x86_64-linux-gnu/libatomic.so.1, /usr/lib/x86_64-linux-gnu/libzstd.so, /usr/lib/x86_64-linux-gnu/libavahi-common.so, /usr/lib/x86_64-linux-gnu/libavahi-client.so, /usr/lib/x86_64-linux-gnu/libxml2.so, /usr/lib/x86_64-linux-gnu/libpthread.so

which can get confusing for the utils - but it's clear that they are still GPL (not MIT, or LGPL).

--     GPL-2.0-or-later: utils/iio_info.c, utils/iio_common.c, utils/gen_code.c
--     MIT: attr.c, backend.c, block.c, buffer.c, channel.c, context.c, device.c, events.c, library.c, mask.c, scan.c, sort.c, stream.c, task.c, utilities.c, xml.c
--     LGPL-2.1-or-later: usb.c, local.c, local-dmabuf.c, local-mmap.c, network.c, network-unix.c, dns_sd.c, dns_sd_avahi.c, lock.c, iiod-client.c, iiod-responder.c
--     Missing SPDX: deps/libini/libini.c

which will adapt based on cmake options used.

pcercuei/libini#5 is in process to fix the Missing SPDX: deps/libini/libini.c issue.

@rgetz rgetz changed the title Rgetz license check License check May 18, 2025
@rgetz
rgetz force-pushed the rgetz-license-check branch from 5a927ac to aeddfc3 Compare May 18, 2025 00:29
@rgetz

rgetz commented May 18, 2025

Copy link
Copy Markdown
Contributor Author

was thinking about this - at this time - this only looks at source files (.c) not header files (.h) - should likely add for the same reason...

Will see if I can update.

@rgetz
rgetz force-pushed the rgetz-license-check branch from aeddfc3 to c886795 Compare May 26, 2025 20:41
@rgetz

rgetz commented May 26, 2025

Copy link
Copy Markdown
Contributor Author
cmake ../ -DLICENSE_CHECK=ON

generates a list that looks like:

-- === License Check for : iio ==========
--     MIT: attr.c, backend.c, block.c, buffer.c, channel.c, context.c, device.c, events.c, library.c, mask.c, scan.c, sort.c, stream.c, task.c, utilities.c, xml.c, iiod-responder.h, include/iio/iio.h, include/iio/iio-backend.h, include/iio/iio-lock.h, iio-private.h, include/iio/iio-debug.h, sort.h, attr.h
--     LGPL-2.1-or-later: usb.c, local.c, local-dmabuf.c, local-mmap.c, network.c, network-unix.c, dns_sd.c, dns_sd_avahi.c, lock.c, iiod-client.c, iiod-responder.c, dynamic.h, network.h, include/iio/iiod-client.h, local.h, dns_sd.h
--     Missing SPDX: deps/libini/libini.c, deps/libini/ini.h
--     External libraries: /usr/lib/x86_64-linux-gnu/libusb-1.0.so, /usr/lib/x86_64-linux-gnu/librt.so, /usr/lib/x86_64-linux-gnu/libatomic.so.1, /usr/lib/x86_64-linux-gnu/libzstd.so, /usr/lib/x86_64-linux-gnu/libavahi-common.so, /usr/lib/x86_64-linux-gnu/libavahi-client.so, /usr/lib/x86_64-linux-gnu/libxml2.so, /usr/lib/x86_64-linux-gnu/libpthread.so

-- === License Check for iiod: iiod ==========
--     LGPL-2.1-or-later: iiod/iiod.c, iiod/interpreter.c, iiod/rw.c, iiod/thread-pool.c, iiod/ops.c, iiod/usbd.c, iiod/serial.c, iiod/network.c, usb.c, local.c, local-dmabuf.c, local-mmap.c, network.c, network-unix.c, dns_sd.c, dns_sd_avahi.c, lock.c, iiod-client.c, iiod-responder.c, dynamic.h, network.h, include/iio/iiod-client.h, local.h, dns_sd.h, iiod/debug.h, iiod/thread-pool.h
--     MIT: iiod/responder.c, attr.c, backend.c, block.c, buffer.c, channel.c, context.c, device.c, events.c, library.c, mask.c, scan.c, sort.c, stream.c, task.c, utilities.c, xml.c, iiod-responder.h, include/iio/iio.h, include/iio/iio-backend.h, include/iio/iio-lock.h, iio-private.h, include/iio/iio-debug.h, sort.h, attr.h, iiod/ops.h
--     LGPL-v2-or-later: iiod/dns-sd.c, iiod/dns-sd.h
--     BSD-3-Clause: iiod/queue.h
--     Missing SPDX: deps/libini/libini.c, deps/libini/ini.h
--     External libraries: /usr/lib/x86_64-linux-gnu/libpthread.so, /usr/lib/x86_64-linux-gnu/libavahi-common.so, /usr/lib/x86_64-linux-gnu/libavahi-client.so, /usr/lib/x86_64-linux-gnu/libaio.so, /usr/lib/x86_64-linux-gnu/libzstd.so

I know this works on gcc, but have not tested on clang, or on MSVC yet. Feedback welcome.

@rgetz
rgetz force-pushed the rgetz-license-check branch from c886795 to edccd54 Compare May 26, 2025 20:59
@dNechita

Copy link
Copy Markdown
Collaborator

I know this works on gcc, but have not tested on clang, or on MSVC yet. Feedback welcome.

On Windows it doesn't work but it can be easily fixed by including Utilities.cmake at the top of the main cmake file.
include(cmake/Utilities.cmake)

Error was:

CMake Error at CMakeLists.txt:765 (spdx_check_all_targets):
  Unknown CMake command "spdx_check_all_targets".

@rgetz

rgetz commented May 29, 2025

Copy link
Copy Markdown
Contributor Author

Thanks - will fix that shortly.

@rgetz

rgetz commented May 29, 2025

Copy link
Copy Markdown
Contributor Author

Any other feedback? The list is pretty dense - it might use an empty line between targets?

@rgetz
rgetz force-pushed the rgetz-license-check branch from edccd54 to a598ee7 Compare June 1, 2025 01:02
@rgetz

rgetz commented Jun 1, 2025

Copy link
Copy Markdown
Contributor Author

Missing SPDX: deps/libini/libini.c, deps/libini/ini.h

I don't know if you want me to fix that locally as part of this patchset? or wait for @pcercuei to have a look at pcercuei/libini#5

I think my preference would be to fix things, and then turn missing SPDX lines into a error - and then turn this on in CI, to make sure that we catch things in the future, but I'm open to opinions.

@rgetz
rgetz force-pushed the rgetz-license-check branch from a598ee7 to b1ffd56 Compare June 1, 2025 17:37
@rgetz
rgetz requested review from AAndrisa and SRaus as code owners June 1, 2025 17:37
@dNechita

dNechita commented Jun 2, 2025

Copy link
Copy Markdown
Collaborator

Missing SPDX: deps/libini/libini.c, deps/libini/ini.h

I don't know if you want me to fix that locally as part of this patchset? or wait for @pcercuei to have a look at pcercuei/libini#5

I think my preference would be to fix things, and then turn missing SPDX lines into a error - and then turn this on in CI, to make sure that we catch things in the future, but I'm open to opinions.

From a technical point of view, you can't touch the files from deps as you would for a regular source file. The original repository would need to be updated first and then make libiio repo point to the updated libini repo.
This is a snipped from the readme of the deps dir:

Commits of the Libiio repository must *not* touch any file or directory
present in the deps/ folder.

@pcercuei

pcercuei commented Jun 2, 2025

Copy link
Copy Markdown
Contributor

I merged the libini PR with the SPDX headers btw.

Comment thread CMakeLists.txt Resolved
Comment thread README_BUILD.md Resolved
@rgetz

rgetz commented Jun 6, 2025

Copy link
Copy Markdown
Contributor Author

From a technical point of view, you can't touch the files from deps as you would for a regular source file.

@dNechita - do you want to take care of this then?

@rgetz
rgetz force-pushed the rgetz-license-check branch 7 times, most recently from 20485c1 to d43c2dc Compare June 9, 2025 00:23
@rgetz
rgetz force-pushed the rgetz-license-check branch 11 times, most recently from 3ef4ea5 to 0a93bf4 Compare February 23, 2026 01:31
This adds a spdx_check_target() CMake function to validate that all source
files in a target (and its linked static/shared libraries) include a valid
SPDX-License-Identifier tag and hides it behind a new "-DLICENSE_CHECK"
cmake option.

Key features:
 - Recursively gathers all sources linked into a target, even from
   subdirectories or helper libraries.
 - uses preprocessor to find header files, based on current settings
 - Differentiates between known SPDX-licensed files and those missing tags.
 - Handles relative paths for better readability.
 - Filters out generated or build-directory files (e.g., config.h, yacc/lex
   output).
 - Summarizes licenses used and flags untagged files for manual review.
 - Prints out external libraries which are linked (which needs to be
   checked by hand).

This is especially useful in projects with mixed-license source files,
where build options can change the resulting binaries license. This will
ensure license compliance, auditability, and downstream clarity.

Helps improve:
 - Legal review processes
 - Contributor workflow (by enforcing license hygiene)
 - Automation and SPDX compatibility

Signed-off-by: Robin Getz <rgetz503@gmail.com>
- Clarify that libiio source includes multiple open-source licenses (MIT, GPL, LGPL)
- Explain that resulting binary license depends on build configuration and linked external libraries
- Recommend using -DLICENSE_CHECK=ON to verify license compliance
- Note that this header file is MIT-licensed but overall project license may differ

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Signed-off-by: Robin Getz <rgetz503@gmail.com>
in the iio_common_config internal statically linked library - ensure
that POSIX_C_SOURCE is set, like the rest of the entire library.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Signed-off-by: Robin Getz <rgetz503@gmail.com>
@rgetz
rgetz force-pushed the rgetz-license-check branch from 0a93bf4 to a7ee123 Compare February 23, 2026 02:04
@rgetz

rgetz commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

@dNechita : can you poke the bsd build/workflow? I would rather keep all the debug/messages turned on, while checking new targets before I remove them....

@dNechita

Copy link
Copy Markdown
Collaborator

@dNechita : can you poke the bsd build/workflow? I would rather keep all the debug/messages turned on, while checking new targets before I remove them....

Sure. Done.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
@rgetz

rgetz commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

@dNechita - it wasn't turned on for netbsd - so it built without...

can you try again (thanks).

@dNechita

Copy link
Copy Markdown
Collaborator

@dNechita - it wasn't turned on for netbsd - so it built without...

can you try again (thanks).

done

@rgetz

rgetz commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@dNechita - it looks like everything works - did you want me to leave it on in CI (to make sure it continues to work?)

@dNechita

Copy link
Copy Markdown
Collaborator

@dNechita - it looks like everything works - did you want me to leave it on in CI (to make sure it continues to work?)

Yes, keep it on in the CI, please.

@dNechita dNechita left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@dNechita
dNechita merged commit 09fc51b into analogdevicesinc:main Apr 9, 2026
30 checks passed
@rgetz

rgetz commented Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

@dNechita - sorry - there were a bunch of noisy debug things in there - that shouldn't have been merged. I will make a new PR with those cleaned up.

@dNechita

Copy link
Copy Markdown
Collaborator

@dNechita - sorry - there were a bunch of noisy debug things in there - that shouldn't have been merged. I will make a new PR with those cleaned up.

I should have gave another look before merging. I will wait for your PR.

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.

3 participants