Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Cmake as a build system #53

Merged
merged 14 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
version: 2
jobs:
fedora40:
fedora40_cmake:
working_directory: ~/libreadtags
docker:
- image: docker.io/fedora:40
steps:
- run:
name: Install Git
command: |
yum -y install git
- checkout
- run:
name: Install build tools
command: |
yum -y install gcc cmake
- run:
name: Build
command: |
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build
cmake --build build --target readtags
- run:
name: Install
command: |
cmake --build build --target install
test -e /usr/local/include/readtags.h
test -e /usr/local/lib/libreadtags.so
fedora40_autotools:
working_directory: ~/libreadtags
docker:
- image: docker.io/fedora:40
Expand Down Expand Up @@ -51,5 +77,6 @@ workflows:
version: 2
build_and_test:
jobs:
- fedora40
- fedora40_cmake
- fedora40_autotools
- fedora40_distcheck
62 changes: 62 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.22)
project(
readtags
#
# Synchronize VERSION with the value in configure.ac.
VERSION 0.3.0
DESCRIPTION "a library for looking up tag entries in tag files"
HOMEPAGE_URL "https://github.com/universal-ctags/libreadtags"
LANGUAGES C
)

set(CMAKE_C_STANDARD 99)

option(LIBREADTAGS_BUILD_SHARED "Build shared/static library" OFF)

# You don't have to edit API_VERSION.
# See https://cmake.org/cmake/help/latest/command/cmake_file_api.html
set(API_VERSION 1)
#
# Synchronize BUILD_VERSION with the value appended to libreadtags.so.<>.
# that is built with Autotools.
set(BUILD_VERSION 1.1.2)

if (LIBREADTAGS_BUILD_SHARED)
message(STATUS "Building shared library")
add_library(${PROJECT_NAME} SHARED readtags.c)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${BUILD_VERSION}
SOVERSION ${API_VERSION}
PUBLIC_HEADER readtags.h
)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
else ()
message(STATUS "Building static library")
add_library(${PROJECT_NAME} STATIC readtags.c)
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
endif ()

add_library(universal-ctags::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
#
# TODO:
#
# * Support find_package
#
# ParticleG's comments quoted from
# https://github.com/universal-ctags/libreadtags/pull/51#issuecomment-2148017962
#
# Actually, if we prepare CMakeList.txt properly, other CMake projects
# just need to use find_package method to load this package, see
# Finding Packages. But if you use CMake method FetchContent to add
# libreadtags to your project, then current changes should be enough.
#
# * Running test cases
#
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 0.4.0

- support cmake as a build system (ParticleG <[email protected]>)

# Version 0.3.0

- fix calls to ctype functions (Colomban Wendling <[email protected]>)
Expand Down
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# libreadtags

libreadtags is a library for reading tags files generated by ctags.
libreadtags assumes the tags file format explained in [tags(5)](https://docs.ctags.io/en/latest/man/tags.5.html)
of Universal-ctags.
Expand All @@ -10,3 +12,58 @@ NEWS.md describes note worty changes.
If you are looking for command line interface for tags files,
you will like [readtags command](https://docs.ctags.io/en/latest/man/readtags.1.html)
shipped as part of Universal-ctags. It uses libreadtags extensively.

You can build libreadtags with GNU Autotools and CMake.

## Autotools Usage

### Build
```shell
test -e autogen.sh && ./autogen.sh
./configure
make
```

### Test
```shell
make check
```


## CMake Usage

### Build as a standalone project

#### Configure and build only

```shell
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build
cmake --build build --target readtags
```

#### Configure and install

This will install the library and headers to `/usr/local`.

```shell
mkdir build
cmake -DCMAKE_BUILD_TYPE=Release -DLIBREADTAGS_BUILD_SHARED=ON -S . -B build
sudo cmake --build build --target install
```

### Integrate into other CMake projects

```cmake
include(FetchContent)

FetchContent_Declare(
readtags
GIT_REPOSITORY https://github.com/universal-ctags/libreadtags.git
GIT_TAG master
)

FetchContent_MakeAvailable(readtags)

target_link_libraries(your_target PRIVATE universal-ctags::readtags)
```
12 changes: 11 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- Autoconf -*-
#
# When updating the above version, you also update VERSION in CMakeList.txt.
AC_INIT(libreadtags, 0.3.0)
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([readtags.c])
Expand All @@ -8,7 +10,8 @@ AC_PROG_LIBTOOL

# LT_VERSION => CURRENT[:REVISION[:AGE]]
#
# (the following instructions are taken from configure.ac in libskk)
# (the following instructions are taken from configure.ac in libskk
# See also "7 Library interface versions" in the libtool info document.)
#
# If library source has changed since last release, increment revision
# If public symbols have been added, removed or changed since last release,
Expand All @@ -20,20 +23,27 @@ AC_PROG_LIBTOOL
#
# 0:0:0
# initial version; API is the same as readtags.h in Exuberant-ctags.
# (libreadtags.so.0.0.0)
#
# 1:0:0
# introduced tagsGetErrno() and tagErrno.
# rename sortType to tagSortType.
# (libreadtags.so.1.0.0)
#
# 2:0:1
# introduced TagErrnoFileMayTooBig.
# introduced tagsFindPseudoTag.
# (libreadtags.so.1.1.0)
#
# 2:1:1
# no change in public interface.
# (libreadtags.so.1.1.1)
#
# 2:2:1
# no change in public interface.
# (libreadtags.so.1.1.2)
#
# When updating LT_VERSION, update BUILD_VERSION of CMakeLists.txt.
#
AC_SUBST(LT_VERSION, [2:2:1])

Expand Down
Loading