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

[vcpkg] Add vcpkg_install_copyright() portfile function #25239

Merged
merged 29 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4fe6358
[vcpkg tool] Add vcpkg_install_copyright
Thomas1664 Jun 14, 2022
f14e4b1
Make sure FILE_LIST is provided
Thomas1664 Jun 14, 2022
f7ea603
relative to ${SOURCE_PATH}
Thomas1664 Jun 21, 2022
4788f6d
Add documentation
Thomas1664 Jun 21, 2022
121c887
Add to table of contents
Thomas1664 Jun 21, 2022
d431c26
Relative paths was a bad idea.
Thomas1664 Jun 22, 2022
752c91b
Tell users to use the correct way
Thomas1664 Jun 22, 2022
fecaf1c
Fix docs
Thomas1664 Jun 22, 2022
72ff376
Add parameter COMMENT
Thomas1664 Jun 23, 2022
f2fa4fa
Merge branch 'chartdir-ci' of https://github.com/Thomas1664/vcpkg int…
Thomas1664 Jun 23, 2022
838ead7
Merge branch 'master' of https://github.com/microsoft/vcpkg into inst…
Thomas1664 Jun 30, 2022
6ce9152
Rename to vcpkg_concat_copyright
Thomas1664 Jun 30, 2022
53f1636
Fix escape
Thomas1664 Jun 30, 2022
1bf3ee6
Revert "Fix escape"
Thomas1664 Jun 30, 2022
33fe92b
Revert "Rename to vcpkg_concat_copyright"
Thomas1664 Jun 30, 2022
357300f
Fix escape
Thomas1664 Jun 30, 2022
837844f
Add support for single copyright file
Thomas1664 Jun 30, 2022
b8306f4
Merge branch 'microsoft:master' into chartdir-ci
Thomas1664 Jul 1, 2022
0d16516
Update docs
Thomas1664 Jul 1, 2022
ba83327
Merge branch 'chartdir-ci' of https://github.com/Thomas1664/vcpkg int…
Thomas1664 Jul 1, 2022
1eebade
Merge branch 'microsoft:master' into chartdir-ci
Thomas1664 Jul 1, 2022
3794de7
Merge branch 'microsoft:master' into chartdir-ci
Thomas1664 Jul 4, 2022
1ad0b9c
Make comment less confusing
Thomas1664 Jul 6, 2022
fc02ce2
[ci skip] Billy CR
Thomas1664 Jul 6, 2022
034b8ec
[ci skip] Format
Thomas1664 Jul 6, 2022
925ffce
Remove explicit checks for STREQUAL ""
Thomas1664 Jul 7, 2022
5fab7d2
Merge branch 'master' of https://github.com/microsoft/vcpkg into inst…
Thomas1664 Jul 11, 2022
e2268b4
Add error msg if file doesn't exist
Thomas1664 Jul 11, 2022
0f78c1c
Merge branch 'microsoft:master' into chartdir-ci
Thomas1664 Jul 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/maintainers/maintainer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ This means that the user should see:
Examples:
* [`brotli`](https://github.com/microsoft/vcpkg/blob/4f0a640e4c5b74166b759a862d7527c930eff32e/ports/brotli/install.patch) creates the `unofficial-brotli` package, producing target `unofficial::brotli::brotli`.

### Install copyright file

Each port has to provide a file named `copyright` in the folder `${CURRENT_PACKAGES_DIR}/share/${PORT}`.

Many ports are using this code to install a copyright file:

```cmake
file(INSTALL "${SOURCE_PATH}LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
```

This is discouraged in favour of [`vcpkg_install_copyright()`](vcpkg_install_copyright.md). New ports should use `vcpkg_install_copyright()` instead. However, it is still valid for existing ports to use something like the code above. You may replace this with `vcpkg_install_copyright` but you don't have to.

`vcpkg_install_copyright` also includes the functionallity to handle multiple copyright files. See its [documentation](vcpkg_install_copyright.md) for more info.

## Features

### Do not use features to implement alternatives
Expand Down
1 change: 1 addition & 0 deletions docs/maintainers/portfile-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- [vcpkg\_host\_path\_list](vcpkg_host_path_list.md)
- [vcpkg\_install\_cmake](vcpkg_install_cmake.md) (deprecated, use [vcpkg\_cmake\_install](ports/vcpkg-cmake/vcpkg_cmake_install.md))
- [vcpkg\_install\_gn](vcpkg_install_gn.md) (deprecated, use [vcpkg\_gn\_install](ports/vcpkg-gn/vcpkg_gn_install.md))
- [vcpkg\_install\_copyright](vcpkg_install_copyright.md)
- [vcpkg\_install\_make](vcpkg_install_make.md)
- [vcpkg\_install\_meson](vcpkg_install_meson.md)
- [vcpkg\_install\_msbuild](vcpkg_install_msbuild.md)
Expand Down
69 changes: 69 additions & 0 deletions docs/maintainers/vcpkg_install_copyright.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# vcpkg_install_copyright
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved

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)
42 changes: 42 additions & 0 deletions scripts/cmake/vcpkg_install_copyright.cmake
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)
Thomas1664 marked this conversation as resolved.
Show resolved Hide resolved
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()
1 change: 1 addition & 0 deletions scripts/ports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ include("${SCRIPTS}/cmake/vcpkg_get_program_files_platform_bitness.cmake")
include("${SCRIPTS}/cmake/vcpkg_get_windows_sdk.cmake")
include("${SCRIPTS}/cmake/vcpkg_host_path_list.cmake")
include("${SCRIPTS}/cmake/vcpkg_install_cmake.cmake")
include("${SCRIPTS}/cmake/vcpkg_install_copyright.cmake")
include("${SCRIPTS}/cmake/vcpkg_install_gn.cmake")
include("${SCRIPTS}/cmake/vcpkg_install_make.cmake")
include("${SCRIPTS}/cmake/vcpkg_install_meson.cmake")
Expand Down
5 changes: 3 additions & 2 deletions scripts/templates/portfile.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ vcpkg_cmake_install()
#}
# vcpkg_cmake_config_fixup(CONFIG_PATH cmake TARGET_PATH share/@PORT@)

# Uncomment the line below if necessary to install the license file for the port to share/${PORT}/copyright
# file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
# Uncomment the line below if necessary to install the license file for the port
# as a file named `copyright` to the directory `${CURRENT_PACKAGES_DIR}/share/${PORT}`
# vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")