]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: separate target for examples, optimize CI, fix fallouts
authorViktor Szakats <commit@vsz.me>
Sat, 14 Sep 2024 00:21:33 +0000 (02:21 +0200)
committerViktor Szakats <commit@vsz.me>
Fri, 20 Sep 2024 21:53:33 +0000 (23:53 +0200)
- Move `docs/examples` builds under a separate target.

- Make `BUILD_EXAMPLES` default to `ON`. It means to generate the rules
  for `docs/examples` by default, but not build them. To build them,
  an explicit `make curl-examples` (or ninja, etc) command is necessary.
  This syncs behaviour with autotools, and also how both cmake and
  autotools are building tests.

- GHA: update cmake jobs to use the new way of building examples.

- GHA: move examples build step at the end of the job, after building
  and running tests. This allows to have build and test run results
  faster, and leave the seldom-changing examples build to the end.
  Building examples is the slowest build step with no practical way to
  make them fast.

- appveyor: enable building examples in two old-MSVC jobs.

- examples: fix examples to build cleanly with old MSVC versions.

- GHA/non-native: move example build log under a GHA foldable section.

- GHA/windows: move building examples into separate step for Linux cross
  jobs.

Follow-up to dfdd978f7c60224dffe2aac25b436dc0a5cd0186 #13491
Closes #14906

13 files changed:
.github/workflows/cygwin.yml
.github/workflows/linux.yml
.github/workflows/macos.yml
.github/workflows/non-native.yml
.github/workflows/windows.yml
CMakeLists.txt
appveyor.sh
appveyor.yml
docs/examples/CMakeLists.txt
docs/examples/cookie_interface.c
docs/examples/http2-serverpush.c
docs/examples/sendrecv.c
docs/examples/simplessl.c

index 1f1f250cd8ffc123f1e8e0a2bc96b6db70b516e1..1c2fd19ec26b9610a7b4fa935acd7f4e504f69de 100644 (file)
@@ -113,11 +113,6 @@ jobs:
           find . -name '*.exe' -o -name '*.dll'
           bld/src/curl.exe --disable --version
 
-      - name: 'autotools build examples'
-        if: ${{ matrix.build == 'automake' }}
-        timeout-minutes: 5
-        run: make -C bld -j5 V=1 examples
-
       - name: 'autotools build tests'
         if: ${{ matrix.build == 'automake' && matrix.tflags != 'skipall' }}
         timeout-minutes: 15
@@ -133,6 +128,11 @@ jobs:
           fi
           make -C bld -j5 V=1 test-ci
 
+      - name: 'autotools build examples'
+        if: ${{ matrix.build == 'automake' }}
+        timeout-minutes: 5
+        run: make -C bld -j5 V=1 examples
+
       - name: 'cmake configure'
         if: ${{ matrix.build == 'cmake' }}
         timeout-minutes: 5
@@ -141,7 +141,6 @@ jobs:
           cmake -B bld -G Ninja ${options} \
             -DCMAKE_UNITY_BUILD=ON \
             -DCURL_WERROR=ON \
-            -DBUILD_EXAMPLES=ON \
             -DENABLE_WEBSOCKETS=ON \
             -DCURL_BROTLI=ON \
             ${{ matrix.config }}
@@ -186,3 +185,8 @@ jobs:
           fi
           PATH="$PWD/bld/lib:$PATH"
           cmake --build bld --config '${{ matrix.type }}' --target test-ci
+
+      - name: 'cmake build examples'
+        if: ${{ matrix.build == 'cmake' }}
+        timeout-minutes: 5
+        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target curl-examples
index be6fb0c024351c6bf3832a4bafc7e83c40bfa124..6b099c416180c21d34df922f34beaface284a4b6 100644 (file)
@@ -504,7 +504,6 @@ jobs:
           cmake . \
             -DCMAKE_C_COMPILER_TARGET=$(uname -m)-pc-linux-gnu -DBUILD_STATIC_LIBS=ON \
             -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON \
-            -DBUILD_EXAMPLES=ON \
             -DCURL_BROTLI=ON -DCURL_ZSTD=ON \
             ${{ matrix.build.generate }}
         if: ${{ matrix.build.generate }}
@@ -535,10 +534,6 @@ jobs:
       - run: ./src/curl -V
         name: 'check curl -V output'
 
-      - run: ${{ matrix.build.make-prefix }} make V=1 examples
-        if: ${{ matrix.build.configure }}
-        name: 'make examples'
-
       - run: make V=1 -C tests
         if: ${{ matrix.build.configure && matrix.build.install_steps != 'skipall' }}
         name: 'make tests (autotools)'
@@ -566,3 +561,11 @@ jobs:
         env:
           TFLAGS: "${{ matrix.build.tflags }}"
           CURL_CI: github
+
+      - run: ${{ matrix.build.make-prefix }} make V=1 examples
+        if: ${{ matrix.build.configure }}
+        name: 'make examples (autotools)'
+
+      - run: ${{ matrix.build.make-prefix }} make VERBOSE=1 curl-examples
+        if: ${{ matrix.build.generate }}
+        name: 'make examples (cmake)'
index 3383b35ee409543f91983f33941fd6ee85b83e52..84e0fb16183713698baeab3c0de3db92dcb5a479 100644 (file)
@@ -121,7 +121,7 @@ jobs:
             compiler: gcc-12
             configure: --enable-debug --with-secure-transport --enable-websockets --with-libssh2=$(brew --prefix libssh2)
             macos-version-min: '10.8'
-          - name: 'LibreSSL'
+          - name: 'LibreSSL +examples'
             compiler: clang
             install: libressl
             configure: --enable-debug --with-openssl=$(brew --prefix libressl) --enable-websockets
@@ -229,9 +229,6 @@ jobs:
       - name: 'curl version'
         run: bld/src/curl --disable --version
 
-      - name: 'make examples'
-        run: make -C bld V=1 examples
-
       - name: 'make tests'
         run: make -C bld V=1 -C tests
 
@@ -264,6 +261,10 @@ jobs:
           rm -f $HOME/.curlrc
           make -C bld V=1 test-ci
 
+      - name: 'make examples'
+        if: ${{ contains(matrix.build.name, '+examples') }}
+        run: make -C bld V=1 examples
+
   cmake:
     name: 'CM ${{ matrix.compiler }} ${{ matrix.build.name }}'
     runs-on: 'macos-latest'
@@ -287,9 +288,9 @@ jobs:
           - name: 'SecureTransport ws debug+'
             generate: -DCURL_USE_SECTRANSP=ON -DENABLE_WEBSOCKETS=ON -DENABLE_DEBUG=ON -DENABLE_CURLDEBUG=ON
             macos-version-min: '10.8'
-          - name: 'LibreSSL !ldap heimdal c-ares'
+          - name: 'LibreSSL !ldap heimdal c-ares +examples'
             install: libressl heimdal
-            generate: -DOPENSSL_ROOT_DIR=$(brew --prefix libressl) -DENABLE_ARES=ON -DCURL_USE_GSSAPI=ON -DGSS_ROOT_DIR=$(brew --prefix heimdal) -DCURL_DISABLE_LDAP=ON -DBUILD_EXAMPLES=ON
+            generate: -DOPENSSL_ROOT_DIR=$(brew --prefix libressl) -DENABLE_ARES=ON -DCURL_USE_GSSAPI=ON -DGSS_ROOT_DIR=$(brew --prefix heimdal) -DCURL_DISABLE_LDAP=ON
             macos-version-min: '10.15'
           - name: 'wolfSSL !ldap brotli zstd'
             install: brotli wolfssl zstd
@@ -399,6 +400,10 @@ jobs:
           rm -f $HOME/.curlrc
           ninja -C bld test-ci
 
+      - name: 'cmake build examples'
+        if: ${{ contains(matrix.name, '+examples') }}
+        run: make -C bld VERBOSE=1
+
   combinations:  # Test buildability with host OS, Xcode / SDK, compiler, target-OS, SecureTransport/not, built tool, combinations
     if: true  # Set to `true` to enable this test matrix. It runs quickly.
     name: "${{ matrix.build == 'cmake' && 'CM' || 'AM' }} ${{ matrix.compiler }} ${{ matrix.image }} ${{ matrix.xcode }} ${{ matrix.config }}"
index 444a0974040e36fd23d8bff94e85bf3b054765c7..0a98ebf0d32f2d36c1351c0c47f2bcf8cf8514ca 100644 (file)
@@ -58,7 +58,6 @@ jobs:
               -DCMAKE_UNITY_BUILD=ON \
               -DCURL_WERROR=ON \
               -DENABLE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \
-              -DBUILD_EXAMPLES=ON \
               -DENABLE_WEBSOCKETS=ON \
               -DCURL_USE_OPENSSL=ON \
               -DCURL_BROTLI=ON -DCURL_USE_GSSAPI=ON \
@@ -70,6 +69,9 @@ jobs:
               export TFLAGS='-j0'  # flakies: ~389 ~392 ~TFTP and more
               cmake --build bld --config Debug --target test-ci
             fi
+            echo '::group::build examples'
+            cmake --build bld --config Debug --parallel 3 --target curl-examples
+            echo '::endgroup::'
 
   openbsd:
     name: 'OpenBSD (cmake, libressl, clang)'
@@ -93,7 +95,6 @@ jobs:
               -DCMAKE_UNITY_BUILD=ON \
               -DCURL_WERROR=ON \
               -DENABLE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \
-              -DBUILD_EXAMPLES=ON \
               -DENABLE_WEBSOCKETS=ON \
               -DCURL_USE_OPENSSL=ON \
               -DCURL_BROTLI=ON \
@@ -105,6 +106,9 @@ jobs:
               export TFLAGS='-j8 ~3017 ~TFTP ~FTP'  # FIXME: TFTP requests executed twice? Related: `curl: (69) TFTP: Access Violation`?
               cmake --build bld --config Debug --target test-ci
             fi
+            echo '::group::build examples'
+            cmake --build bld --config Debug --parallel 3 --target curl-examples
+            echo '::endgroup::'
 
   freebsd:
     name: 'FreeBSD (${{ matrix.build }}, openssl, ${{ matrix.compiler }}, ${{ matrix.arch }})'
@@ -140,11 +144,13 @@ jobs:
               --disable-dependency-tracking || { tail -n 1000 config.log; false; }
             make -j3 install
             src/curl --disable --version
-            make -j3 examples
             if [ '${{ matrix.arch }}' = 'x86_64' ]; then  # Slow on emulated CPU
               make -j3 -C tests
               make test-ci V=1 TFLAGS='-j8 ~FTP'
             fi
+            echo '::group::build examples'
+            make -j3 examples
+            echo '::endgroup::'
 
       - name: 'cmake'
         if: ${{ matrix.build == 'cmake' }}
@@ -162,7 +168,6 @@ jobs:
               -DCMAKE_UNITY_BUILD=ON \
               -DCURL_WERROR=ON \
               -DENABLE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \
-              -DBUILD_EXAMPLES=ON \
               -DENABLE_WEBSOCKETS=ON \
               -DCURL_USE_OPENSSL=ON \
               -DCURL_BROTLI=ON -DCURL_USE_GSSAPI=ON \
@@ -174,6 +179,9 @@ jobs:
               export TFLAGS='-j8 ~FTP'
               cmake --build bld --config Debug --target test-ci
             fi
+            echo '::group::build examples'
+            cmake --build bld --config Debug --parallel 3 --target curl-examples
+            echo '::endgroup::'
 
   omnios:
     name: 'OmniOS (autotools, openssl, gcc, amd64)'
@@ -197,6 +205,8 @@ jobs:
               --disable-dependency-tracking || { tail -n 1000 config.log; false; }
             gmake -j3 install
             src/curl --disable --version
-            gmake -j3 examples
             gmake -j3 -C tests
             gmake test-ci V=1 TFLAGS='-j12 ~MQTT ~FTP'
+            echo '::group::build examples'
+            gmake -j3 examples
+            echo '::endgroup::'
index f036076faca2c47f6b6e1431e3e11cada2d09124..052a405602d1dcf705d97cca7151d02db20a5cbe 100644 (file)
@@ -56,8 +56,8 @@ jobs:
           - { build: 'cmake'    , sys: 'mingw64', env: 'x86_64'      , tflags: '~2301 ~2302'             , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DENABLE_ARES=ON', type: 'Debug', name: 'schannel c-ares U' }
           - { build: 'cmake'    , sys: 'ucrt64' , env: 'ucrt-x86_64' , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DENABLE_CURLDEBUG=ON', type: 'Release', name: 'schannel R TrackMemory' }
           - { build: 'cmake'    , sys: 'clang64', env: 'clang-x86_64', tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_OPENSSL=ON -DENABLE_UNICODE=OFF', type: 'Release', name: 'openssl' }
-          - { build: 'cmake'    , sys: 'mingw64', env: 'x86_64'      , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DBUILD_EXAMPLES=OFF', type: 'Release', test: 'uwp', name: 'schannel R' }
-          - { build: 'cmake'    , sys: 'mingw32', env: 'i686'        , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DBUILD_EXAMPLES=OFF', type: 'Release', name: 'schannel R' }
+          - { build: 'cmake'    , sys: 'mingw64', env: 'x86_64'      , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON', type: 'Release', test: 'uwp', name: 'schannel R' }
+          - { build: 'cmake'    , sys: 'mingw32', env: 'i686'        , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON', type: 'Release', name: 'schannel R' }
       fail-fast: false
     steps:
       - run: git config --global core.autocrlf input
@@ -135,11 +135,6 @@ jobs:
           find . -name '*.exe' -o -name '*.dll'
           bld/src/curl.exe --disable --version
 
-      - name: 'autotools build examples'
-        if: ${{ matrix.build == 'autotools' }}
-        timeout-minutes: 5
-        run: make -C bld -j5 V=1 examples
-
       - name: 'autotools build tests'
         if: ${{ matrix.build == 'autotools' && matrix.tflags != 'skipall' }}
         timeout-minutes: 10
@@ -169,6 +164,11 @@ jobs:
           PATH="$PATH:/c/Program Files (x86)/stunnel/bin"
           make -C bld -j5 V=1 test-ci
 
+      - name: 'autotools build examples'
+        if: ${{ matrix.build == 'autotools' }}
+        timeout-minutes: 5
+        run: make -C bld -j5 V=1 examples
+
       - name: 'cmake configure'
         if: ${{ matrix.build == 'cmake' }}
         timeout-minutes: 5
@@ -198,7 +198,6 @@ jobs:
             '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \
             -DCMAKE_UNITY_BUILD=ON \
             -DCURL_WERROR=ON \
-            -DBUILD_EXAMPLES=ON \
             -DENABLE_WEBSOCKETS=ON \
             -DCURL_BROTLI=ON \
             ${{ matrix.config }}
@@ -224,7 +223,7 @@ jobs:
         if: ${{ matrix.build == 'cmake' }}
         timeout-minutes: 1
         run: |
-          find . -name '*.exe' -o -name '*.dll' | grep -v '/examples/'
+          find . -name '*.exe' -o -name '*.dll'
           if [ '${{ matrix.test }}' != 'uwp' ]; then  # UWP missing 'msvcr120_app.dll', fails with exit code 0xc0000135
             PATH="$PWD/bld/lib:$PATH"
             bld/src/curl.exe --disable --version
@@ -259,6 +258,11 @@ jobs:
           PATH="$PWD/bld/lib:$PATH:/c/Program Files (x86)/stunnel/bin"
           cmake --build bld --config '${{ matrix.type }}' --target test-ci
 
+      - name: 'cmake build examples'
+        if: ${{ matrix.build == 'cmake' }}
+        timeout-minutes: 5
+        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target curl-examples
+
   old-mingw-w64:
     name: 'old-mingw, CM ${{ matrix.env }} ${{ matrix.name }}'
     runs-on: windows-latest
@@ -327,7 +331,6 @@ jobs:
             '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \
             -DCMAKE_UNITY_BUILD=ON \
             -DCURL_WERROR=ON \
-            -DBUILD_EXAMPLES=ON \
             -DENABLE_WEBSOCKETS=ON \
             -DCURL_USE_LIBPSL=OFF \
             ${{ matrix.config }}
@@ -343,7 +346,7 @@ jobs:
         run: cat bld/lib/curl_config.h || true
 
       - name: 'cmake build'
-        timeout-minutes: 10
+        timeout-minutes: 5
         run: |
           PATH="$(cygpath "${USERPROFILE}")/my-cache/${{ matrix.dir }}/bin:/c/msys64/usr/bin:$PATH"
           cmake --build bld --config '${{ matrix.type }}' --parallel 5
@@ -351,7 +354,7 @@ jobs:
       - name: 'curl version'
         timeout-minutes: 1
         run: |
-          find . -name '*.exe' -o -name '*.dll' | grep -v '/examples/'
+          find . -name '*.exe' -o -name '*.dll'
           PATH="$PWD/bld/lib:$PATH"
           bld/src/curl.exe --disable --version
 
@@ -382,6 +385,12 @@ jobs:
           PATH="$PWD/bld/lib:$PATH:/c/Program Files (x86)/stunnel/bin"
           cmake --build bld --config '${{ matrix.type }}' --target test-ci
 
+      - name: 'cmake build examples'
+        timeout-minutes: 5
+        run: |
+          PATH="$(cygpath "${USERPROFILE}")/my-cache/${{ matrix.dir }}/bin:/c/msys64/usr/bin:$PATH"
+          cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target curl-examples
+
   linux-cross-mingw-w64:
     name: "linux-mingw, ${{ matrix.build == 'cmake' && 'CM' || 'AM' }} ${{ matrix.compiler }}"
     runs-on: ubuntu-latest
@@ -418,9 +427,11 @@ jobs:
 
       - name: 'autotools build'
         if: ${{ matrix.build == 'autotools' }}
-        run: |
-          make -C bld -j5
-          make -C bld -j5 examples
+        run: make -C bld -j5
+
+      - name: 'autotools build examples'
+        if: ${{ matrix.build == 'autotools' }}
+        run: make -C bld -j5 examples
 
       - name: 'cmake configure'
         if: ${{ matrix.build == 'cmake' }}
@@ -431,7 +442,6 @@ jobs:
             -DCMAKE_C_COMPILER=${TRIPLET}-gcc \
             -DCMAKE_UNITY_BUILD=ON \
             -DCURL_WERROR=ON \
-            -DBUILD_EXAMPLES=ON \
             -DCURL_USE_SCHANNEL=ON -DUSE_WIN32_IDN=ON \
             -DCURL_USE_LIBPSL=OFF
 
@@ -443,6 +453,10 @@ jobs:
         if: ${{ matrix.build == 'cmake' }}
         run: cmake --build bld --parallel 5
 
+      - name: 'cmake build examples'
+        if: ${{ matrix.build == 'cmake' }}
+        run: cmake --build bld --parallel 5 --target curl-examples
+
   msvc:
     name: 'msvc, CM ${{ matrix.arch }}-${{ matrix.plat }} ${{ matrix.name }}'
     runs-on: windows-latest
@@ -553,7 +567,6 @@ jobs:
             '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \
             -DCMAKE_UNITY_BUILD=ON \
             -DCURL_WERROR=ON \
-            -DBUILD_EXAMPLES=ON \
             -DENABLE_WEBSOCKETS=ON \
             -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \
             -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE= \
@@ -576,7 +589,7 @@ jobs:
       - name: 'curl version'
         timeout-minutes: 1
         run: |
-          find . -name '*.exe' -o -name '*.dll' | grep -v '/examples/'
+          find . -name '*.exe' -o -name '*.dll'
           if [ '${{ matrix.plat }}' != 'uwp' ]; then
             PATH="$PWD/bld/lib:$PATH"
             bld/src/curl.exe --disable --version
@@ -611,3 +624,7 @@ jobs:
           fi
           PATH="$PWD/bld/lib:$PATH:/c/Program Files (x86)/stunnel/bin:/c/Program Files/OpenSSH-Win64"
           cmake --build bld --config '${{ matrix.type }}' --target test-ci
+
+      - name: 'cmake build examples'
+        timeout-minutes: 5
+        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target curl-examples
index bfcbed8f7ee9c92b35f36e094e5988a61647b446..dd5693bf0c6a98ce14614f06d9fe49198cd24900 100644 (file)
@@ -1782,7 +1782,7 @@ if(BUILD_CURL_EXE)
   add_subdirectory(src)
 endif()
 
-option(BUILD_EXAMPLES "Build libcurl examples" OFF)
+option(BUILD_EXAMPLES "Build libcurl examples" ON)
 if(BUILD_EXAMPLES)
   add_subdirectory(docs/examples)
 endif()
index 692084b1d5fd8fa0b0ffb2f268fa6058355cc454..7237137d990246652b0d412a135f00062e71f18b 100644 (file)
@@ -149,3 +149,10 @@ if [[ "${TFLAGS}" != 'skipall' ]] && \
     )
   fi
 fi
+
+# build examples
+
+if [[ "${EXAMPLES}" = 'ON' ]] && \
+   [ "${BUILD_SYSTEM}" = 'CMake' ]; then
+  cmake --build _bld --config "${PRJ_CFG}" --parallel 2 --target curl-examples
+fi
index 8410ceb073f02b121072440eb04c73e18793f8dd..63fe9c8ca5433c3111ef862fee5f10bc24aaefec 100644 (file)
@@ -36,6 +36,7 @@ environment:
   DEBUG: 'ON'
   SHARED: 'OFF'
   TFLAGS: 'skipall'
+  EXAMPLES: 'OFF'
   matrix:
 
     # generated CMake-based Visual Studio builds
@@ -50,7 +51,7 @@ environment:
       ENABLE_UNICODE: 'OFF'
       HTTP_ONLY: 'OFF'
       SHARED: 'ON'
-    - job_name: 'CMake, VS2008, Debug, x86, Schannel, Build-tests'
+    - job_name: 'CMake, VS2008, Debug, x86, Schannel, Build-tests & examples'
       APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015'
       BUILD_SYSTEM: CMake
       PRJ_GEN: 'Visual Studio 9 2008'
@@ -60,6 +61,7 @@ environment:
       HTTP_ONLY: 'OFF'
       SHARED: 'ON'
       TFLAGS: 'skiprun'
+      EXAMPLES: 'ON'
     - job_name: 'CMake, VS2022, Release, x64, OpenSSL 3.2, WebSockets, Build-only'
       APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022'
       BUILD_SYSTEM: CMake
@@ -84,7 +86,7 @@ environment:
       DEBUG: 'OFF'
       CURLDEBUG: 'ON'
       TFLAGS: 'skiprun'
-    - job_name: 'CMake, VS2010, Debug, x64, Schannel, Static, Build-tests'
+    - job_name: 'CMake, VS2010, Debug, x64, Schannel, Static, Build-tests & examples'
       APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015'
       BUILD_SYSTEM: CMake
       PRJ_GEN: 'Visual Studio 10 2010 Win64'
@@ -93,6 +95,7 @@ environment:
       ENABLE_UNICODE: 'OFF'
       HTTP_ONLY: 'OFF'
       TFLAGS: 'skiprun'
+      EXAMPLES: 'ON'
     - job_name: 'CMake, VS2022, Debug, x64, Schannel, Static, Unicode, Build-only'
       APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022'
       BUILD_SYSTEM: CMake
index ea2b8035c74a7170e85e3cae460585fe5e678358..21c427d12bf577e21d72edaa8055a29aa8192b45 100644 (file)
 #
 ###########################################################################
 
+add_custom_target(curl-examples)
+
 # Get 'check_PROGRAMS' variable
 transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
 
 foreach(_target IN LISTS check_PROGRAMS)
   set(_target_name "curl-example-${_target}")
-  add_executable(${_target_name} "${_target}.c")
+  add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
+  add_dependencies(curl-examples ${_target_name})
   target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_LIBS})
   target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES")
   if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
index 2b11b4868742fe3c034cd1107b4938925ee48986..396aeca97e1845dd48dc276610e463bb282d833b 100644 (file)
@@ -32,6 +32,7 @@
 #include <time.h>
 
 #include <curl/curl.h>
+#include <curl/mprintf.h>
 
 static void
 print_cookies(CURL *curl)
@@ -90,14 +91,11 @@ main(void)
 
     printf("-----------------------------------------------\n"
            "Setting a cookie \"PREF\" via cookie interface:\n");
-#ifdef _WIN32
-#define snprintf _snprintf
-#endif
     /* Netscape format cookie */
-    snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
-             ".example.com", "TRUE", "/", "FALSE",
-             difftime(time(NULL) + 31337, (time_t)0),
-             "PREF", "hello example, i like you!");
+    curl_msnprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
+                   ".example.com", "TRUE", "/", "FALSE",
+                   difftime(time(NULL) + 31337, (time_t)0),
+                   "PREF", "hello example, i like you!");
     res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
     if(res != CURLE_OK) {
       fprintf(stderr, "Curl curl_easy_setopt failed: %s\n",
@@ -110,7 +108,7 @@ main(void)
        modified, likely not what you intended. For more information refer to
        the CURLOPT_COOKIELIST documentation.
     */
-    snprintf(nline, sizeof(nline),
+    curl_msnprintf(nline, sizeof(nline),
       "Set-Cookie: OLD_PREF=3d141414bf4209321; "
       "expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.example.com");
     res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
index 3594ea2760e37c7e444c6f69e5f2c3d8b765277a..e259e149790da83e940da54deedd1df67a6abcc7 100644 (file)
@@ -31,6 +31,7 @@
 
 /* curl stuff */
 #include <curl/curl.h>
+#include <curl/mprintf.h>
 
 #ifndef CURLPIPE_MULTIPLEX
 #error "too old libcurl, cannot do HTTP/2 server push!"
@@ -172,7 +173,7 @@ static int server_push_callback(CURL *parent,
 
   (void)parent; /* we have no use for this */
 
-  snprintf(filename, 128, "push%u", count++);
+  curl_msnprintf(filename, 128, "push%u", count++);
 
   /* here's a new stream, save it in a new file for each new push */
   out = fopen(filename, "wb");
index 379b20dae60a27e4f297ecefe38e7544d06b4c37..93e06099c9b7eea80e1b28f614313a24e77cdce8 100644 (file)
@@ -51,6 +51,9 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
 #if defined(__GNUC__)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wsign-conversion"
+#elif defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:4127)  /* conditional expression is constant */
 #endif
   FD_SET(sockfd, &errfd); /* always check for error */
 
@@ -62,6 +65,8 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
   }
 #if defined(__GNUC__)
 #pragma GCC diagnostic pop
+#elif defined(_MSC_VER)
+#pragma warning(pop)
 #endif
 
   /* select() returns the number of signalled sockets or -1 */
index c5087d9d43885046c9b7b39da978aafec7e0f2d0..fcbb5a4607edc0df87a780f0c198ecc606aeb6ca 100644 (file)
@@ -83,6 +83,10 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site");
     curl_easy_setopt(curl, CURLOPT_HEADERDATA, headerfile);
 
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4127)  /* conditional expression is constant */
+#endif
     do { /* dummy loop, just to break out from */
       if(pEngine) {
         /* use crypto engine */
@@ -133,6 +137,9 @@ int main(void)
 
       /* we are done... */
     } while(0);
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
     /* always cleanup */
     curl_easy_cleanup(curl);
   }