|
| 1 | +# CMake file to be called in script mode (${CMAKE_COMMAND} -P <file>) to |
| 2 | +# Generate a source archive release asset from add_custom_command |
| 3 | +# |
| 4 | +# See SourceDistTarget.cmake |
| 5 | + |
| 6 | +if(NOT CMAKE_ARGV3) |
| 7 | + message(FATAL_ERROR "Must pass the top level src dir to ${CMAKE_ARGV2} as the first argument") |
| 8 | +endif() |
| 9 | + |
| 10 | +if(NOT CMAKE_ARGV4) |
| 11 | + message(FATAL_ERROR "Must pass the top level src dir to ${CMAKE_ARGV2} as the second argument") |
| 12 | +endif() |
| 13 | + |
| 14 | +find_package(Git) |
| 15 | +if(NOT GIT_FOUND) |
| 16 | + message( FATAL_ERROR "You can't create a source archive release asset without git!") |
| 17 | +endif() |
| 18 | + |
| 19 | +execute_process(COMMAND "${GIT_EXECUTABLE}" describe --always |
| 20 | + RESULT_VARIABLE git_status |
| 21 | + OUTPUT_VARIABLE git_version |
| 22 | + WORKING_DIRECTORY "${CMAKE_ARGV3}" |
| 23 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 24 | +if(NOT (git_status STREQUAL "0")) |
| 25 | + message( FATAL_ERROR "git describe --always failed with exit status: ${git_status} and message: |
| 26 | +${git_version}") |
| 27 | +endif() |
| 28 | + |
| 29 | +set(archive "OpenCoarrays-${git_version}") |
| 30 | +set(l_archive "opencoarrays-${git_version}") |
| 31 | +set(release_asset "${CMAKE_ARGV4}/${archive}.tar.gz") |
| 32 | +execute_process( |
| 33 | + COMMAND "${GIT_EXECUTABLE}" archive "--prefix=${archive}/" -o "${release_asset}" "${git_version}" |
| 34 | + RESULT_VARIABLE git_status |
| 35 | + OUTPUT_VARIABLE git_output |
| 36 | + WORKING_DIRECTORY "${CMAKE_ARGV3}" |
| 37 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 38 | + |
| 39 | +if(NOT (git_status STREQUAL "0")) |
| 40 | + message( FATAL_ERROR "git archive ... failed with exit status: ${git_status} and message: |
| 41 | +${git_output}") |
| 42 | +else() |
| 43 | + message( STATUS "Source code release asset created from `git archive`: ${release_asset}") |
| 44 | +endif() |
| 45 | + |
| 46 | +file(SHA256 "${release_asset}" tarball_sha256) |
| 47 | +set(sha256_checksum "${tarball_sha256} ${archive}.tar.gz") |
| 48 | +configure_file("${CMAKE_ARGV3}/cmake/opencoarrays-VER-SHA256.txt.in" |
| 49 | + "${CMAKE_ARGV4}/${l_archive}-SHA256.txt" |
| 50 | + @ONLY) |
| 51 | +message( STATUS |
| 52 | + "SHA 256 checksum of release tarball written out as: ${CMAKE_ARGV4}/${l_archive}-SHA256.txt" ) |
| 53 | + |
| 54 | +find_program(GPG_EXECUTABLE |
| 55 | + gpg |
| 56 | + DOC "Location of GnuPG (gpg) executable") |
| 57 | + |
| 58 | +if(GPG_EXECUTABLE) |
| 59 | + execute_process( |
| 60 | + COMMAND "${GPG_EXECUTABLE}" --armor --detach-sign --comment "@gpg_comment@" "${CMAKE_ARGV4}/${l_archive}-SHA256.txt" |
| 61 | + RESULT_VARIABLE gpg_status |
| 62 | + OUTPUT_VARIABLE gpg_output |
| 63 | + WORKING_DIRECTORY "${CMAKE_ARGV4}") |
| 64 | + if(NOT (gpg_status STREQUAL "0")) |
| 65 | + message( WARNING "GPG signing of ${CMAKE_ARGV4}/${l_archive}-SHA256.txt appears to have failed |
| 66 | +with status: ${gpg_status} and output: ${gpg_output}") |
| 67 | + else() |
| 68 | + configure_file("${CMAKE_ARGV3}/cmake/opencoarrays-VER-SHA256.txt.asc.in" |
| 69 | + "${CMAKE_ARGV4}/${l_archive}-GPG.comment" |
| 70 | + @ONLY) |
| 71 | + file(READ "${CMAKE_ARGV4}/${l_archive}-GPG.comment" gpg_comment) |
| 72 | + configure_file("${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc" |
| 73 | + "${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc.out" |
| 74 | + @ONLY) |
| 75 | + file(RENAME "${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc.out" |
| 76 | + "${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc") |
| 77 | + message(STATUS "GPG signed SHA256 checksum created: ${CMAKE_ARGV4}/${l_archive}-SHA256.txt.asc") |
| 78 | + endif() |
| 79 | +endif() |
0 commit comments