diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b0f0561..e9a0b2b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,9 +95,8 @@ jobs: - name: Install dependencies run: | brew update - brew install --formula flatbuffers swig doxygen boost + brew install --formula swig doxygen - name: Cache vcpkg - if: matrix.target != 'macos' uses: actions/cache@v5 with: path: ${{ github.workspace }}/vcpkg_cache @@ -129,6 +128,7 @@ jobs: env: CXXFLAGS: '/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR' # https://github.com/actions/runner-images/issues/10004 DEST: ${{ github.workspace }}/${{ matrix.image }}_${{ matrix.platform }} + VCPKG_ROOT: C:/vcpkg steps: - name: Checkout uses: actions/checkout@v6 @@ -148,15 +148,10 @@ jobs: VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg_cache,readwrite run: | $swig = (Get-Item "$env:LOCALAPPDATA\Microsoft\WinGet\Links\swig.exe").Target - cmake -A ${{ matrix.platform }} -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo ` - "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" ` - "-DSWIG_EXECUTABLE=$swig" ` - -DVCPKG_TARGET_TRIPLET=${{ matrix.platform }}-windows-static-md ` - ${{ matrix.platform == 'x64' && '-DVCPKG_MANIFEST_FEATURES=tests' || '' }} ` - -DCMAKE_INSTALL_LIBDIR=bin - cmake --build build --config RelWithDebInfo - ctest -V -C RelWithDebInfo --test-dir build - cmake --install build --config RelWithDebInfo --prefix ${{ env.DEST }} + $vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath + & "$vsPath\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.platform == 'arm64' && 'amd64_arm64' || 'amd64' }} "&&" pwsh build.ps1 ` + -swig $swig -installdir ${{ env.DEST }} -buildType RelWithDebInfo ` + ${{ matrix.platform == 'x64' && '-RunTests' || '' }} - name: Archive artifacts uses: actions/upload-artifact@v7 with: diff --git a/CMakePresets.json b/CMakePresets.json index 246571a2..744a600e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,13 +6,11 @@ "displayName": "Ninja", "description": "Sets Ninja generator, build and install directory", "generator": "Ninja", - "binaryDir": "${sourceDir}/build", + "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", - "CMAKE_C_COMPILER": "cl.exe", - "CMAKE_CXX_COMPILER": "cl.exe", "VCPKG_MANIFEST_FEATURES": "tests" } }, @@ -27,9 +25,12 @@ "rhs": "Darwin" }, "cacheVariables": { - "CMAKE_OSX_ARCHITECTURES": "arm64", + "CMAKE_OSX_ARCHITECTURES": "arm64;x86_64", "CMAKE_OSX_DEPLOYMENT_TARGET": "14.0", "CMAKE_FIND_ROOT_PATH": "$env{DEST};/opt/homebrew", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_TARGET_TRIPLET": "arm64-x64-osx", + "VCPKG_MANIFEST_FEATURES": "tests", "FRAMEWORK_DESTINATION": "$env{DEST}/lib" }, "installDir": "$env{DEST}" @@ -54,6 +55,7 @@ "inherits": ["mobile", "macos"], "cacheVariables": { "CMAKE_SYSTEM_NAME": "iOS", + "CMAKE_OSX_ARCHITECTURES": "arm64", "CMAKE_OSX_SYSROOT": "${presetName}", "CMAKE_OSX_DEPLOYMENT_TARGET": "16.3", "CMAKE_DISABLE_FIND_PACKAGE_SWIG": "YES" @@ -111,6 +113,17 @@ "CMAKE_ANDROID_ARCH_ABI": "x86_64", "VCPKG_TARGET_TRIPLET": "x64-android" } + }, + { + "name": "windows", + "displayName": "Windows", + "description": "This windows build is only available on Windows", + "binaryDir": "${sourceDir}/build/windows-$env{PLATFORM}", + "cacheVariables": { + "CMAKE_INSTALL_LIBDIR": "bin", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_TARGET_TRIPLET": "$env{PLATFORM}-windows-static-md" + } } ], "buildPresets": @@ -138,6 +151,10 @@ { "name": "androidx86_64", "configurePreset": "androidx86_64" + }, + { + "name": "windows", + "configurePreset": "windows" } ] } diff --git a/README.md b/README.md index ff18baae..07e8108f 100644 --- a/README.md +++ b/README.md @@ -91,15 +91,12 @@ For more information refer [doc/intro.md](doc/intro.md) document. * [Visual Studio Community 2022](https://www.visualstudio.com/downloads/) * [CMake](http://www.cmake.org) * [vcpkg](https://vcpkg.io/) - * [Swig](http://swig.org/download.html) - Optional, for C#, Python and Java bindings + * [Swig](http://swig.org/download.html) - Optional, for C# and Java bindings * [Doxygen](https://www.doxygen.nl/download.html) - Optional, for generating documentation - * [Wix toolset](http://wixtoolset.org/releases/) - Optional, for creating Windows installation packages - * [Python](https://www.python.org/downloads/) - Optional, for Python bindings * [Java](https://www.oracle.com/java/technologies/downloads/) - Optional, for Java bindings 2. Open desired Visual Studio tools command prompt: * x64 Native Tool Command Prompt - * x86 Native Tool Command Prompt * ARM64 Native Tool Command Prompt * Or some cross compile combination with target host type @@ -108,6 +105,16 @@ For more information refer [doc/intro.md](doc/intro.md) document. git clone https://github.com/open-eid/libcdoc.git cd libcdoc -4. Configure and Build +4. Configure, build and install .\build.ps1 + + `build.ps1` drives the `windows` CMake preset with vcpkg. If neither the `-vcpkg` + parameter nor the `VCPKG_ROOT` environment variable points to a vcpkg checkout, one is + cloned automatically. By default it builds the x64 Debug and RelWithDebInfo + configurations. Common options: + + .\build.ps1 -platform arm64 # target ARM64 + .\build.ps1 -RunTests # build and run the unit tests + .\build.ps1 -installdir C:\libcdoc # install after building + .\build.ps1 -generator "Visual Studio 17 2022" # use another CMake generator diff --git a/build.ps1 b/build.ps1 index 414a69fe..73b66117 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,52 +1,46 @@ #powershell -ExecutionPolicy ByPass -File build.ps1 param( [string]$libcdoc = $PSScriptRoot, - [string]$platform = "x64", + [string]$platform = $(if ($null -eq $env:PLATFORM) {"x64"} else {$env:PLATFORM}), [string]$build_number = $(if ($null -eq $env:BUILD_NUMBER) {"0"} else {$env:BUILD_NUMBER}), [string]$git = "git.exe", [string]$vcpkg = $env:VCPKG_ROOT, - [string]$vcpkg_installed = $null, - [string]$vcpkg_installed_platform = $(if($vcpkg_installed) { "$vcpkg_installed\vcpkg_installed_$platform" } else { "$libdigidocpp\build\windows-$platform\vcpkg_installed" }), - [string]$vcpkg_triplet = "$platform-windows", [string]$cmake = "cmake.exe", - [string]$generator = "Visual Studio 17 2022", - [switch]$RunTests = $false, + [string]$generator = "Ninja Multi-Config", + [string]$swig = $null, + [string]$installdir = $null, + [string[]]$buildType = @("Debug", "RelWithDebInfo"), + [switch]$RunTests = $false ) -if(!(Test-Path -Path $vcpkg)) { - $vcpkg = "$libdigidocpp\vcpkg" +if(!$vcpkg -or !(Test-Path -Path $vcpkg)) { + $vcpkg = "$libcdoc\vcpkg" & $git clone https://github.com/microsoft/vcpkg $vcpkg & $vcpkg\bootstrap-vcpkg.bat } $cmakeext = @() -if($platform -eq "arm64" -and $env:VSCMD_ARG_HOST_ARCH -ne "arm64") { - $cmakeext += "-DCMAKE_DISABLE_FIND_PACKAGE_Python3=yes" - $RunTests = $false +if($swig) { + $cmakeext += "-DSWIG_EXECUTABLE=$swig" } if($RunTests) { $cmakeext += "-DVCPKG_MANIFEST_FEATURES=tests" } +if($installdir) { + $cmakeext += "-DCMAKE_INSTALL_PREFIX=$installdir" +} -$buildpath = "build" $env:PLATFORM = $platform $env:VCPKG_ROOT = $vcpkg -& $cmake --fresh -B $buildpath -S . "-G$generator" $cmakeext ` - "--toolchain $vcpkg/scripts/buildsystems/vcpkg.cmake" ` - "-DVCPKG_INSTALLED_DIR=$vcpkg_installed_platform" ` - "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" - -foreach($type in @("Debug", "RelWithDebInfo")) { - "===================" - "Build Configuration: " + $type - "===================" - & $cmake --build $buildpath --config $type -# & $cmake --install $buildpath -} +& $cmake --preset windows --fresh "-G$generator" $cmakeext -if($RunTests) { - Push-Location "$libcdoc\$buildpath" - ctest -V -C Debug - Pop-Location +foreach($type in $buildType) { + & $cmake --build --preset windows --config $type + if($RunTests) { + & $cmake --build --preset windows --config $type --target check + } + if($installdir) { + & $cmake --build --preset windows --config $type --target install + } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 95ac912e..56b1ae3e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,4 +22,4 @@ if(WIN32) ) endif() -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS unittests) +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -C $ --output-on-failure DEPENDS unittests) diff --git a/vcpkg-triplets/arm64-x64-osx.cmake b/vcpkg-triplets/arm64-x64-osx.cmake new file mode 100644 index 00000000..2fe10148 --- /dev/null +++ b/vcpkg-triplets/arm64-x64-osx.cmake @@ -0,0 +1,7 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64 x86_64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_OSX_ARCHITECTURES arm64 x86_64) +set(VCPKG_OSX_DEPLOYMENT_TARGET 14.0) diff --git a/vcpkg.json b/vcpkg.json index 9c354efb..f3866224 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -9,17 +9,14 @@ "default-features": false, "platform": "!osx" }, - { - "name": "flatbuffers", - "platform": "!osx" - }, - { - "name": "openssl", - "platform": "!osx" - } + "flatbuffers", + "openssl" ], "features": { - "tests": { "description": "Build tests", "dependencies": ["boost-test"] } + "tests": { + "description": "Build tests", + "dependencies": [{ "name": "boost-test", "platform": "!ios & !android" }] + } }, "builtin-baseline": "67b5ee32c608c87971eed243d4bff140568ebe53", "vcpkg-configuration": {