Merge pull request #7079 from Icinga/tools/windows

Build Windows with Visual Studio 2017
This commit is contained in:
Michael Friedrich 2019-04-05 16:38:12 +02:00 committed by GitHub
commit 6a298615e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 167 additions and 138 deletions

View File

@ -27,9 +27,6 @@ option (USE_SYSTEMD
set(HAVE_SYSTEMD ${USE_SYSTEMD})
file(STRINGS VERSION VERSION_LINE REGEX "^Version: ")
string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE})
include(GNUInstallDirs)
include(InstallConfig)
include(SetFullDir)
@ -104,15 +101,36 @@ else()
string(SUBSTRING ${SPEC_REVISION} 10 ${SPEC_REVISION_LENGTH} SPEC_REVISION)
set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}")
set(ICINGA2_VERSION "${SPEC_VERSION}")
else()
# use GIT version as ICINGA2_VERSION
string(REGEX REPLACE "^[rv]" "" ICINGA2_VERSION "${GIT_VERSION}")
endif()
configure_file(icinga-version.h.cmake icinga-version.h)
endif()
# NuGet on Windows requires a semantic versioning, example: 2.10.4.123 (only 4 element, only numeric)
string(REGEX REPLACE "-([0-9]+).*$" ".\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION}")
if(WIN32)
set(Boost_USE_STATIC_LIBS ON)
add_definitions(-DBOOST_ALL_NO_LIB)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
# Disabled for linking issues for newer Boost versions, they link against Windows SDKs
#add_definitions(-DBOOST_ALL_NO_LIB)
# Disable optimization for Boost::context
# https://www.boost.org/doc/libs/1_69_0/libs/context/doc/html/context/overview.html
# https://docs.microsoft.com/en-us/cpp/build/reference/gl-whole-program-optimization?view=vs-2017
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /GL- /EHs")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /GL- /EHs")
# detect if 32-bit target
if(CMAKE_VS_PLATFORM_NAME STREQUAL "Win32")
# SAFESEH is not supported in Boost on Windows x86
# maybe it is when Boost is compiled with it...
# https://lists.boost.org/Archives/boost/2013/10/206720.php
# https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers?view=vs-2017
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
endif()
endif()
if(NOT DEFINED LOGROTATE_HAS_SU)
@ -386,7 +404,7 @@ endif()
set(CPACK_PACKAGE_NAME "Icinga 2")
set(CPACK_PACKAGE_VENDOR "Icinga GmbH")
set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION})
set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION_SAFE})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")

View File

@ -5,7 +5,6 @@ if(MSVC)
icinga2setupagent
${CMAKE_CURRENT_SOURCE_DIR}/windows-setup-agent/Icinga2SetupAgent.csproj
TYPE FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
PLATFORM Win32
)
install(

View File

@ -3,7 +3,7 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<ProjectGuid>{A86F1159-66E8-4BDB-BF28-A2BDAF76517C}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
@ -65,6 +65,43 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'RelWithDebInfo|Win32' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\RelWithDebInfo\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'MinSizeRel|Win32' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\MinSizeRel\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
@ -203,11 +240,11 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@ -1,18 +1,20 @@
---
version: 2.9.0.dev.{build}
version: 2.11.0.dev.{build}
os: Visual Studio 2017
platform: x64
environment:
BITS: 64
CMAKE_BUILD_TYPE: Debug
CMAKE_GENERATOR: "Visual Studio 15 2017 Win64"
VSCMD_VER: 15.0
# https://www.appveyor.com/docs/windows-images-software/#boost
BOOST_ROOT: 'C:\Libraries\boost_1_66_0'
BOOST_LIBRARYDIR: 'C:\Libraries\boost_1_66_0\lib64-msvc-14.1'
BOOST_ROOT: 'C:\Libraries\boost_1_67_0'
BOOST_LIBRARYDIR: 'C:\Libraries\boost_1_67_0\lib64-msvc-14.1'
# https://www.appveyor.com/docs/windows-images-software/#tools
OPENSSL_ROOT_DIR: 'C:\OpenSSL-v111-Win64'
BISON_BINARY: 'C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_bison.exe'
FLEX_BINARY: 'C:\ProgramData\chocolatey\lib\winflexbison3\tools\win_flex.exe'
CMAKE_BUILD_TYPE: Debug
branches:
only:
@ -33,32 +35,21 @@ install:
# https://help.appveyor.com/discussions/questions/18777-how-to-use-vcvars64bat-from-powershell#comment_44999171
before_build:
- ps: |
$bits = $env:PLATFORM -replace "^x", ""
cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars${bits}.bat`" && set > `"${env:TEMP}\vcvars.txt`""
Get-Content "$env:TEMP\vcvars.txt" | Foreach-Object {
if ($_ -match "^(VSCMD.*?)=(.*)$") {
Set-Content ("env:" + $matches[1]) $matches[2]
}
}
& .\tools\win32\load-vsenv.ps1
if (-not (Test-Path ".\build\vendor\OpenSSL")) {
& .\tools\win32\download-openssl.ps1
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
}
& .\tools\win32\configure.ps1
& powershell.exe .\tools\win32\configure.ps1
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
del build\Icinga*.msi
build_script:
- ps: |
& .\tools\win32\build.ps1
& powershell.exe .\tools\win32\build.ps1
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
test_script:
- ps: |
& .\tools\win32\test.ps1
& powershell.exe .\tools\win32\test.ps1
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
# Disable until we really need them

View File

@ -8,7 +8,7 @@ if(WIN32)
add_custom_target(choco-pkg ALL
COMMAND choco pack
COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/icinga2.${SPEC_VERSION}.nupkg ${CMAKE_CURRENT_BINARY_DIR}/icinga2.nupkg
COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/icinga2.${ICINGA2_VERSION_SAFE}.nupkg ${CMAKE_CURRENT_BINARY_DIR}/icinga2.nupkg
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/icinga2.nuspec ${CMAKE_CURRENT_BINARY_DIR}/chocolateyInstall.ps1 chocolateyUninstall.ps1
)
endif()

View File

@ -1,7 +1,7 @@
$packageName = 'icinga2'
$installerType = 'msi'
$url32 = 'https://packages.icinga.com/windows/Icinga2-v${SPEC_VERSION}-x86.msi'
$url64 = 'https://packages.icinga.com/windows/Icinga2-v${SPEC_VERSION}-x86_64.msi'
$url32 = 'https://packages.icinga.com/windows/Icinga2-v${ICINGA2_VERSION_SAFE}-x86.msi'
$url64 = 'https://packages.icinga.com/windows/Icinga2-v${ICINGA2_VERSION_SAFE}-x86_64.msi'
$silentArgs = '/qn /norestart'
$validExitCodes = @(0)

View File

@ -6,7 +6,7 @@
<!-- Read this before publishing packages to chocolatey.org: https://github.com/chocolatey/chocolatey/wiki/CreatePackages -->
<id>icinga2</id>
<title>Icinga 2</title>
<version>${SPEC_VERSION}</version>
<version>${ICINGA2_VERSION_SAFE}</version>
<authors>Icinga GmbH</authors>
<owners>Icinga GmbH</owners>
<summary>icinga2 - Monitoring Agent for Windows</summary>

View File

@ -30,7 +30,7 @@ struct pageFileInfo
static bool l_Debug;
BOOL EnumPageFilesProc(LPVOID pContext, PENUM_PAGE_FILE_INFORMATION pPageFileInfo, LPCTSTR lpFilename) {
BOOL EnumPageFilesProc(LPVOID pContext, PENUM_PAGE_FILE_INFORMATION pPageFileInfo, LPCWSTR lpFilename) {
std::vector<pageFileInfo>* pageFile = static_cast<std::vector<pageFileInfo>*>(pContext);
SYSTEM_INFO systemInfo;
@ -199,10 +199,11 @@ static int printOutput(printInfoStruct& printInfo)
static int check_swap(printInfoStruct& printInfo)
{
PENUM_PAGE_FILE_CALLBACK pageFileCallback = &EnumPageFilesProc;
// Needs explicit cast: http://msinilo.pl/blog2/post/p1348/
PENUM_PAGE_FILE_CALLBACKW pageFileCallback = (PENUM_PAGE_FILE_CALLBACKW)EnumPageFilesProc;
std::vector<pageFileInfo> pageFiles;
if(!EnumPageFiles(pageFileCallback, &pageFiles)) {
if(!EnumPageFilesW(pageFileCallback, &pageFiles)) {
printErrorInfo();
return 3;
}

View File

@ -1,7 +1,13 @@
Set-PsDebug -Trace 1
if (-not (Test-Path env:ICINGA2_BUILDPATH)) {
$env:ICINGA2_BUILDPATH = '.\build'
}
if (-not (Test-Path env:CMAKE_BUILD_TYPE)) {
$env:CMAKE_BUILD_TYPE = 'RelWithDebInfo'
}
if (-not (Test-Path $env:ICINGA2_BUILDPATH)) {
Write-Host "Path '$env:ICINGA2_BUILDPATH' does not exist!"
exit 1
@ -14,5 +20,8 @@ if (-not ($env:PATH -contains $env:CMAKE_PATH)) {
$env:PATH = $env:CMAKE_PATH + ';' + $env:PATH
}
cmake.exe --build "$env:ICINGA2_BUILDPATH" --target PACKAGE --config RelWithDebInfo
cmake.exe --build "$env:ICINGA2_BUILDPATH" --target ALL_BUILD --config $env:CMAKE_BUILD_TYPE
if ($lastexitcode -ne 0) { exit $lastexitcode }
cmake.exe --build "$env:ICINGA2_BUILDPATH" --target PACKAGE --config $env:CMAKE_BUILD_TYPE
if ($lastexitcode -ne 0) { exit $lastexitcode }

View File

@ -1,3 +1,5 @@
Set-PsDebug -Trace 1
if (-not (Test-Path env:ICINGA2_BUILDPATH)) {
$env:ICINGA2_BUILDPATH = '.\build'
}
@ -8,40 +10,23 @@ if (-not (Test-Path env:CMAKE_BUILD_TYPE)) {
if (-not (Test-Path "$env:ICINGA2_BUILDPATH")) {
mkdir "$env:ICINGA2_BUILDPATH" | out-null
}
if (-not (Test-Path "$env:ICINGA2_BUILDPATH\install")) {
mkdir "$env:ICINGA2_BUILDPATH\install" | out-null
}
if (-not (Test-Path env:CMAKE_PATH)) {
$env:CMAKE_PATH = 'C:\Program Files\CMake\bin'
}
if (-not ($env:PATH -contains $env:CMAKE_PATH)) {
$env:PATH = $env:CMAKE_PATH + ';' + $env:PATH
}
if (-not (Test-Path env:CMAKE_GENERATOR)) {
$env:CMAKE_GENERATOR = 'Visual Studio 15 2017 Win64'
}
if (-not (Test-Path env:OPENSSL_ROOT_DIR)) {
if (Test-Path env:VSCMD_ARG_TGT_ARCH) {
$OpenSSL_arch = $env:VSCMD_ARG_TGT_ARCH
} else {
throw "Missing env variable VSCMD_ARG_TGT_ARCH"
}
if (Test-Path env:VSCMD_VER) {
$VSmajor = $env:VSCMD_VER -replace "\..*$", ""
$OpenSSL_vcbuild = "vc${VSmajor}0"
} else {
throw "Missing env variable VSCMD_VER"
}
$env:OPENSSL_ROOT_DIR = "$env:ICINGA2_BUILDPATH\vendor\OpenSSL-$OpenSSL_arch-$OpenSSL_vcbuild"
$env:OPENSSL_ROOT_DIR = 'c:\local\OpenSSL_1_1_1b-Win64'
}
if (-not (Test-Path env:BOOST_ROOT)) {
$env:BOOST_ROOT = 'c:\local\boost_1_65_1'
$env:BOOST_ROOT = 'c:\local\boost_1_69_0-Win64'
}
if (-not (Test-Path env:BOOST_LIBRARYDIR)) {
$env:BOOST_LIBRARYDIR = 'c:\local\boost_1_65_1\lib64-msvc-14.1'
$env:BOOST_LIBRARYDIR = 'c:\local\boost_1_69_0-Win64\lib64-msvc-14.1'
}
if (-not (Test-Path env:FLEX_BINARY)) {
$env:FLEX_BINARY = 'C:\ProgramData\chocolatey\bin\win_flex.exe'
@ -63,11 +48,12 @@ if (Test-Path CMakeCache.txt) {
& cmake.exe "$sourcePath" `
-DCMAKE_BUILD_TYPE="$env:CMAKE_BUILD_TYPE" `
-G $env:CMAKE_GENERATOR -DCPACK_GENERATOR=WIX `
-G "$env:CMAKE_GENERATOR" -DCPACK_GENERATOR=WIX `
-DICINGA2_WITH_MYSQL=OFF -DICINGA2_WITH_PGSQL=OFF `
-DICINGA2_WITH_LIVESTATUS=OFF -DICINGA2_WITH_COMPAT=OFF `
-DOPENSSL_ROOT_DIR="$env:OPENSSL_ROOT_DIR" `
-DBOOST_ROOT="$env:BOOST_ROOT" `
-DBOOST_LIBRARYDIR="$env:BOOST_LIBRARYDIR" `
-DBOOST_INCLUDEDIR="$env:BOOST_ROOT" `
-DFLEX_EXECUTABLE="$env:FLEX_BINARY" `
-DBISON_EXECUTABLE="$env:BISON_BINARY"

View File

@ -1,76 +0,0 @@
$ErrorActionPreference = "Stop"
$OpenSSL_version = '1.1.0g-1'
if (Test-Path env:VSCMD_ARG_TGT_ARCH) {
$OpenSSL_arch = $env:VSCMD_ARG_TGT_ARCH
} else {
throw "Missing env variable VSCMD_ARG_TGT_ARCH"
}
if (Test-Path env:VSCMD_VER) {
$VSmajor = $env:VSCMD_VER -replace "\..*$", ""
$OpenSSL_vcbuild = "vc${VSmajor}0"
} else {
throw "Missing env variable VSCMD_VER"
}
$OpenSSL_fileversion = $OpenSSL_version.Replace('.', '_').Split('-')[0]
$OpenSSL_file = [string]::Format(
'openssl-{0}-binary-icinga-{1}-{2}.zip',
$OpenSSL_fileversion,
$OpenSSL_arch,
$OpenSSL_vcbuild
)
$OpenSSL_url = [string]::Format(
'https://github.com/Icinga/openssl-windows/releases/download/v{0}/{1}',
$OpenSSL_version,
$OpenSSL_file
)
if (-not (Test-Path env:ICINGA2_BUILDPATH)) {
$env:ICINGA2_BUILDPATH = '.\build'
}
$vendor_path = $env:ICINGA2_BUILDPATH + '\vendor'
$OpenSSL_zip_location = $env:ICINGA2_BUILDPATH + '\vendor\' + $OpenSSL_file
$OpenSSL_vendor_path = "$vendor_path\OpenSSL-$OpenSSL_arch-$OpenSSL_vcbuild"
# Tune Powershell TLS protocols
$AllProtocols = [System.Net.SecurityProtocolType]'Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
if (-not (Test-Path $env:ICINGA2_BUILDPATH)) {
mkdir $env:ICINGA2_BUILDPATH | out-null
}
if (-not (Test-Path $vendor_path)) {
mkdir $vendor_path | out-null
}
if (Test-Path $OpenSSL_zip_location) {
Write-Output "OpenSSL archive available at $OpenSSL_zip_location"
} else {
Write-Output "Downloading OpenSSL binary dist from $OpenSSL_url"
$progressPreference = 'silentlyContinue'
Invoke-WebRequest -Uri $OpenSSL_url -OutFile $OpenSSL_zip_location
$progressPreference = 'Continue'
if (Test-Path $OpenSSL_vendor_path) {
Remove-Item -Recurse $OpenSSL_vendor_path
}
}
if (-not (Test-Path $OpenSSL_vendor_path)) {
mkdir $OpenSSL_vendor_path | out-null
Write-Output "Extracting ZIP to $OpenSSL_vendor_path"
Add-Type -AssemblyName System.IO.Compression.FileSystem
$pwd = Get-Location
[System.IO.Compression.ZipFile]::ExtractToDirectory(
(Join-Path -path $pwd -childpath $OpenSSL_zip_location),
(Join-Path -path $pwd -childpath $OpenSSL_vendor_path)
)
if ($lastexitcode -ne 0){ exit $lastexitcode }
} else {
Write-Output "OpenSSL is already available at $OpenSSL_vendor_path"
}

View File

@ -0,0 +1,58 @@
# why that env handling, see
# https://help.appveyor.com/discussions/questions/18777-how-to-use-vcvars64bat-from-powershell#comment_44999171
Set-PsDebug -Trace 1
$SOURCE = Get-Location
if (Test-Path env:ICINGA2_BUILDPATH) {
$BUILD = $env:ICINGA2_BUILDPATH
} else {
$BUILD = "${SOURCE}\Build"
}
if (-not (Test-Path $BUILD)) {
mkdir $BUILD | Out-Null
}
if (Test-Path env:VS_INSTALL_PATH) {
$VSBASE = $env:VS_INSTALL_PATH
} else {
$VSBASE = "C:\Program Files (x86)\Microsoft Visual Studio\2017"
}
if (Test-Path env:BITS) {
$bits = $env:BITS
} else {
$bits = 64
}
# Execute vcvars in cmd and store env
$vcvars_locations = @(
"${VSBASE}\BuildTools\VC\Auxiliary\Build\vcvars${bits}.bat",
"${VSBASE}\Community\VC\Auxiliary\Build\vcvars${bits}.bat"
)
$vcvars = $null
foreach ($file in $vcvars_locations) {
if (Test-Path $file) {
$vcvars = $file
break
}
}
if ($vcvars -eq $null) {
throw "Could not get Build environment script at locations: ${vcvars_locations}"
}
cmd.exe /c "call `"${vcvars}`" && set > `"${BUILD}\vcvars.txt`""
if ($LastExitCode -ne 0) {
throw "Could not load Build environment from: ${vcvars}"
}
# Load environment for PowerShell
Get-Content "${BUILD}\vcvars.txt" | Foreach-Object {
if ($_ -match "^(VSCMD.*?)=(.*)$") {
Set-Content ("env:" + $matches[1]) $matches[2]
}
}

View File

@ -1,7 +1,13 @@
Set-PsDebug -Trace 1
if (-not (Test-Path env:ICINGA2_BUILDPATH)) {
$env:ICINGA2_BUILDPATH = 'build'
}
if (-not (Test-Path env:CMAKE_BUILD_TYPE)) {
$env:CMAKE_BUILD_TYPE = 'RelWithDebInfo'
}
[string]$pwd = Get-Location
if (-not (Test-Path $env:ICINGA2_BUILDPATH)) {
@ -18,7 +24,7 @@ if (-not ($env:PATH -contains $env:CMAKE_PATH)) {
cd "$env:ICINGA2_BUILDPATH"
ctest.exe -C RelWithDebInfo -T test -O $env:ICINGA2_BUILDPATH/Test.xml --output-on-failure
ctest.exe -C "${env:CMAKE_BUILD_TYPE}" -T test -O $env:ICINGA2_BUILDPATH/Test.xml --output-on-failure
if ($lastexitcode -ne 0) {
cd ..
exit $lastexitcode