-
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.
- Loading branch information
Showing
1 changed file
with
177 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
name: CMake Windows Build | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
CMAKE_VERSION: 3.25.2 | ||
|
||
jobs: | ||
build: | ||
name: ${{ matrix.config.name }} | ||
runs-on: ${{ matrix.config.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- { | ||
name: "Windows Latest MSVC", | ||
artifact: "dec2bin", | ||
os: windows-latest, | ||
cc: "cl", | ||
cxx: "cl", | ||
build_type: "Release", | ||
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat", | ||
archiver: "7z a", | ||
generators: "Visual Studio 2022" | ||
} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Build MPIR (vcpkg) | ||
#uses: johnwason/vcpkg-action@v4 | ||
#id: vcpkg | ||
#env: | ||
# VCPKG_DISABLE_METRICS: 1 | ||
#with: | ||
# pkgs: mpir | ||
# triplet: x64-windows-release | ||
# token: ${{ github.token }} | ||
run: | | ||
#vcpkg integrate install | ||
vcpkg install mpir:x64-windows-release | ||
#vcpkg list | ||
- name: Download CMake | ||
shell: cmake -P {0} | ||
run: | | ||
set(cmake_version $ENV{CMAKE_VERSION}) | ||
message(STATUS "Using host CMake version: ${CMAKE_VERSION}") | ||
if ("${{ runner.os }}" STREQUAL "Windows") | ||
set(cmake_suffix "windows-x86_64.zip") | ||
set(cmake_dir "cmake-${cmake_version}-windows-x86_64/bin") | ||
elseif ("${{ runner.os }}" STREQUAL "Linux") | ||
set(cmake_suffix "linux-x86_64.tar.gz") | ||
set(cmake_dir "cmake-${cmake_version}-linux-x86_64/bin") | ||
elseif ("${{ runner.os }}" STREQUAL "macOS") | ||
set(cmake_suffix "macos-universal.tar.gz") | ||
set(cmake_dir "cmake-${cmake_version}-macos-universal/CMake.app/Contents/bin") | ||
endif() | ||
set(cmake_url "https://github.com/Kitware/CMake/releases/download/v${cmake_version}/cmake-${cmake_version}-${cmake_suffix}") | ||
file(DOWNLOAD "${cmake_url}" ./cmake.zip SHOW_PROGRESS) | ||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./cmake.zip) | ||
# Add to PATH environment variable | ||
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/${cmake_dir}" cmake_dir) | ||
set(path_separator ":") | ||
if ("${{ runner.os }}" STREQUAL "Windows") | ||
set(path_separator ";") | ||
endif() | ||
file(APPEND "$ENV{GITHUB_PATH}" "$ENV{GITHUB_WORKSPACE}${path_separator}${cmake_dir}") | ||
if (NOT "${{ runner.os }}" STREQUAL "Windows") | ||
execute_process( | ||
COMMAND chmod +x ${cmake_dir}/cmake | ||
) | ||
endif() | ||
- name: Configure CMake | ||
shell: cmake -P {0} | ||
run: | | ||
set(ENV{CC} ${{ matrix.config.cc }}) | ||
set(ENV{CXX} ${{ matrix.config.cxx }}) | ||
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x") | ||
execute_process( | ||
COMMAND "${{ matrix.config.environment_script }}" && set | ||
OUTPUT_FILE environment_script_output.txt | ||
) | ||
file(STRINGS environment_script_output.txt output_lines) | ||
foreach(line IN LISTS output_lines) | ||
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$") | ||
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}") | ||
endif() | ||
endforeach() | ||
endif() | ||
set(path_separator ":") | ||
if ("${{ runner.os }}" STREQUAL "Windows") | ||
set(path_separator ";") | ||
endif() | ||
set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}${path_separator}$ENV{PATH}") | ||
execute_process( | ||
COMMAND cmake | ||
-S . | ||
-B build | ||
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} | ||
RESULT_VARIABLE result | ||
) | ||
if (NOT result EQUAL 0) | ||
message(FATAL_ERROR "Bad exit status") | ||
endif() | ||
- name: Build | ||
shell: cmake -P {0} | ||
run: | | ||
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x") | ||
file(STRINGS environment_script_output.txt output_lines) | ||
foreach(line IN LISTS output_lines) | ||
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$") | ||
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}") | ||
endif() | ||
endforeach() | ||
endif() | ||
execute_process( | ||
COMMAND cmake --build build --config ${{ matrix.config.build_type }} | ||
RESULT_VARIABLE result | ||
OUTPUT_VARIABLE output | ||
ERROR_VARIABLE output | ||
ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE | ||
) | ||
if (NOT result EQUAL 0) | ||
string(REGEX MATCH "FAILED:.*$" error_message "${output}") | ||
string(REPLACE "\n" "%0A" error_message "${error_message}") | ||
message("::error::${error_message}") | ||
message(FATAL_ERROR "Build failed") | ||
endif() | ||
- name: Pack | ||
shell: bash | ||
run: | | ||
#ls -laR | ||
#${{ matrix.config.archiver }} ${{ matrix.config.artifact }} . | ||
cp C:/vcpkg/packages/mpir_x64-windows-release/bin/mpir.dll ./build/${{ matrix.config.build_type }}/ | ||
ls -la ./build/${{ matrix.config.build_type }}/ | ||
- name: Upload | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ matrix.config.artifact }} | ||
path: ./build/${{ matrix.config.build_type }}/* | ||
|
||
- name: Upload release asset | ||
if: github.event_name == 'release' && (github.event.action == 'published' || github.event.action == 'created') | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ github.event.release.upload_url }} | ||
asset_path: ./${{ matrix.config.artifact }}.exe | ||
asset_name: ${{ matrix.config.artifact }} | ||
asset_content_type: application/octet-stream | ||
#asset_content_type: application/zip | ||
|
||
#- name: Test | ||
#working-directory: ${{github.workspace}}/build | ||
# Execute tests defined by the CMake configuration. | ||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | ||
#run: ctest -C ${{ matrix.config.build_type }} |