-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Extopts is a C library that helps to quickly build your C-applications with sane standardized CLI.
In other words, it does same thing as getopt but with more declarative interface and more features. Similar to glib approach but BSD-licensed and still more features.
This library has two main methods of using in your project: pkgconfig- and cmake-based.
Note: in this tutorial it is assumed that extopts & extmods are
used with C-applications compiled for C99 standart (option -std=c99
for gcc). Using with C90-programs presumably will not cause any issues
but may (or may not) bring a couple of warnings with compilation flags
-Wall -pedantic
.
To link against extopts with simple makefile one can use compiler flags taken from
pkg-config --libs --cflags extopts
For example:
CC = gcc
CFLAGS += `pkg-config --cflags extopts`
LIBS += `pkg-config --libs extopts`
$(CC) $(CFLAGS) $(LIBS) main.c
CMake-based project can use extopts by including following lines into CMakeLists.txt:
find_package (extopts)
include_directories (${EXTOPTS_INCLUDE_DIR})
target_link_libraries (${PROJECT} ${EXTOPTS_LIBRARY})
So minimal cmake project will be:
cmake_minimum_required (VERSION 2.8)
set (PROJECT "myprj")
project (${PROJECT})
add_executable (${PROJECT} main.c)
find_package (extopts)
include_directories (${EXTOPTS_INCLUDE_DIR})
target_link_libraries (${PROJECT} ${EXTOPTS_LIBRARY})
Extopts is based on cmake build system. Full build and package install can be done with next sequence of actions:
-
get latest code from git
git clone [email protected]:githaff/extopts.git
-
change directory into downloaded sources
cd extopts
-
prepare cmake build
cmake .
To specify target install path use option -DCMAKE_INSTALL_PREFIX=/usr.
Option -DDISABLE_SHARED=ON allows to prevents shared library from being built.
Release build configuration can be selected with -DCMAKE_BUILD_TYPE=Release. So full prepare command for building distributed binaries packages will look somewhat like:
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release
-
build binaries
make
-
install binaries into system (must be runned with root priveleges)
make install
Version information is stored within latest git tag or .version file if present. To prepare distribution in form of source code package command
make dist
can be used. It will create tar.gz-package without git info but with correct version info.
Warning: Using github releases is prohibited since it doesn't carry version info and thus it will be assumed to be 0.0.0.
Extopts source code contains fully working example which is not built by default. To compile it one should prepare package as described above and then compile example itself with command:
make example
Usage key features explained on code samples are presented at usage page. For more thorough description of library functionality see API page.