Skip to content

Commit

Permalink
Merge pull request #29 from abelcheung/cmake-migration
Browse files Browse the repository at this point in the history
build: Retire autotools and switch to cmake, closes #21
  • Loading branch information
abelcheung authored Nov 24, 2023
2 parents 7bfae10 + 3838090 commit bc93121
Show file tree
Hide file tree
Showing 17 changed files with 1,195 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ insert_final_newline = true
charset = utf-8
indent_style = space

[*.{c,h,txt}]
[*.{c,h,txt,cmake}]
indent_size = 4

[configure.ac]
Expand Down
53 changes: 23 additions & 30 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,50 @@ jobs:
if_true: '--enable-static'
if_false: '--disable-static'

- name: Install dependencies
# cmake pulls ninja by default
- name: Install dependencies (MSYS)
if: matrix.os == 'windows-2022'
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.msystem }}
update: true
install: >-
markdown
groff
git
pacboy: >-
autotools:p
gcc:p
libxml2:p
iconv:p
toolchain:p
glib2:p
7zip:p
cmake:p
- name: Install dependencies
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-22.04'
run: >
sudo apt-get install -y
build-essential
automake
cmake
ninja-build
libglib2.0-dev
libxml2-utils
- name: Install dependencies
- name: Install dependencies (MacOS)
if: matrix.os == 'macos-12'
run: |
brew install automake
brew install cmake ninja
# env only useful for MSYS2
- name: Pre-build
env:
WANT_AUTOCONF: latest
WANT_AUTOMAKE: latest
run: >-
autoreconf -f -i -v
&& ./configure ${{ steps.static_flag.outputs.value }}
run: |
mkdir build
cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release
- name: Build
run: make all

- name: Test suite
run: make check

- name: Source dist check
if: matrix.os == 'ubuntu-22.04'
run: make distcheck
run: |
cmake --build build -v
- name: Windows binary dist check
if: matrix.os == 'windows-2022'
run: make -f dist-win.mk dist-win
- name: Test prefixed install
run: |
cmake --install build --prefix inst --strip -v
- name: CTest
env:
MSYS2_PATH_TYPE: inherit
run: |
cd build && ctest --output-on-failure -V
53 changes: 53 additions & 0 deletions .github/workflows/cmake_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CMake compatibility check

on:
workflow_dispatch:

jobs:
check:
strategy:
fail-fast: false
matrix:
cmake_ver:
- 3.27.7
- 3.26.5
- 3.25.3
- 3.24.4
- 3.23.5
- 3.22.6
- 3.21.7
- 3.20.6
- 3.19.8
- 3.18.6
- 3.17.5
- 3.16.9
- 3.15.7
- 3.14.7
- 3.13.5
- 3.12.4
- 3.11.4
- 3.10.3
- 3.9.6
- 3.8.2
- 3.7.2
- 3.6.3
- 3.5.2
- 3.4.3
- 3.3.2
- 3.2.3
- 3.1.3
- 3.0.2
runs-on: macos-12
steps:
- uses: actions/checkout@v4

- uses: lukka/get-cmake@latest
with:
cmakeVersion: ${{ matrix.cmake_ver }}
ninjaVersion: latest

- name: Check cmake invocation
run: |
mkdir build
cmake -S . -B build -G Ninja
52 changes: 8 additions & 44 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
**/*.exe
**/*.o
**/.deps
**/Makefile
**/Makefile.in
/.dirstamp

# IDE or editor files
/.vscode
/ABOUT-NLS
/aclocal.m4
/autom4te.cache
/compile
/config.cache
/config.guess
/config.h
/config.h.in
/config.log
/config.rpath
/config.status
/config.sub
/configure
/depcomp
/install-sh
/m4
/missing
/mkinstalldirs
/po/*.gmo
/po/*.header
/po/*.mo
/po/*.pot
/po/*.sed
/po/insert-header.sin
/po/Makefile.in.in
/po/Makevars.template
/po/POTFILES
/po/remove-potcdate.sin
/po/Rules-quot
/po/stamp-it
/po/stamp-po
/src/rifiuti
/src/rifiuti-vista
/stamp-h1
/test/atconfig
/test/atlocal
/test/package.m4
/test/testsuite
/test/testsuite.dir
/test/testsuite.log
/test/test_glib_iconv
/.idea
**/*.bak
**/*~

# CMake
/build*
87 changes: 87 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
cmake_minimum_required(VERSION 3.17 FATAL_ERROR) # cmake -E rm

project(rifiuti2
VERSION 0.7.0
HOMEPAGE_URL https://github.com/abelcheung/rifiuti2/
LANGUAGES C)

if(NOT WIN32)
include(GNUInstallDirs)
endif()

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb -Wall")
set(CMAKE_STATIC_LINKER_FLAGS "-static")
configure_file(config.h.in config.h)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED "glib-2.0 >= 2.40.0")

# Do static build in Windows, which require finding
# extra libraries
if (WIN32)
pkg_check_modules(ICONV REQUIRED "iconv")
list(APPEND GLIB_STATIC_CFLAGS_OTHER -DGLIB_STATIC_COMPILATION)
endif()

foreach(bin rifiuti rifiuti-vista)
add_executable(
${bin}
src/${bin}.c
src/${bin}.h
)
target_include_directories(
${bin} BEFORE
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)
target_sources(
${bin}
PRIVATE
src/utils.c
src/utils.h
)
if(WIN32)
target_sources(${bin} PRIVATE src/utils-win.c src/utils-win.h)
target_include_directories(${bin} PRIVATE
${GLIB_STATIC_INCLUDE_DIRS} ${ICONV_STATIC_INCLUDE_DIRS})
target_compile_options (${bin} PRIVATE
${GLIB_STATIC_CFLAGS_OTHER} ${ICONV_STATIC_CFLAGS_OTHER})
target_link_libraries (${bin} PRIVATE authz
${GLIB_STATIC_LIBRARIES} ${ICONV_STATIC_LIBRARIES})
target_link_directories (${bin} PRIVATE
${GLIB_STATIC_LIBRARY_DIRS} ${ICONV_STATIC_LIBRARY_DIRS})
target_link_options (${bin} BEFORE PRIVATE ${CMAKE_STATIC_LINKER_FLAGS})
else()
target_include_directories(${bin} PRIVATE ${GLIB_INCLUDE_DIRS})
target_compile_options (${bin} PRIVATE ${GLIB_CFLAGS_OTHER})
target_link_libraries (${bin} PRIVATE ${GLIB_LIBRARIES})
target_link_directories (${bin} PRIVATE ${GLIB_LIBRARY_DIRS})
endif()
endforeach()

install(
TARGETS
rifiuti
rifiuti-vista
RUNTIME
)
if(NOT WIN32)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/rifiuti.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
)
endif()
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/LICENSE
${CMAKE_CURRENT_SOURCE_DIR}/NEWS.md
${CMAKE_CURRENT_SOURCE_DIR}/README.md
${CMAKE_CURRENT_SOURCE_DIR}/docs/THANKS.txt
TYPE DOC
)

include(CTest)
add_subdirectory(test)
5 changes: 5 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#cmakedefine PROJECT_NAME "@PROJECT_NAME@"
#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"
#cmakedefine PROJECT_HOMEPAGE_URL "@PROJECT_HOMEPAGE_URL@"

#define G_LOG_DOMAIN PROJECT_NAME
10 changes: 4 additions & 6 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#if HAVE_SETLOCALE
#include <locale.h>
#endif
#include "utils.h"
#include <glib/gi18n.h>
#include <glib/gstdio.h>
Expand Down Expand Up @@ -749,7 +747,7 @@ rifiuti_setup_opt_ctx (GOptionContext **context,

bug_report_str = g_strdup_printf (
/* TRANSLATOR COMMENT: argument is bug report webpage */
_("Report bugs to %s"), PACKAGE_BUGREPORT);
_("Report bugs to %s"), PROJECT_HOMEPAGE_URL);
g_option_context_set_description (*context, bug_report_str);
g_free (bug_report_str);

Expand Down Expand Up @@ -1393,13 +1391,13 @@ move_temp_file (void)
void
print_version_and_exit (void)
{
fprintf (stdout, "%s %s\n", PACKAGE, VERSION);
fprintf (stdout, "%s %s\n", PROJECT_NAME, PROJECT_VERSION);
/* TRANSLATOR COMMENT: %s is software name */
fprintf (stdout, _("%s is distributed under the "
"BSD 3-Clause License.\n"), PACKAGE);
"BSD 3-Clause License.\n"), PROJECT_NAME);
/* TRANSLATOR COMMENT: 1st argument is software name, 2nd is official URL */
fprintf (stdout, _("Information about %s can be found on\n\n\t%s\n"),
PACKAGE, PACKAGE_URL);
PROJECT_NAME, PROJECT_HOMEPAGE_URL);

exit (R2_OK);
}
Expand Down
Loading

0 comments on commit bc93121

Please sign in to comment.