1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-25 03:41:57 +03:00

cmake: add and test "unity" builds

"Unity" (aka "jumbo", aka "amalgamation" builds concatenate source files
before compiling. It has these benefits for example: faster builds,
improved code optimization, cleaner code. Let's support and test this.

- enable unity builds for some existing CI builds to test this build
  scenario.
- tune `UNITY_BUILD_BATCH_SIZE` size.
- disable unity build for example and test programs (they use one source
  each already).

You can enable it by passing `-DCMAKE_UNITY_BUILD=ON` to cmake.
Supported by CMake 3.16 and newer.

Ref: https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html

Closes #1034
This commit is contained in:
Viktor Szakats
2023-05-07 00:38:55 +00:00
parent cdd7fc009d
commit 7129ea9ca8
5 changed files with 26 additions and 16 deletions

View File

@ -159,7 +159,7 @@ jobs:
shell: msys2 {0}
run: |
if [[ "${{ matrix.env }}" = 'clang'* ]]; then
options='-DCMAKE_C_COMPILER=clang'
options='-DCMAKE_C_COMPILER=clang -DCMAKE_UNITY_BUILD=ON'
else
options='-DCMAKE_C_COMPILER=gcc'
fi
@ -197,13 +197,13 @@ jobs:
strategy:
matrix:
include:
- { arch: x64 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'OFF', zlib: 'OFF' }
- { arch: x64 , plat: windows, crypto: WinCNG , log: 'ON' , shared: 'ON' , zlib: 'OFF' }
- { arch: x64 , plat: windows, crypto: OpenSSL, log: 'OFF', shared: 'ON' , zlib: 'OFF' }
- { arch: x64 , plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' }
- { arch: arm64, plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' }
- { arch: arm64, plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' }
- { arch: x86 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' }
- { arch: x64 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'OFF', zlib: 'OFF', unity: 'OFF' }
- { arch: x64 , plat: windows, crypto: WinCNG , log: 'ON' , shared: 'ON' , zlib: 'OFF', unity: 'OFF' }
- { arch: x64 , plat: windows, crypto: OpenSSL, log: 'OFF', shared: 'ON' , zlib: 'OFF', unity: 'OFF' }
- { arch: x64 , plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF', unity: 'OFF' }
- { arch: arm64, plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF', unity: 'OFF' }
- { arch: arm64, plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF', unity: 'ON' }
- { arch: x86 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF', unity: 'OFF' }
fail-fast: false
steps:
- uses: actions/checkout@v3
@ -217,6 +217,7 @@ jobs:
else
system='Windows'
fi
[ "${{ matrix.unity }}" = 'ON' ] && options="${options} -DCMAKE_UNITY_BUILD=ON"
cmake . -B bld ${options} \
-DCMAKE_SYSTEM_NAME=${system} \
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \
@ -298,6 +299,7 @@ jobs:
if: ${{ matrix.build == 'cmake' }}
run: |
cmake . -B bld ${{ matrix.crypto.cmake }} \
-DCMAKE_UNITY_BUILD=ON \
-DENABLE_WERROR=ON \
-DENABLE_DEBUG_LOGGING=ON \
-DENABLE_ZLIB_COMPRESSION=ON \

View File

@ -50,6 +50,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
project(libssh2 C)
set(CMAKE_UNITY_BUILD_BATCH_SIZE 32)
option(BUILD_STATIC_LIBS "Build Static Libraries" ON)
add_feature_info("Static library" BUILD_STATIC_LIBS
"creating libssh2 static library")

View File

@ -82,14 +82,6 @@ environment:
CRYPTO_BACKEND: "OpenSSL"
SKIP_CTEST: "yes"
- job_name: "VS2010, WinCNG, x64, Build-only"
APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015"
GENERATOR: "Visual Studio 10 2010"
PLATFORM: "x64"
BUILD_SHARED_LIBS: "ON"
CRYPTO_BACKEND: "WinCNG"
SKIP_CTEST: "yes"
- job_name: "VS2008, WinCNG, x86, Build-only"
APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015"
GENERATOR: "Visual Studio 9 2008"
@ -98,6 +90,15 @@ environment:
CRYPTO_BACKEND: "WinCNG"
SKIP_CTEST: "yes"
- job_name: "VS2010, WinCNG, x64, Build-only"
APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015"
GENERATOR: "Visual Studio 10 2010"
PLATFORM: "x64"
BUILD_SHARED_LIBS: "ON"
CRYPTO_BACKEND: "WinCNG"
UNITY: "ON"
SKIP_CTEST: "yes"
- job_name: "VS2022, WinCNG, x64, Server 2019, Logging"
APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022"
GENERATOR: "Visual Studio 17 2022"
@ -167,6 +168,9 @@ build_script:
if($env:UWP -eq "ON") {
$env:CMAKE_ARG += " -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0"
}
if($env:UNITY -eq "ON") {
$env:CMAKE_ARG += " -DCMAKE_UNITY_BUILD=ON"
}
$env:CMAKE_ARG += " -DCMAKE_VS_GLOBALS=TrackFileAccess=false"
# FIXME: First sshd test sometimes timeouts, subsequent ones almost always fail:
# 'libssh2_session_handshake failed (-43): Failed getting banner'

View File

@ -48,6 +48,7 @@ foreach(example ${EXAMPLES})
# to find generated header
target_include_directories(${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ../src)
target_link_libraries(${example} ${LIB_SELECTED} ${LIBRARIES})
set_target_properties(${example} PROPERTIES UNITY_BUILD false)
endforeach()
add_target_to_copy_dependencies(

View File

@ -82,6 +82,7 @@ foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS})
add_executable(${test} ${test}.c)
target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}")
target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include "${CRYPTO_BACKEND_INCLUDE_DIR}")
set_target_properties(${test} PROPERTIES UNITY_BUILD false)
# build a single test with gcov
if(GCOV_PATH AND test STREQUAL test_auth_keyboard_info_request)