Skip to content

Commit

Permalink
add installer to CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Sep 27, 2024
1 parent c6181ad commit b4af22c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .github/scripts/windows-agent-compile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ else {

cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=On -DWINDOWS=On -DBUILD_FROM_CACHE=On -S. -DVCPKG_CRT_LINKAGE=dynamic -DBUILD_SHARED_LIBS=OFF -Bbuild_windows

Write-Host "build agent and tests"

Write-Host "------------- build agent and installer ---------------"

cmake --build build_windows --config Release

35 changes: 16 additions & 19 deletions .github/workflows/windows-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ concurrency:

on:
workflow_dispatch:
inputs:
installer_in_artifact:
description: 'Save installer and binary in artifacts'
required: true
default: false
type: boolean
unit_test:
description: 'run unit tests'
required: true
default: true
type: boolean

pull_request:
paths:
- agent/**
Expand Down Expand Up @@ -52,36 +64,21 @@ jobs:
shell: powershell

- name: Common test
if: inputs.unit_test == true
run: |
cd build_windows
tests/ut_common
- name: Agent test
if: inputs.unit_test == true
run: |
cd build_windows
tests/ut_agent
- name: Zip agent
run: |
$files_to_compress = "agent\conf\centagent.reg", "build_windows\agent\Release\centagent.exe"
Compress-Archive -Path $files_to_compress -DestinationPath centreon-monitoring-agent.zip
- name: Save agent package in cache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: centreon-monitoring-agent.zip
key: ${{ github.run_id }}-${{ github.sha }}-CMA-${{ github.head_ref || github.ref_name }}
enableCrossOsArchive: ${{ true }}

- name: Upload package artifacts
if: |
github.event_name != 'workflow_dispatch' &&
contains(fromJson('["stable"]'), needs.get-version.outputs.stability) &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
if: inputs.installer_in_artifact == true
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
name: packages-centreon-monitoring-agent-windows
path: centreon-monitoring-agent.zip
path: agent\installer\centreon-monitoring-agent.exe
retention-days: 1
3 changes: 3 additions & 0 deletions agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ else()
absl::any absl::log absl::base absl::bits
Boost::program_options
fmt::fmt)

add_subdirectory(installer)

endif()


Expand Down
46 changes: 43 additions & 3 deletions agent/installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,49 @@
# For more information : [email protected]
#

project("Centreon agent Installer")


# Set directories.
set(SRC_DIR "${PROJECT_SOURCE_DIR}/installer")
set(CENTAGENT_PATH_OUTPUT_DIR ${Centreon\ agent_BINARY_DIR})

if( ${CMAKE_GENERATOR} MATCHES "Visual Studio.*" )
set(CENTAGENT_PATH "${Centreon\ agent_BINARY_DIR}/${CMAKE_BUILD_TYPE}/centagent.exe")
else()
set(CENTAGENT_PATH "${Centreon\ agent_BINARY_DIR}/centagent.exe")
endif()

string(REPLACE "/" "\\" CENTAGENT_PATH "${CENTAGENT_PATH}")

#uncomment if makensis is not in the path
set(MKNSIS "C:/Program Files (x86)/NSIS/Bin/makensis.exe")

#set(MKNSIS "makensis.exe")

# Configure files.
configure_file("${SRC_DIR}/version.nsi.in"
"${SRC_DIR}/version.nsi")
configure_file("${PROJECT_SOURCE_DIR}/version.nsi.in" "${PROJECT_SOURCE_DIR}/version.nsi")

file(GLOB COMMON_INSTALLERS_FILES "${PROJECT_SOURCE_DIR}/version.nsi" "${PROJECT_SOURCE_DIR}/dlg_helper.nsi" "${PROJECT_SOURCE_DIR}/resources/*")

message(NOTICE "---------------- Generate installer in ${PROJECT_SOURCE_DIR} ---------------")

# modify binary called from the application manager
# embedded in installer
add_custom_command(
DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.nsi" ${COMMON_INSTALLERS_FILES} ${CENTREON_AGENT}
COMMENT "--------- Generating cma configuration modifier --------"
OUTPUT "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.exe"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMAND ${MKNSIS} "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.nsi")


#final installer
add_custom_command(
DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.nsi" "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.exe" ${COMMON_INSTALLERS_FILES}
COMMENT "--------- Generating cma configuration installer --------"
OUTPUT "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.exe"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMAND ${MKNSIS} "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.nsi")

add_custom_target("centreon-monitoring-agent-installer" ALL DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.exe")

5 changes: 1 addition & 4 deletions agent/installer/centreon-monitoring-agent.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,8 @@ Section "Centreon Monitoring Agent" CMAInstSection
; even if service is stopped, process can be stopping so we wait a little more
Sleep 500

;file "..\..\build_windows\agent\Release\centagent.exe"
file "..\..\build_windows\agent\centagent.exe"
file ${CENTAGENT_PATH}
file "centreon-monitoring-agent-modify.exe"
;file "..\..\build_msdev\agent\centagent.exe"
;file "..\..\build_msdev\agent\*.dll"
writeUninstaller "$INSTDIR\uninstall.exe"


Expand Down
3 changes: 2 additions & 1 deletion agent/installer/version.nsi.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@

!define VERSIONMAJOR ${COLLECT_MAJOR}
!define VERSIONMINOR ${COLLECT_MINOR}
!define VERSIONBUILD ${COLLECT_PATCH}
!define VERSIONBUILD ${COLLECT_PATCH}
!define CENTAGENT_PATH "${CENTAGENT_PATH}"

0 comments on commit b4af22c

Please sign in to comment.