Skip to content

Commit

Permalink
only print delimiter when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLartians committed Jan 6, 2021
1 parent 94c221d commit 0689ed4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ function(write_license_disclaimer FILE_NAME PACKAGES)
file(WRITE ${FILE_NAME} "")
set(PRINT_DELIMITER OFF)
foreach(package ${PACKAGES})
if(PRINT_DELIMITER)
file(APPEND ${FILE_NAME} "\n-----\n")
endif()
file(GLOB licenses "${${package}_SOURCE_DIR}/LICENSE*" "${${package}_SOURCE_DIR}/license*")
list(LENGTH licenses LICENSE_COUNT)
if(LICENSE_COUNT GREATER_EQUAL 1)
if(PRINT_DELIMITER)
file(APPEND ${FILE_NAME} "\n-----\n")
endif()

list(GET licenses 0 license)
file(READ ${license} license_TEXT)
file(APPEND ${FILE_NAME}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# CPMlicenses.cmake
# CPMLicenses.cmake

A license collector for your projects using CPM.cmake.

## About

Many open-source projects require adding a disclaimer to your binary reproducing the dependencies license. Finding and updating the disclaimer for all dependencies can be a tedious task. Luckily, if you've used [CPM.cmake](https://github.com/TheLartians/CPM.cmake) to add the dependencies this process can be automated.

CPMlicenses.cmake will automatically scan all source directories of your CPM.cmake dependencies and find any file that begins with `LICENCE` or `LICENSE`, appending the contents to an output file that you can use as a license disclaimer.
CPMlicenses.cmake will automatically scan all source directories of your CPM.cmake dependencies and find any file that begins with `LICENCE` or `LICENSE`, appending the contents to an output file that you can use as a license disclaimer. If no license has been found for a package, a warning will be emitted.

## Usage

Expand All @@ -15,12 +15,12 @@ Use [CPM.cmake](https://github.com/TheLartians/CPM.cmake) to add CPMLicenses.cma
```cmake
CPMAddPackage(
NAME CPMLicenses.cmake
GITHUB_REPOSITORY TheLartians/CPMlicenses.cmake
VERSION 0.0.1
GITHUB_REPOSITORY TheLartians/CPMLicenses.cmake
VERSION 0.0.2
)
```

After all additional dependencies have been added, create the target by calling `cpm_licenses_create_disclaimer_target(<target name> <output file> <packages>)`. Afterwards, simply build the CMake target with the specified name to create the file containing the licenses.
After all additional dependencies have been added, create the target by calling `cpm_licenses_create_disclaimer_target(<target name> <output file> <packages>)`. Afterwards, simply build the CMake target with the specified name to create the file containing the licenses.

For example, with the configuration

Expand Down

0 comments on commit 0689ed4

Please sign in to comment.