forked from alicevision/vcpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vcpkg] Add
vcpkg_install_copyright()
portfile function (microsoft#…
…25239) * [vcpkg tool] Add vcpkg_install_copyright * Make sure FILE_LIST is provided * relative to ${SOURCE_PATH} * Add documentation * Add to table of contents * Relative paths was a bad idea. * Tell users to use the correct way Co-authored-by: Billy O'Neal <bion@microsoft.com> * Fix docs * Add parameter COMMENT * Rename to vcpkg_concat_copyright * Fix escape * Revert "Fix escape" This reverts commit 53f1636. * Revert "Rename to vcpkg_concat_copyright" This reverts commit 6ce9152. * Fix escape * Add support for single copyright file * Update docs * Make comment less confusing * [ci skip] Billy CR * [ci skip] Format * Remove explicit checks for STREQUAL "" * Add error msg if file doesn't exist Co-authored-by: Billy O'Neal <bion@microsoft.com>
- Loading branch information
Showing
6 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# vcpkg_install_copyright | ||
|
||
The latest version of this document lives in the [vcpkg repo](https://github.com/Microsoft/vcpkg/blob/master/docs/maintainers/vcpkg_install_copyright.md). | ||
|
||
Merges multiple copyright files into a single file and install it. | ||
Installs a single copyright file. | ||
|
||
## Usage | ||
|
||
```cmake | ||
vcpkg_install_copyright(FILE_LIST <file1> <file2>... [COMMENT]) | ||
``` | ||
|
||
## Parameters | ||
|
||
### FILE_LIST | ||
Specifies a list of license files with absolute paths. You must provide at least one file. | ||
|
||
### COMMENT | ||
This optional parameter adds a comment before at the top of the file. | ||
|
||
## Notes | ||
|
||
This function creates a file called `copyright` inside `${CURRENT_PACKAGES_DIR}/share/${PORT}` | ||
|
||
If more than one file is provided, this function concatenates the contents of multiple copyright files to a single file. | ||
|
||
The resulting `copyright` file looks similar to this: | ||
|
||
``` | ||
LICENSE-LGPL2.txt: | ||
Lorem ipsum dolor... | ||
LICENSE-MIT.txt: | ||
Lorem ipsum dolor sit amet... | ||
``` | ||
|
||
Or with `COMMENT`: | ||
|
||
``` | ||
A meaningful comment | ||
LICENSE-LGPL2.txt: | ||
Lorem ipsum dolor... | ||
LICENSE-MIT.txt: | ||
Lorem ipsum dolor sit amet... | ||
``` | ||
|
||
## Examples | ||
|
||
```cmake | ||
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE/license.md" "${SOURCE_PATH}/LICENSE/license_gpl.md" COMMENT "This is a comment") | ||
``` | ||
|
||
You can also collect the required files using a `GLOB` pattern: | ||
|
||
```cmake | ||
file(GLOB LICENSE_FILES "${SOURCE_PATH}/LICENSES/*") | ||
vcpkg_install_copyright(FILE_LIST ${LICENSE_FILES}) | ||
``` | ||
|
||
## Source | ||
|
||
[vcpkg_install_copyright.md](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_install_copyright.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function(vcpkg_install_copyright) | ||
cmake_parse_arguments(PARSE_ARGV 0 arg "" "COMMENT" "FILE_LIST") | ||
|
||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
if(NOT DEFINED arg_FILE_LIST) | ||
message(FATAL_ERROR "FILE_LIST must be specified") | ||
endif() | ||
|
||
list(LENGTH arg_FILE_LIST FILE_LIST_LENGTH) | ||
set(out_string "") | ||
|
||
if(FILE_LIST_LENGTH LESS_EQUAL 0) | ||
message(FATAL_ERROR "FILE_LIST must contain at least one file") | ||
elseif(FILE_LIST_LENGTH EQUAL 1) | ||
if(arg_COMMENT) | ||
file(READ "${arg_FILE_LIST}" out_string) | ||
else() | ||
file(INSTALL "${arg_FILE_LIST}" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) | ||
return() | ||
endif() | ||
else() | ||
foreach(file_item IN LISTS arg_FILE_LIST) | ||
if(NOT EXISTS "${file_item}") | ||
message(FATAL_ERROR "\n${CMAKE_CURRENT_FUNCTION} was passed a non-existing path: ${file_item}\n") | ||
endif() | ||
|
||
get_filename_component(file_name "${file_item}" NAME) | ||
file(READ "${file_item}" file_contents) | ||
|
||
string(APPEND out_string "${file_name}:\n\n${file_contents}\n\n") | ||
endforeach() | ||
endif() | ||
|
||
if(arg_COMMENT) | ||
string(PREPEND out_string "${arg_COMMENT}\n\n") | ||
endif() | ||
|
||
file(WRITE "${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright" "${out_string}") | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters