Skip to content

chore(build): add cmake build system and windows ci job#523

Open
somethingwithproof wants to merge 23 commits intoCacti:developfrom
somethingwithproof:feat/windows-ci-cmake
Open

chore(build): add cmake build system and windows ci job#523
somethingwithproof wants to merge 23 commits intoCacti:developfrom
somethingwithproof:feat/windows-ci-cmake

Conversation

@somethingwithproof
Copy link
Copy Markdown
Contributor

Summary

  • Add CMakeLists.txt as a cross-platform build alternative to autotools
  • Add Windows CI job using MSYS2/MinGW-w64 with crash dump collection
  • Add Linux CMake CI job to verify CMake parity with autotools
  • No C source files modified

CMakeLists.txt

Mirrors configure.ac feature checks:

  • C99 standard, generates config/config.h via configure_file()
  • Header checks: sys/socket.h, sys/select.h, sys/wait.h, netinet/in.h, etc.
  • Function checks: malloc, calloc, gettimeofday, strerror, strtoll
  • MySQL/MariaDB detection via pkg-config with manual fallback
  • Net-SNMP detection via pkg-config, then net-snmp-config, then manual find
  • Configurable RESULTS_BUFFER (2048), MAX_SIMULTANEOUS_SCRIPTS (20), MAX_MYSQL_BUF_SIZE (131072)
  • Platform-specific linking: ws2_32/iphlpapi/advapi32 on Windows, m/dl elsewhere

CI Changes

Existing autotools and flawfinder jobs are unchanged. Two new jobs added:

build-cmake-linux: Ubuntu, gcc/clang matrix, cmake + ninja. Validates CMake produces the same build as autotools.

build-windows: windows-latest, MSYS2/MINGW64 with MariaDB, Net-SNMP, OpenSSL. Configures Windows Error Reporting to capture crash dumps as CI artifacts on failure.

The Windows build will likely fail until the platform abstraction layer is implemented. This is intentional: the CI output provides the exact compiler errors needed to guide the porting work.

Test plan

  • Linux autotools job passes (unchanged)
  • Linux CMake job compiles spine successfully
  • Windows job attempts build and reports errors (expected at this stage)
  • Flawfinder job passes (unchanged)

Copilot AI review requested due to automatic review settings April 8, 2026 06:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a CMake-based build path and CI coverage to validate CMake builds on Linux and start surfacing Windows porting errors early, without touching the existing C sources.

Changes:

  • Introduces a top-level CMakeLists.txt that builds spine and generates config/config.h via configure_file().
  • Adds a CMake config header template (config/config.h.cmake.in) to mirror key autotools feature macros.
  • Extends GitHub Actions CI with Linux CMake builds and a Windows MSYS2/MinGW build job (plus artifact upload/crash-dump plumbing).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
config/config.h.cmake.in New CMake-driven config.h template for feature macros and build-time constants.
CMakeLists.txt New CMake build definition for dependency detection, config generation, build, and install.
.github/workflows/ci.yml Adds Linux CMake job and Windows MSYS2/MinGW job; minor whitespace cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

CMakeLists.txt Outdated
option(ENABLE_WARNINGS "Enable -Wall compiler warnings" ON)

if(ENABLE_WARNINGS)
add_compile_options(-Wall)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENABLE_WARNINGS currently adds -Wall unconditionally for any compiler. This will break builds with non-GNU/Clang toolchains (e.g., MSVC) and can also affect cross-compilers. Consider gating this by CMAKE_C_COMPILER_ID (GNU/Clang) and/or applying it via target_compile_options(spine ...) so it’s scoped to the target.

Suggested change
add_compile_options(-Wall)
if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang)$")
add_compile_options(-Wall)
endif()

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

CMakeLists.txt Outdated
if(WIN32)
target_link_libraries(spine PRIVATE ws2_32 iphlpapi advapi32)
else()
target_link_libraries(spine PRIVATE m dl)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-Windows branch always links dl (target_link_libraries(spine PRIVATE m dl)). libdl doesn’t exist on macOS and some other Unix-like platforms, so this will cause link failures there (autotools only adds -ldl when it’s available). Consider using CMAKE_DL_LIBS and/or probing for dlclose before linking dl.

Suggested change
target_link_libraries(spine PRIVATE m dl)
target_link_libraries(spine PRIVATE m ${CMAKE_DL_LIBS})

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Using CMAKE_DL_LIBS.

CMakeLists.txt Outdated
Comment on lines +161 to +178
OUTPUT_VARIABLE NETSNMP_CFLAGS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${NETSNMP_CONFIG} --libs
OUTPUT_VARIABLE NETSNMP_LIBS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(NETSNMP_FOUND TRUE)
# Parse cflags into include dirs
string(REPLACE " " ";" _snmp_cflags_list "${NETSNMP_CFLAGS_RAW}")
set(NETSNMP_INCLUDE_DIRS "")
foreach(_flag ${_snmp_cflags_list})
if(_flag MATCHES "^-I(.*)")
list(APPEND NETSNMP_INCLUDE_DIRS "${CMAKE_MATCH_1}")
endif()
endforeach()
set(NETSNMP_LDFLAGS "${NETSNMP_LIBS_RAW}")
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the net-snmp-config fallback path, NETSNMP_LIBRARIES is never set, and the raw --libs output is passed via target_link_options. Using link options for -l... libraries is fragile (ordering/"as-needed" issues) and differs from the pkg-config/manual-find paths that use target_link_libraries. Consider parsing NETSNMP_LIBS_RAW into a proper libraries list and populating NETSNMP_LIBRARIES (and only keep true linker flags in target_link_options), and also check execute_process result codes before marking Net-SNMP as found.

Suggested change
OUTPUT_VARIABLE NETSNMP_CFLAGS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${NETSNMP_CONFIG} --libs
OUTPUT_VARIABLE NETSNMP_LIBS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(NETSNMP_FOUND TRUE)
# Parse cflags into include dirs
string(REPLACE " " ";" _snmp_cflags_list "${NETSNMP_CFLAGS_RAW}")
set(NETSNMP_INCLUDE_DIRS "")
foreach(_flag ${_snmp_cflags_list})
if(_flag MATCHES "^-I(.*)")
list(APPEND NETSNMP_INCLUDE_DIRS "${CMAKE_MATCH_1}")
endif()
endforeach()
set(NETSNMP_LDFLAGS "${NETSNMP_LIBS_RAW}")
RESULT_VARIABLE NETSNMP_CFLAGS_RESULT
OUTPUT_VARIABLE NETSNMP_CFLAGS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${NETSNMP_CONFIG} --libs
RESULT_VARIABLE NETSNMP_LIBS_RESULT
OUTPUT_VARIABLE NETSNMP_LIBS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NETSNMP_CFLAGS_RESULT EQUAL 0 AND NETSNMP_LIBS_RESULT EQUAL 0)
set(NETSNMP_FOUND TRUE)
# Parse cflags into include dirs
string(REPLACE " " ";" _snmp_cflags_list "${NETSNMP_CFLAGS_RAW}")
set(NETSNMP_INCLUDE_DIRS "")
foreach(_flag ${_snmp_cflags_list})
if(_flag MATCHES "^-I(.*)")
list(APPEND NETSNMP_INCLUDE_DIRS "${CMAKE_MATCH_1}")
endif()
endforeach()
# Parse libs into link libraries and true linker flags
separate_arguments(_snmp_libs_list UNIX_COMMAND "${NETSNMP_LIBS_RAW}")
set(NETSNMP_LIBRARIES "")
set(NETSNMP_LDFLAGS "")
foreach(_flag ${_snmp_libs_list})
if(_flag MATCHES "^-l.+")
list(APPEND NETSNMP_LIBRARIES "${_flag}")
elseif(IS_ABSOLUTE "${_flag}")
list(APPEND NETSNMP_LIBRARIES "${_flag}")
else()
list(APPEND NETSNMP_LDFLAGS "${_flag}")
endif()
endforeach()
endif()

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Parsing --libs into NETSNMP_LIBRARIES and NETSNMP_LDFLAGS separately.

Comment on lines +67 to +69
/* Net-SNMP */
#cmakedefine SNMP_LOCALNAME @SNMP_LOCALNAME@

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SNMP_LOCALNAME is declared here, but the CMake build doesn’t currently detect or set it (unlike configure.ac, which compiles a test and defines it to 0/1). As a result, CMake builds will always compile the snmp_session.localname code path as disabled, reducing feature parity. Consider adding the corresponding compile check in CMakeLists.txt and setting SNMP_LOCALNAME accordingly (or dropping the macro from this template until the check exists).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Added CheckCSourceCompiles test for snmp_session.localname.

Comment on lines +125 to +155
build-windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

- uses: msys2/setup-msys2@d44ca8e88d8b43d56cf71b6e8e17253983e8e4f7
with:
msystem: MINGW64
update: true
install: >-
mingw-w64-x86_64-gcc
mingw-w64-x86_64-cmake
mingw-w64-x86_64-ninja
mingw-w64-x86_64-libmariadbclient
mingw-w64-x86_64-net-snmp
mingw-w64-x86_64-openssl
pkg-config

- name: Configure
run: |
mkdir build && cd build
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
..

- name: Build
run: cmake --build build

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description notes the Windows build is expected to fail for now, but as written this job failing will fail the entire workflow and block merges if CI is required. If the intent is to collect compiler errors without gating, consider marking this job continue-on-error: true (or otherwise making it non-blocking) until the Windows port is in place.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Added continue-on-error: true.

- Add CMakeLists.txt mirroring configure.ac feature checks
- Add config/config.h.cmake.in template for cmake builds
- Add build-cmake-linux CI job (gcc/clang matrix)
- Add build-windows CI job (MSYS2/MinGW-w64, continue-on-error)
- Windows crash dump collection via WER LocalDumps
- Gate -Wall by compiler ID (GNU/Clang vs MSVC)
- Use CMAKE_DL_LIBS instead of hardcoded -ldl
- Parse net-snmp-config --libs into proper NETSNMP_LIBRARIES
- Add SNMP_LOCALNAME compile check for feature parity
- No C source files modified

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof
Copy link
Copy Markdown
Contributor Author

Review note: rebase on #524 after that lands — the platform_*.c files duplicate the shims #524 adds. Consider squashing or explicit acknowledgement of the overlap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants