chore(build): add cmake build system and windows ci job#523
chore(build): add cmake build system and windows ci job#523somethingwithproof wants to merge 23 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
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.txtthat buildsspineand generatesconfig/config.hviaconfigure_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) |
There was a problem hiding this comment.
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.
| add_compile_options(-Wall) | |
| if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang)$") | |
| add_compile_options(-Wall) | |
| endif() |
CMakeLists.txt
Outdated
| if(WIN32) | ||
| target_link_libraries(spine PRIVATE ws2_32 iphlpapi advapi32) | ||
| else() | ||
| target_link_libraries(spine PRIVATE m dl) |
There was a problem hiding this comment.
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.
| target_link_libraries(spine PRIVATE m dl) | |
| target_link_libraries(spine PRIVATE m ${CMAKE_DL_LIBS}) |
There was a problem hiding this comment.
Fixed. Using CMAKE_DL_LIBS.
CMakeLists.txt
Outdated
| 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}") |
There was a problem hiding this comment.
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.
| 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() |
There was a problem hiding this comment.
Fixed. Parsing --libs into NETSNMP_LIBRARIES and NETSNMP_LDFLAGS separately.
| /* Net-SNMP */ | ||
| #cmakedefine SNMP_LOCALNAME @SNMP_LOCALNAME@ | ||
|
|
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Fixed. Added CheckCSourceCompiles test for snmp_session.localname.
| 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 | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
d36fb77 to
7c94f7e
Compare
Summary
CMakeLists.txt
Mirrors configure.ac feature checks:
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