Build Windows exe using Travis CI

I work on MacOS Catalina but want to build a .exe file to run on Windows from a very simple Github repo (https://github.com/hect1995/TimerShutDown) that I have created.

To accomplish that I have been recommended to use Travis CI and I have used https://frame.42yeah.me/2020/02/27/travis-ci.html as a resource.

Following the instructions I have created in my repo a CMakeList.txt, run_command_and_apply_environment_differences.sh and vcvars64_vs2017.bat as stated in the link I have included.

My .travis.yml looks like:

language: cpp
compiler: cl
os: windows
script:
- source ./run_command_and_apply_environment_differences.sh "call vcvars64_vs2017.bat"
- mkdir build
- cd build
- cmake -G "NMake Makefiles" ..
- nmake all
- 7z a meli.zip timer.exe
- ls
deploy:
  provider: releases
  api_key:
    secure: ..........
  file: meli
  on:
    repo: hect1995/TimerShutDown
  skip_cleanup: 'true'

And my CMakeList.txt as:

cmake_minimum_required(VERSION 3.5)
project(TimerShutDown LANGUAGES CXX) 
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
add_executable(timer
  TimerShutDown.cpp
)

The problem is that once I commit and check the travis-ci web interface I get:

travis_fold:start:worker_info
[0K[33;1mWorker information[0m
hostname: 5eb54a23-75f9-4618-982b-fa6a21ef1096@1.worker-com-78f4bfd8fc-6fkkr.gce-production-3
version: v6.2.17 https://github.com/travis-ci/worker/tree/bc420764f334fe0d096a417c80426f672f1b7d18
instance: travis-job-081f61d8-02cd-455d-a9ba-b17a11fb4ffe travis-ci-windows-1809-containers-1591408217-f1e3a578 (via amqp)
startup: 6.172584848s
travis_fold:end:worker_info
[0KSecret environment variables are not obfuscated on Windows, please refer to our documentation: https://docs.travis-ci.com/user/best-practices-security[0m
travis_time:start:26281959
[0Ktravis_time:end:26281959:start=1592498987150521000,finish=1592498987194498700,duration=43977700,event=check_unsupported
[0Ktravis_time:start:1b268b00
[0Ktravis_time:end:1b268b00:start=1592498987251760000,finish=1592498987306660100,duration=54900100,event=apt_get_update
[0Ktravis_time:start:062fbb96
[0K[33;1mDisabling Windows Defender[0m
$ powershell -Command Set-MpPreference -DisableArchiveScanning \$true
$ powershell -Command Set-MpPreference -DisableRealtimeMonitoring \$true
$ powershell -Command Set-MpPreference -DisableBehaviorMonitoring \$true
travis_time:end:062fbb96:start=1592498987392416000,finish=1592498991408732800,duration=4016316800,event=disable_windows_defender
[0Ktravis_time:start:05294e84
[0Ktravis_time:start:0446ba84
[0Ktravis_time:end:0446ba84:start=1592498991519115500,finish=1592498991685142500,duration=166027000,event=checkout
[0Ktravis_fold:start:ssh_key
[0KInstalling SSH key from: default repository key
Key fingerprint: f7:de:8d:18:a6:4a:15:5d:27:4a:1b:1d:4a:c8:f5:49
travis_fold:end:ssh_key
[0KUsing /c/Users/travis/_netrc to clone repository.

travis_fold:start:git.checkout
[0Ktravis_time:start:01089f60
[0K$ git clone --depth=50 --branch=untagged-696a63f9f4633d877ab5 https://github.com/hect1995/TimerShutDown.git hect1995/TimerShutDown
Cloning into 'hect1995/TimerShutDown'...
travis_time:end:01089f60:start=1592498991954346200,finish=1592498992999358100,duration=1045011900,event=checkout
[0K$ cd hect1995/TimerShutDown
$ git checkout -qf untagged-696a63f9f4633d877ab5
travis_fold:end:git.checkout
[0K
travis_time:end:01089f60:start=1592498991954346200,finish=1592498993087161100,duration=1132814900,event=checkout
[0Ktravis_time:start:0fbc2d0c
[0Ktravis_time:end:0fbc2d0c:start=1592498993130620400,finish=1592498993219381900,duration=88761500,event=env
[0K$ export TRAVIS_COMPILER=cl
$ export CXX=${CXX:-g++}
$ export CXX_FOR_BUILD=${CXX_FOR_BUILD:-g++}
$ export CC=${CC:-gcc}
$ export CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
$ cl --version
travis_time:start:019c5460
[0K$ source ./run_command_and_apply_environment_differences.sh "call vcvars64_vs2017.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
Note: switching to '99a46b6fc9820744d604066447c397c7e6c3b7f6'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

/c/Users/travis/.travis/functions: line 109: cl: command not found
[vcvarsall.bat] Environment initialized for: 'x64'
travis_time:end:019c5460:start=1592498993275944400,finish=1592498995445591600,duration=2169647200,event=script
[0K[32;1mThe command "source ./run_command_and_apply_environment_differences.sh "call vcvars64_vs2017.bat"" exited with 0.[0m
travis_time:start:0307f4bb
[0K$ mkdir build
travis_time:end:0307f4bb:start=1592498995489408800,finish=1592498995549967800,duration=60559000,event=script
[0K[32;1mThe command "mkdir build" exited with 0.[0m
travis_time:start:0151574a
[0K$ cd build
travis_time:end:0151574a:start=1592498995594607600,finish=1592498995630024100,duration=35416500,event=script
[0K[32;1mThe command "cd build" exited with 0.[0m
travis_time:start:09542556
[0K$ cmake -G "NMake Makefiles" ..
-- The CXX compiler identification is GNU 8.1.0
-- Check for working CXX compiler: C:/ProgramData/chocolatey/bin/g++.exe
-- Check for working CXX compiler: C:/ProgramData/chocolatey/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/travis/build/hect1995/TimerShutDown/build
travis_time:end:09542556:start=1592498995673921900,finish=1592499001690910900,duration=6016989000,event=script
[0K[32;1mThe command "cmake -G "NMake Makefiles" .." exited with 0.[0m
travis_time:start:11add02c
[0K$ nmake all
[35m[1mScanning dependencies of target timer[0m
[ 50%] [32mBuilding CXX object CMakeFiles/timer.dir/timerShutDown.cpp.obj[0m

Microsoft (R) Program Maintenance Utility Version 14.16.27040.0
Copyright (C) Microsoft Corporation.  All rights reserved.

[100%] [32m[1mLinking CXX executable timer.exe[0m
[100%] Built target timer
travis_time:end:11add02c:start=1592499001734180100,finish=1592499002917674200,duration=1183494100,event=script
[0K[32;1mThe command "nmake all" exited with 0.[0m
travis_time:start:096cf042
[0K$ 7z a meli.zip timer.exe

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
1 file, 65737 bytes (65 KiB)

Creating archive: meli.zip

Add new data to archive: 1 file, 65737 bytes (65 KiB)


Files read from disk: 1
Archive size: 20051 bytes (20 KiB)
Everything is Ok
travis_time:end:096cf042:start=1592499002958082600,finish=1592499003120169300,duration=162086700,event=script
[0K[32;1mThe command "7z a meli.zip timer.exe" exited with 0.[0m
travis_time:start:212e813e
[0K$ ls
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
meli.zip
timer.exe
travis_time:end:212e813e:start=1592499003160609500,finish=1592499003215826800,duration=55217300,event=script
[0K[32;1mThe command "ls" exited with 0.[0m

[33;1mSkipping a deployment with the releases provider because this branch is not permitted: untagged-696a63f9f4633d877ab5[0m

Done. Your build exited with 0.

The problem is:

If I run on Windows timer.exe I get:

The code execution cannot proceed because libgcc_s_seh-1.dllas not found. Reinstalling the program may fix this problem

I solved the problem by adding into the CMakefile.txt but now I get:

The code execution cannot proceed because `libwinpthread-1.dll` was not found. Reinstalling the program may fix this problem

What am I doing wrong?

The advice in that blog post is dated (and the author didn’t even bother to put a date) and the vcvars64_vs2017.bat provided looks incomplete. This is what you get blindly relying on random advice on the Net.

https://travis-ci.com/github/hect1995/TimerShutDown/builds/172098634#L45:

/c/Users/travis/.travis/functions: line 109: cl: command not found

shows that the batch file cannot set up VS build tools.


There’s no official Travis guidance on building with CMake, so the best thing to rely on is CMake’s official advice.

Specifically, to build stuff with the VS toolchain, it has the VS 2017 generator. It’s supposed to find VS tools itself and set up necessary paths in the generated files. Due to this, you’ll probably need to invoke the build via CMake, too.

Imprint