Skip to content

Commit

Permalink
Merge branch 'feature/cmake'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoellendorf committed May 20, 2024
2 parents 8861d24 + 35861cc commit 762715c
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 2,979 deletions.
48 changes: 48 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ----------------------------------
# Options affecting listfile parsing
# ----------------------------------
#with section("parse"):

## Specify structure for custom cmake functions
#additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'],
# 'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}}

## Override configurations per-command where available
#override_spec = {}

## Specify variable tags.
#vartags = []

## Specify property tags.
#proptags = []

# -----------------------------
# Options affecting formatting.
# -----------------------------
with section("format"):

# If an argument group contains more than this many sub-groups (parg or kwarg
# groups) then force it to a vertical layout.
max_subgroups_hwrap = 2

# If a positional argument group contains more than this many arguments, then
# force it to a vertical layout.
max_pargs_hwrap = 2

# If a cmdline positional group consumes more than this many lines without
# nesting, then invalidate the layout (and nest)
max_rows_cmdline = 2

# Format keywords consistently as 'lower' or 'upper' case
keyword_case = 'upper'

# ------------------------------------------------
# Options affecting comment reflow and formatting.
# ------------------------------------------------
with section("markup"):

# If comment markup is enabled, don't reflow the first comment block in each
# listfile. Use this to preserve formatting of your copyright/license
# statements.
first_comment_is_literal = True

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
# Autogenerate source file
/test/AllTests.c
/test/testrun
# Files generated by iniparser-meta
CMakeLists.txt
config.cmake.in
# CMake build directories
build*/
html/
105 changes: 105 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
image: registry.gitlab.com/iniparser/docker-cmake:latest

variables:
GIT_SUBMODULE_STRATEGY: recursive
LD_LIBRARY_PATH: ${CI_BUILDS_DIR}/iniparser/iniparser/install/lib/


stages:
- build
- doc
- test
- win

build:
stage: build
script:
- mkdir build
- cd build
- cmake -DCMAKE_INSTALL_PREFIX=../install -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON ..
- make install
- tree -a .
artifacts:
paths:
- install/*
- build/html/*

pages:
stage: doc
dependencies:
- build
script:
- mv build/html/ public/
artifacts:
paths:
- public
#rules:
#- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

test:
stage: test
script:
- pwd
- ls -l
- cd install/bin
- ./testrun
dependencies:
- build

memcheck:
stage: test
script:
- pwd
- ls -l
- cd install/bin
- valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=255 ./testrun
dependencies:
- build

iniexample-memcheck:
stage: test
script:
- pwd
- tree
- cd install/share/doc/iniparser/examples/
- valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=255 ./iniexample
dependencies:
- build

iniwrite-memcheck:
stage: test
script:
- pwd
- tree
- cd install/share/doc/iniparser/examples/
- valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=255 ./iniwrite
dependencies:
- build

parse-memcheck:
stage: test
script:
- pwd
- tree
- cd install/share/doc/iniparser/examples/
- valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=255 ./parse
dependencies:
- build

.shared_windows_runners:
tags:
- saas-windows-medium-amd64

win-build:
extends:
- .shared_windows_runners
stage: win
script:
- mkdir build
- cd build
- cmake -DCMAKE_INSTALL_PREFIX=..\install -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=ON ..
- cmake --build .
artifacts:
paths:
- install
dependencies: []
191 changes: 191 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
cmake_minimum_required(VERSION 3.12)

project(iniparser VERSION 4.2.2)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

option(
BUILD_SHARED_LIBS
"Build using shared libraries"
ON)
option(
BUILD_STATIC_LIBS
"Build using static libraries"
ON)
if(BUILD_SHARED_LIBS)
list(
APPEND
TARGET_TYPES
"shared")
endif()
if(BUILD_STATIC_LIBS)
list(
APPEND
TARGET_TYPES
"static")
endif()
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

foreach(TARGET_TYPE ${TARGET_TYPES})
set(TARGET_NAME "${PROJECT_NAME}-${TARGET_TYPE}")
set(TARGETS_EXPORT_NAME "${TARGET_NAME}Targets")
string(TOUPPER ${TARGET_TYPE} UPPER_TARGET_TYPE)
message(DEBUG "TARGET_TYPE: ${TARGET_TYPE}")
message(DEBUG "UPPER_TARGET_TYPE: ${UPPER_TARGET_TYPE}")
message(DEBUG "TARGET_NAME: ${TARGET_NAME}")
add_library(
${TARGET_NAME}
${UPPER_TARGET_TYPE}
"src/iniparser.c"
"src/dictionary.c")
set(PUBLIC_HEADERS "src/iniparser.h" "src/dictionary.h")
set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER
"${PUBLIC_HEADERS}")

target_include_directories(
${TARGET_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>)
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION
${PROJECT_VERSION_MAJOR})

if(UNIX)
target_compile_options(
${TARGET_NAME}
PRIVATE -fPIC
-Wall
-Wextra
-pedantic)
endif(UNIX)

# install targets
install(
TARGETS ${TARGET_NAME}
EXPORT ${TARGETS_EXPORT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})

# build directory package config
export(
TARGETS ${TARGET_NAME}
APPEND
FILE "${TARGETS_EXPORT_NAME}.cmake")

# installed package config
install(EXPORT ${TARGETS_EXPORT_NAME} DESTINATION "${CONFIG_INSTALL_DIR}")
endforeach()

# installed package config
set(PROJECT_CONFIG_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake")
set(PROJECT_VERSION_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")

configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/config.cmake.in ${PROJECT_CONFIG_FILE}
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}")
# generate package version file
write_basic_package_version_file(
${PROJECT_VERSION_FILE}
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
# install version and config file
install(FILES ${PROJECT_VERSION_FILE} ${PROJECT_CONFIG_FILE}
DESTINATION ${CONFIG_INSTALL_DIR})
file(
GLOB
FIND_MODULES
"${PROJECT_SOURCE_DIR}/cmake/Find*.cmake")
message(DEBUG "Find modules: ${FIND_MODULES}")
install(FILES ${FIND_MODULES} DESTINATION ${CONFIG_INSTALL_DIR})
# make available in build directory for user package registry dependants
file(COPY ${FIND_MODULES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
# add to CMake registry
export(PACKAGE ${PROJECT_NAME})
# generate pc-file
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/pc.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
@ONLY)
# install pc-file
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

option(BUILD_TESTS "Build and install tests")
if(BUILD_TESTS)
set(TEST_NAME testrun)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/AllTests.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/test_dictionary.c
${CMAKE_CURRENT_SOURCE_DIR}/test/test_iniparser.c
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test/make-tests.sh >
${CMAKE_CURRENT_BINARY_DIR}/AllTests.c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/)

add_executable(
${TEST_NAME}
${CMAKE_CURRENT_BINARY_DIR}/AllTests.c
${CMAKE_CURRENT_SOURCE_DIR}/test/CuTest.c
${CMAKE_CURRENT_SOURCE_DIR}/test/test_dictionary.c
${CMAKE_CURRENT_SOURCE_DIR}/test/test_iniparser.c)

target_link_libraries(${TEST_NAME} "${PROJECT_NAME}-static")

target_include_directories(
${TEST_NAME}
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>)

install(TARGETS ${TEST_NAME})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/ressources
DESTINATION ${CMAKE_INSTALL_BINDIR})

enable_testing()
add_test(
NAME testsuite
COMMAND ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()

option(BUILD_EXAMPLES "Build and install examples")
if(BUILD_EXAMPLES)
add_executable(iniexample ${CMAKE_CURRENT_SOURCE_DIR}/example/iniexample.c)
add_executable(iniwrite ${CMAKE_CURRENT_SOURCE_DIR}/example/iniwrite.c)
add_executable(parse ${CMAKE_CURRENT_SOURCE_DIR}/example/parse.c)

foreach(TARGET_TYPE ${TARGET_TYPES})
# if BUILD_STATIC_WITH_SHARED_LIBS=ON shared takes precedence
target_link_libraries(iniexample ${PROJECT_NAME}-${TARGET_TYPE})
target_link_libraries(iniwrite ${PROJECT_NAME}-${TARGET_TYPE})
target_link_libraries(parse ${PROJECT_NAME}-${TARGET_TYPE})
endforeach()
install(
TARGETS iniexample
iniwrite
parse
DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples/)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/example/twisted.ini
DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples/)
endif()

option(
BUILD_DOCS
"Build and install docs"
ON)
if(BUILD_DOCS)
find_package(Doxygen REQUIRED)
set(DOXYGEN_STRIP_FROM_PATH ${CMAKE_CURRENT_SOURCE_DIR})
doxygen_add_docs(
docs
${CMAKE_CURRENT_SOURCE_DIR}/doc/iniparser.txt
${CMAKE_CURRENT_SOURCE_DIR}/src/iniparser.h
ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()
Loading

0 comments on commit 762715c

Please sign in to comment.