Skip to content

Commit

Permalink
Install licenses from CMake to avoid duplicate workflow code
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Mar 16, 2024
1 parent 7e64157 commit 79d439c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 48 deletions.
79 changes: 31 additions & 48 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,23 @@ jobs:
-DVCPKG_TARGET_TRIPLET="$env:VCPKG_DEFAULT_TRIPLET"
-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
-DCMAKE_INSTALL_PREFIX="${{github.workspace}}/Install"
-DRMLUI_INSTALL_TARGETS_DIR=Bin-${{matrix.library_linkage}}/CMake
-DCMAKE_INSTALL_BINDIR=Bin-${{matrix.library_linkage}}/${{matrix.build_type}}
-DCMAKE_INSTALL_LIBDIR=Bin-${{matrix.library_linkage}}/${{matrix.build_type}}
-DCMAKE_INSTALL_INCLUDEDIR=Include
-DRMLUI_INSTALL_TARGETS_DIR=Bin-${{matrix.library_linkage}}/CMake
-DCMAKE_INSTALL_DATADIR="."
-DRMLUI_INSTALL_LICENSES_AND_BUILD_INFO=ON
-DRMLUI_ARCHITECTURE="${{ matrix.architecture }}"
-DRMLUI_COMMIT_DATE="$(git show $env:GITHUB_SHA --no-patch --format=%cd --date=iso)"
-DRMLUI_RUN_ID="$env:GITHUB_RUN_ID"
-DRMLUI_SHA="$env:GITHUB_SHA"
- name: Build
run: cmake --build Build --config ${{ matrix.build_type }}

- name: Install
run: cmake --install Build --config ${{ matrix.build_type }}

- name: Copy licenses
run: |-
cp LICENSE.txt Install/LICENSE.txt
$vcpkg_installed_dir="C:/vcpkg/installed/$env:VCPKG_DEFAULT_TRIPLET/"
$destination_dir="./Install/Dependencies/"
$copyright_files = Get-ChildItem -Path "$vcpkg_installed_dir/share" -Filter "copyright" -Recurse | Where-Object { $_.Directory.Name -notmatch '^vcpkg-' }
mkdir $destination_dir -Force | Out-Null
foreach ($file in $copyright_files) {
$name = $file.Directory.Name
Copy-Item -Path $file.FullName -Destination "$destination_dir/$name.txt"
}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -108,7 +102,12 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
-DCMAKE_INSTALL_PREFIX="${{github.workspace}}/Install"
-DCMAKE_INSTALL_BINDIR="Samples"
-DCMAKE_INSTALL_DATAROOTDIR="."
-DCMAKE_INSTALL_DATADIR="."
-DRMLUI_INSTALL_LICENSES_AND_BUILD_INFO=ON
-DRMLUI_ARCHITECTURE="${{ matrix.architecture }}"
-DRMLUI_COMMIT_DATE="$(git show $env:GITHUB_SHA --no-patch --format=%cd --date=iso)"
-DRMLUI_RUN_ID="$env:GITHUB_RUN_ID"
-DRMLUI_SHA="$env:GITHUB_SHA"
- name: Build
run: cmake --build Build --config Release
Expand All @@ -125,39 +124,10 @@ jobs:
cp changelog.md Install/
cp Samples/readme.md Install/Samples/
- name: Write build info
- name: Copy extra license files
run: |-
$rmlui_version=""
if ("$env:GITHUB_REF" -like "refs/tags/*") {
$rmlui_version=" $env:GITHUB_REF" -replace "refs/tags/", ""
}
$date=git show $env:GITHUB_SHA --no-patch --format=%cd --date=iso
echo @"
RmlUi$rmlui_version library and sample binaries for ${{ matrix.architecture }}.
https://github.com/mikke89/RmlUi
Built using $env:GENERATOR on $date (run $env:GITHUB_RUN_ID).
Commit id: $env:GITHUB_SHA
"@ > "Install/Build.txt"
- name: Copy licenses
run: |-
$vcpkg_installed_dir="C:/vcpkg/installed/$env:VCPKG_DEFAULT_TRIPLET/"
$destination_dir="./Install/Dependencies/"
$copyright_files = Get-ChildItem -Path "$vcpkg_installed_dir/share" -Filter "copyright" -Recurse | Where-Object { $_.Directory.Name -notmatch '^vcpkg-' }
mkdir $destination_dir -Force | Out-Null
foreach ($file in $copyright_files) {
$name = $file.Directory.Name
Copy-Item -Path $file.FullName -Destination "$destination_dir/$name.txt"
}
cp Dependencies/rlottie/licenses Install/Dependencies/rlottie -Recurse
cp Dependencies/rlottie/COPYING Install/Dependencies/rlottie
cp LICENSE.txt Install/LICENSE.txt
cp Include/RmlUi/Core/Containers/LICENSE.txt Install/LICENSE.Core.ThirdParty.txt
cp Source/Debugger/LICENSE.txt Install/LICENSE.Debugger.ThirdParty.txt
echo @'
The rlottie library includes source code licensed under Mozilla Public License Version 2.0.
The source for this code can be found in the rlottie library at the following URL:
Expand All @@ -183,13 +153,26 @@ jobs:
architecture: [win32, win64]

steps:
# Download artifacts in a well-defined order, with release binaries last.
- uses: actions/download-artifact@v4
with:
name: samples-${{ matrix.architecture }}

- uses: actions/download-artifact@v4
with:
name: build-${{ matrix.architecture }}-Dynamic-Debug

- uses: actions/download-artifact@v4
with:
merge-multiple: true
name: build-${{ matrix.architecture }}-Static-Debug

- name: List artifact contents
run: |
Get-ChildItem -Recurse | ForEach-Object { $_.FullName }
- uses: actions/download-artifact@v4
with:
name: build-${{ matrix.architecture }}-Dynamic-Release

- uses: actions/download-artifact@v4
with:
name: build-${{ matrix.architecture }}-Static-Release

- uses: actions/upload-artifact@v4
with:
Expand Down
50 changes: 50 additions & 0 deletions CMake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,53 @@ function(install_sample_target target)
DESTINATION "${CMAKE_INSTALL_DATADIR}/${sample_path}"
)
endfunction()

#[[
Install all license files, including for all installed packages in vcpkg if in use.
]]
function(install_licenses)
set(bin_licenses_dir "${CMAKE_CURRENT_BINARY_DIR}/Licenses")
configure_file("${PROJECT_SOURCE_DIR}/LICENSE.txt"
"${bin_licenses_dir}/LICENSE.txt" COPYONLY
)
configure_file("${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/Containers/LICENSE.txt"
"${bin_licenses_dir}/LICENSE.Core.ThirdParty.txt" COPYONLY
)
configure_file("${PROJECT_SOURCE_DIR}/Source/Debugger/LICENSE.txt"
"${bin_licenses_dir}/LICENSE.Debugger.ThirdParty.txt" COPYONLY
)

if(VCPKG_TOOLCHAIN)
set(vcpkg_share_dir "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share")
file(GLOB copyright_files "${vcpkg_share_dir}/*/copyright")
foreach(copyright_file IN LISTS copyright_files)
get_filename_component(name ${copyright_file} DIRECTORY)
get_filename_component(name ${name} NAME)
if(NOT "${name}" MATCHES "^vcpkg-")
set(copy_destination "${bin_licenses_dir}/Dependencies/${name}.txt")
configure_file(${copyright_file} ${copy_destination} COPYONLY)
endif()
endforeach()
endif()

install(DIRECTORY "${bin_licenses_dir}/" DESTINATION "${CMAKE_INSTALL_DATADIR}")
endfunction()

#[[
Install text file with build info.
]]
function(install_build_info)
if(NOT RMLUI_ARCHITECTURE OR NOT RMLUI_COMMIT_DATE OR NOT RMLUI_RUN_ID OR NOT RMLUI_SHA)
message(FATAL_ERROR "Missing variables")
endif()
generate_rmlui_version_string()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/Build.txt"
"RmlUi ${RMLUI_VERSION_SHORT} binaries for ${RMLUI_ARCHITECTURE}.\n\n"
"https://github.com/mikke89/RmlUi\n\n"
"Built using ${CMAKE_GENERATOR} (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}) on ${RMLUI_COMMIT_DATE} (run ${RMLUI_RUN_ID}).\n"
"Commit id: ${RMLUI_SHA}"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Build.txt"
DESTINATION "${CMAKE_INSTALL_DATADIR}"
)
endfunction()
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ endif()

set(RMLUI_INSTALL_TARGETS_DIR "" CACHE STRING "Override the install directory for the generated CMake targets.")
mark_as_advanced(RMLUI_INSTALL_TARGETS_DIR)
option(RMLUI_INSTALL_LICENSES_AND_BUILD_INFO "Install license files and build info intended for the github actions workflow." OFF)
mark_as_advanced(RMLUI_INSTALL_LICENSES_AND_BUILD_INFO)

# Add custom CMake modules path for external dependencies
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/Modules")
Expand Down Expand Up @@ -193,4 +195,9 @@ if(RMLUI_IS_ROOT_PROJECT)
)
endif()

if(RMLUI_INSTALL_LICENSES_AND_BUILD_INFO)
install_licenses()
install_build_info()
endif()

install_runtime_dependencies()

0 comments on commit 79d439c

Please sign in to comment.