diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..3ec1db15 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,146 @@ +name: Release + +on: + release: + types: + - published + +jobs: + source: + name: Source + + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Generate .version + run: | + cmake -DWRITE_VERSION=1 -P generate_version.cmake + + - name: Create bundles + run: | + FOLDER_NAME=grfcodec-${{ github.event.release.tag_name }} + + # Rename the folder to grfcodec-NNN + mkdir ${FOLDER_NAME} + find . -maxdepth 1 -not -name . -not -name .git -not -name ${FOLDER_NAME} -exec mv {} ${FOLDER_NAME}/ \; + + mkdir -p build/bundles + + echo "::group::Create tarball (xz) bundle" + tar --xz -cvf build/bundles/${FOLDER_NAME}-source.tar.xz ${FOLDER_NAME} + echo "::endgroup::" + + echo "::group::Create zip bundle" + zip -9 -r build/bundles/${FOLDER_NAME}-source.zip ${FOLDER_NAME} + echo "::endgroup::" + + - name: Store bundles + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ github.event.release.tag_name }} build/bundles/* + + windows: + needs: source + + strategy: + fail-fast: false + matrix: + arch: [x86, x64] + + name: Windows (${{ matrix.arch }}) + + runs-on: windows-latest + + steps: + - name: Prepare build dir for gh usage + shell: bash + run: | + git init build + cd build + git remote add origin ${{ github.event.repository.html_url }} + + - name: Download source + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + cd build + gh release download ${{ github.event.release.tag_name }} -p "*.xz" -D .. + + - name: Unpack source + shell: bash + run: | + tar --xz -xf *-source.tar.xz --strip-components=1 + + - name: Prepare cache key + id: key + shell: powershell + run: | + # Work around caching failure with GNU tar + New-Item -Type Junction -Path vcpkg -Target c:\vcpkg + + Write-Output "image=$env:ImageOS-$env:ImageVersion" >> $env:GITHUB_OUTPUT + + - name: Enable vcpkg cache + uses: actions/cache@v3 + with: + path: vcpkg/installed + key: ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }}-1 # Increase the number whenever dependencies are modified + restore-keys: | + ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }} + + - name: Prepare vcpkg + shell: bash + run: | + vcpkg install --triplet=${{ matrix.arch }}-windows-static \ + boost-bimap \ + boost-date-time \ + boost-foreach \ + libpng \ + # EOF + + - name: Install MSVC problem matcher + uses: ammaraskar/msvc-problem-matcher@master + + - name: Configure developer command prompt for ${{ matrix.arch }} + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + + - name: Build + shell: bash + run: | + cd build + + echo "::group::CMake" + cmake .. \ + -GNinja \ + -DVCPKG_TARGET_TRIPLET=${{ matrix.arch }}-windows-static \ + -DCMAKE_TOOLCHAIN_FILE="c:\vcpkg\scripts\buildsystems\vcpkg.cmake" \ + -DCMAKE_BUILD_TYPE=Release \ + # EOF + echo "::endgroup::" + + echo "::group::Build" + cmake --build . + echo "::endgroup::" + + - name: Create bundles + shell: bash + run: | + cd build + echo "::group::Run CPack" + cpack + echo "::endgroup::" + + - name: Store bundles + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + cd build + gh release upload ${{ github.event.release.tag_name }} bundles/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 57c22e30..b359b060 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,6 @@ if(MINGW) endif() -find_package(Git REQUIRED) find_package(PNG) find_package(Boost REQUIRED) @@ -84,12 +83,10 @@ include_directories("${GENERATED_BINARY_DIR}") # Target to generate version.h add_custom_target(version_header COMMAND ${CMAKE_COMMAND} - -D GIT_EXECUTABLE=${GIT_EXECUTABLE} - -D INPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in - -D OUTPUT_FILE=${GENERATED_BINARY_DIR}/version.h + -DGENERATED_BINARY_DIR=${GENERATED_BINARY_DIR} + -DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_version.cmake" - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in" - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/generate_version.cmake" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} BYPRODUCTS "${GENERATED_BINARY_DIR}/version.h" ) @@ -115,6 +112,7 @@ add_custom_target(palettes_header DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/ttdpal.h.in" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/pal2c.cmake" BYPRODUCTS "${GENERATED_BINARY_DIR}/ttdpal.h" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) @@ -146,3 +144,42 @@ endif() # Add source files add_subdirectory(src) + + +# Install files +include(GNUInstallDirs) + +install(TARGETS + grfid + grfstrip + nforenum + grfcodec + DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/changelog.txt + ${CMAKE_CURRENT_SOURCE_DIR}/COPYING + DESTINATION ${CMAKE_INSTALL_DOCDIR} +) + +add_subdirectory(docs) + + +# CPack +if(WIN32) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ARCHITECTURE "win64") + else() + set(ARCHITECTURE "win32") + endif() + + set(CPACK_SYSTEM_NAME "${ARCHITECTURE}") + set(CPACK_STRIP_FILES YES) + set(CPACK_OUTPUT_FILE_PREFIX "bundles") + set(CPACK_PACKAGE_FILE_NAME "grfcodec-#CPACK_PACKAGE_VERSION#-windows-${CPACK_SYSTEM_NAME}") + + set(CPACK_GENERATOR "ZIP") + + include(CPack) +endif() diff --git a/CPackProperties.cmake.in b/CPackProperties.cmake.in new file mode 100644 index 00000000..55c0626b --- /dev/null +++ b/CPackProperties.cmake.in @@ -0,0 +1,5 @@ +# Make the current version available to CPack +set(CPACK_PACKAGE_VERSION "@GIT_VERSION@") + +# Name the output file with the correct version +string(REPLACE "#CPACK_PACKAGE_VERSION#" "${CPACK_PACKAGE_VERSION}" CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}") diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 00000000..d7d5fa8a --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.5) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/grfcodec.1 + ${CMAKE_CURRENT_SOURCE_DIR}/grfid.1 + ${CMAKE_CURRENT_SOURCE_DIR}/grfstrip.1 + ${CMAKE_CURRENT_SOURCE_DIR}/nforenum.1 + DESTINATION ${CMAKE_INSTALL_MANDIR} +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/auto_correct.txt + ${CMAKE_CURRENT_SOURCE_DIR}/commands.txt + ${CMAKE_CURRENT_SOURCE_DIR}/grf.txt + ${CMAKE_CURRENT_SOURCE_DIR}/grfcodec.txt + ${CMAKE_CURRENT_SOURCE_DIR}/grftut.txt + ${CMAKE_CURRENT_SOURCE_DIR}/nforenum.txt + ${CMAKE_CURRENT_SOURCE_DIR}/readme.rpn.txt + ${CMAKE_CURRENT_SOURCE_DIR}/readme.txt + ${CMAKE_CURRENT_SOURCE_DIR}/sanity.txt + ${CMAKE_CURRENT_SOURCE_DIR}/todo.txt + DESTINATION ${CMAKE_INSTALL_DOCDIR} +) diff --git a/generate_version.cmake b/generate_version.cmake index f4188708..d392048f 100644 --- a/generate_version.cmake +++ b/generate_version.cmake @@ -1,18 +1,40 @@ -execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=M - OUTPUT_VARIABLE GIT_VERSION - RESULT_VARIABLE GIT_DESCRIBE_RESULT - ERROR_VARIABLE GIT_DESCRIBE_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE -) +find_package(Git QUIET) -execute_process( - COMMAND ${GIT_EXECUTABLE} show -s --pretty=%cd --date=short HEAD - OUTPUT_VARIABLE GIT_DATE - RESULT_VARIABLE GIT_SHOW_RESULT - ERROR_VARIABLE GIT_SHOW_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE -) +# .git may be a directory or a regular file +if(GIT_FOUND AND EXISTS ".git") + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty=M + OUTPUT_VARIABLE GIT_VERSION + RESULT_VARIABLE GIT_DESCRIBE_RESULT + ERROR_VARIABLE GIT_DESCRIBE_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) -configure_file(${INPUT_FILE} ${OUTPUT_FILE}) + execute_process( + COMMAND ${GIT_EXECUTABLE} show -s --pretty=%cd --date=short HEAD + OUTPUT_VARIABLE GIT_DATE + RESULT_VARIABLE GIT_SHOW_RESULT + ERROR_VARIABLE GIT_SHOW_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +elseif(EXISTS ".version") + file(READ ".version" GIT_VERSION) + string(REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}") + string(REPLACE "\t" ";" GIT_VERSION "${GIT_VERSION}") + list(GET GIT_VERSION 1 GIT_DATE) + list(GET GIT_VERSION 0 GIT_VERSION) +else() + message(WARNING "No version detected") + set(GIT_VERSION "unknown") + set(GIT_DATE "unknown") +endif() +if(WRITE_VERSION) + file(WRITE .version "${GIT_VERSION}\t${GIT_DATE}\n") +else() + message(STATUS "Generating version.h") + configure_file("src/version.h.in" "${GENERATED_BINARY_DIR}/version.h") + + message(STATUS "Generating CPackProperties.cmake") + configure_file("CPackProperties.cmake.in" "${CPACK_BINARY_DIR}/CPackProperties.cmake" @ONLY) +endif()