Build multiple CMake configurations

Philip's Avatar

Philip

05 Nov, 2019 08:54 AM

Hi,

I am using AppVeyor to build a C++ library that uses CMake as build system. The library can be built as both static and dynamic library and this can be configured by passing either -DBUILD_SHARED_LIBS=0 or -DBUILD_SHARED_LIBS=1 as command line argument to cmake. How can I configure AppVeyor (using appveyor.yml) so that it builds both versions? The current appveyor.yml looks like this:

version: 1.0.{build}
image:
- Visual Studio 2019
- Visual Studio 2017
configuration:
- Debug
- Release
before_build:
- cmd: cmake -H. -B./build -DBUILD_SHARED_LIBS=1
build:
  verbosity: normal

I tried wrapping the before_build in a for, but this did not work (AppVeyor ran once with -DBUILD_SHARED_LIBS=1 but skipped the ...=0 version):

for:
  -
    before_build:
    - cmd: cmake -H. -B./build -DBUILD_SHARED_LIBS=1
  -
    before_build:
    - cmd: cmake -H. -B./build -DBUILD_SHARED_LIBS=0

I also tried adding a matrix to the before_build, but this did not work either (AppVeyor showed Error parsing appveyor.yml: Script contents must be a string (Line: 10, Column: 3)):

before_build:
  matrix:
  - cmd: cmake -H. -B./build -DBUILD_SHARED_LIBS=1
  - cmd: cmake -H. -B./build -DBUILD_SHARED_LIBS=0

How can I configure AppVeyor so that it builds both versions?

Regards,
Philip

  1. Support Staff 1 Posted by Feodor Fitsner on 05 Nov, 2019 05:28 PM

    Feodor Fitsner's Avatar

    Hi Philip,

    This is probably the config you are looking for:

    
    version: 1.0.{build}
    
    image:
    - Visual Studio 2019
    - Visual Studio 2017
    
    configuration:
    - Debug
    - Release
    
    environment:
      matrix:
      - DBUILD_SHARED_LIBS: 0
      - DBUILD_SHARED_LIBS: 1
    
    before_build:
    - cmd: cmake -H. -B./build -DBUILD_SHARED_LIBS=%DBUILD_SHARED_LIBS%
    
    build:
      verbosity: normal
    
  2. 2 Posted by Philip on 05 Nov, 2019 07:57 PM

    Philip's Avatar

    That works great, thank you! I did not know that you can use environment variables for this.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

05 Dec, 2019 09:12 PM
04 Dec, 2019 07:46 PM
04 Dec, 2019 12:01 AM
04 Dec, 2019 12:00 AM
03 Dec, 2019 11:00 PM