Commit 3a016513e42c082c6b7b509bf93f63066a1b65f8

Ralf Habacker 2020-12-28T12:29:13

CI: Add static building for cmake

diff --git a/.travis.yml b/.travis.yml
index 3584048..ba1a8f6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,18 +1,21 @@
 language: c
 
 compiler:
+  - x86_64-linux-gnu-gcc
   - i686-w64-mingw32-gcc
   - x86_64-w64-mingw32-gcc
 
 addons:
   apt:
     packages:
+      - gcc
       - gcc-mingw-w64
       - wine
       - cmake
 
 env:
-  - ci_buildsys=cmake
+  - ci_buildsys=cmake ci_variant=static
+  - ci_buildsys=cmake ci_variant=shared
   - ci_buildsys=Makefile
 
 jobs:
@@ -39,5 +42,12 @@ jobs:
       # Check that we have a real i586-mingw32msvc-gcc compiler as sometimes it is just a symlink to i686-w64-mingw32-gcc
       before_script: "i586-mingw32msvc-gcc -v 2>&1 | grep -q -x 'Target: i586-mingw32msvc'"
 
+  exclude:
+    # unsupported
+    - compiler: i686-linux-gnu-gcc
+      env: ci_buildsys=Makefile
+    - compiler: x86_64-linux-gnu-gcc
+      env: ci_buildsys=Makefile
+
 script:
   - ci_target=${CC%-*} ./tools/ci-build.sh
diff --git a/tools/ci-build.sh b/tools/ci-build.sh
index 366a407..196fd92 100755
--- a/tools/ci-build.sh
+++ b/tools/ci-build.sh
@@ -9,35 +9,72 @@ set -x
 
 # ci_target:
 # target to build for
-: "${ci_target:=${CROSS_COMPILE%-}}"
+: "${ci_target:=x86_64-linux-gnu-gcc}"
+
+# ci_variant:
+# variant to build e.g shared, static
+: "${ci_variant:=shared}"
+
+if test -v CROSS_COMPILE; then
+    ci_target=${CROSS_COMPILE%-}
+fi
 
 case "$ci_buildsys" in
     (Makefile)
-        ./configure --enable-shared --enable-static --enable-wine --cross-prefix=${ci_target}-
-        make
-        make test
+        case "$ci_target" in
+            (*mingw32*)
+                ./configure --enable-shared --enable-static --enable-wine --cross-prefix=${ci_target}-
+                make
+                make test
+                ;;
+        esac
         ;;
 
     (cmake)
+        cmake_options="
+            --no-warn-unused-cli
+            -DBUILD_TESTS=1
+            -DCMAKE_BUILD_TYPE=RelWithDebInfo
+        "
+        case "$ci_variant" in
+            (shared)
+                cmake_options+=" -DBUILD_SHARED_LIBS=ON"
+                ;;
+            (static)
+                cmake_options+=" -DBUILD_SHARED_LIBS=OFF"
+                ;;
+        esac
+
         cmake --version
-        rm -rf build
-        mkdir build
-        cd build
-        cmake \
-            --no-warn-unused-cli                         \
-            -DCMAKE_FIND_ROOT_PATH=$(${ci_target}-gcc --print-sysroot)/${ci_target}       \
-            -DCMAKE_BUILD_TYPE=RelWithDebInfo            \
-            -DCMAKE_C_COMPILER=$(which ${ci_target}-gcc) \
-            -DCMAKE_SYSTEM_PROCESSOR=${ci_target%-*-*}   \
-            -DCMAKE_CROSSCOMPILING=TRUE                  \
-            -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER    \
-            -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY     \
-            -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY     \
-            -DCMAKE_SYSTEM_NAME=Windows                  \
-            -DBUILD_TESTS=1                              \
-            -DENABLE_WINE=ON                             \
-            -DWINE_EXECUTABLE=/usr/bin/wine              \
-            ..
+
+        # create build dir
+        rm -rf ci-build-${ci_variant}-${ci_target}
+        mkdir -p ci-build-${ci_variant}-${ci_target}
+        cd ci-build-${ci_variant}-${ci_target}
+
+        case "$ci_target" in
+            (*mingw32*)
+                cmake \
+                    -DCMAKE_FIND_ROOT_PATH=$(${ci_target}-gcc --print-sysroot)/${ci_target}       \
+                    -DCMAKE_C_COMPILER=$(which ${ci_target}-gcc) \
+                    -DCMAKE_SYSTEM_PROCESSOR=${ci_target%-*-*}   \
+                    -DCMAKE_CROSSCOMPILING=TRUE                  \
+                    -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER    \
+                    -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY     \
+                    -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY     \
+                    -DCMAKE_SYSTEM_NAME=Windows                  \
+                    -DENABLE_WINE=ON                             \
+                    -DWINE_EXECUTABLE=/usr/bin/wine              \
+                    $cmake_options \
+                    ..
+                ;;
+            (*linux*)
+                cmake \
+                    $cmake_options \
+                    ..
+                ;;
+        esac
+
         make
         ctest --output-on-failure
         make install DESTDIR=$(pwd)/DESTDIR