Skip to content

Commit

Permalink
Add CMake build system
Browse files Browse the repository at this point in the history
Supports:
building the library
building executables
testing
generate man page
generate pkg-config file
installing

use older boost for travis so it works in its cmake
  • Loading branch information
dimztimz committed Mar 19, 2019
1 parent c5cef39 commit 8f0713e
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ nuspell-*.tar.gz

# QtCreator https://qt.io
/Makefile.am.user
/CMakeLists.txt.user

# https://vim.sourceforge.io/
.?*.swp
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/Catch2"]
path = external/Catch2
url = https://github.com/catchorg/Catch2.git
24 changes: 10 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ os:

before_install: |
cd ~ &&
wget https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2 -O - |
wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.bz2 -O - |
tar -xj &&
cd -
Expand All @@ -25,39 +25,35 @@ install:
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
echo 'using gcc : : g++-7 : ;' > ~/user-config.jam
fi
- export BOOST_ROOT=~/.local
- export BOOST_ROOT=~/boost_1_64_0
- |
cd ~/boost_1_67_0 &&
./bootstrap.sh --prefix=$BOOST_ROOT --with-libraries=locale --with-toolset="$CC" &&
./b2 install -d0 -j 4 cxxflags=-std=c++14 define=BOOST_LOCALE_HIDE_AUTO_PTR &&
cd ~/boost_1_64_0 &&
./bootstrap.sh --with-libraries=locale --with-toolset="$CC" &&
./b2 -d0 -j 4 cxxflags=-std=c++14 define=BOOST_LOCALE_HIDE_AUTO_PTR &&
cd -
before_script:
- |
case $TRAVIS_OS_NAME in
linux) export LD_LIBRARY_PATH=$BOOST_ROOT/lib ;;
osx) export DYLD_LIBRARY_PATH=$BOOST_ROOT/lib ;;
linux) export LD_LIBRARY_PATH=$BOOST_ROOT/stage/lib ;;
osx) export DYLD_LIBRARY_PATH=$BOOST_ROOT/stage/lib ;;
esac
- |
# On Linux Use gcc-7. On OS X always use clang, dont download gcc from Homebrew.
if [ "$CXX" = "g++" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then
export CXX="g++-7" CC="gcc-7";
fi
- export CPPFLAGS='-DBOOST_LOCALE_HIDE_AUTO_PTR'
#- export CPPFLAGS='-DBOOST_LOCALE_HIDE_AUTO_PTR'

script: autoreconf -i && ./configure && make -j 4 && make check -j 4
script: mkdir build && cd build && cmake .. && make -j 4 && ctest -j 4

after_failure:
- cat tests/v1cmdline/test-suite.log
- cat tests/test-suite.log
- cat Testing/Temporary/LastTest.log

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- autoconf
- automake
- gcc-7
- g++-7
- libicu-dev
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.5)
project(nuspell VERSION 2.2.0)
set(PROJECT_HOMEPAGE_URL "https://nuspell.github.io/")
include(FindPkgConfig)
include(GNUInstallDirs)

pkg_check_modules(ICU REQUIRED icu-uc)
find_package(Boost 1.62.0 REQUIRED COMPONENTS locale)

add_subdirectory(src/hunspell)
add_subdirectory(src/nuspell)

include(CTest)
execute_process(COMMAND git submodule update --init -- external/Catch2
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(external/Catch2)
add_subdirectory(tests)

add_subdirectory(docs)
configure_file(nuspell.pc.in nuspell.pc @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nuspell.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
77 changes: 30 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Main features of Nuspell spell checker and morphological analyzer:

Build-only dependencies:

g++ make autoconf automake libtool pkg-config wget libiconv
g++ make cmake pkg-config git

Runtime dependencies:

Expand All @@ -32,7 +32,7 @@ Runtime dependencies:
Recommended tools for developers:

```
qtcreator clang-format gdb vim doxygen
qtcreator ninja clang-format gdb vim doxygen
```

## Building on GNU/Linux and Unixes
Expand All @@ -41,37 +41,20 @@ We first need to download the dependencies. Some may already be preinstalled.

For Ubuntu and Debian:

sudo apt install g++ autoconf automake make libtool pkg-config \
sudo apt install g++ make cmake pkg-config \
libboost-locale-dev libboost-system-dev libicu-dev

Then run the following commands:

autoreconf -vfi
./configure
mkdir build
cd build
cmake ..
make
sudo make install

<!--sudo ldconfig-->

For speeding up the build process, see also the -j option of make.

<!-- old hunspell v1 stuff
For dictionary development, use the `--with-warnings` option of
configure.
For interactive user interface of Nuspell executable, use the `--with-ui
option`.
Optional developer packages:
- ncurses (need for --with-ui), eg. libncursesw5 for UTF-8
- readline (for fancy input line editing, configure parameter:
--with-readline)
In Ubuntu, the packages are:
libncurses5-dev libreadline-dev
-->
For speeding up the build process, run `make -j`, or use Ninja instead of Make.

## Building on OSX and macOS

Expand All @@ -80,11 +63,11 @@ In Ubuntu, the packages are:
3. Install dependencies

```
brew install autoconf automake libtool pkg-config wget
brew install cmake pkg-config
brew install boost --with-icu4c
```

Then run the standard trio of autoreconf, configure and make. See above.
Then run the standard cmake and make. See above.

If you want to build with GCC instead of Clang, you need to pull GCC with
Homebrew and rebuild all the dependencies with it. See Homewbrew manuals.
Expand All @@ -94,13 +77,18 @@ Homebrew and rebuild all the dependencies with it. See Homewbrew manuals.
### 1\. Compiling with Mingw64 and MSYS2

Download MSYS2, update everything and install the following
packages:
packages:

pacman -S base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-boost \
mingw-w64-x86_64-cmake

pacman -S base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-libtool \
mingw-w64-x86_64-boost
Then from inside the nuspell folder run:

Open Mingw-w64 Win64 prompt and compile the same way as on Linux, see
above.
mkdir build
cd build
cmake .. -G "Unix Makefiles"
make
sudo make install

### 2\. Building in Cygwin environment

Expand All @@ -112,9 +100,9 @@ Cygwin1.dll.

Install the following required packages

autoconf automake libtool pkgconf icu boost-libs
cmake pkgconf icu boost-libs

Then run the standard trio of autoreconf, configure and make. See above.
Then run the standard cmake and make. See above.

# Debugging Nuspell

Expand All @@ -129,31 +117,29 @@ It is recomended to install a debug build of the standard library:
For debugging we need to create a debug build and then we need to start
`gdb`.

./configure CXXFLAGS='-g -O0 -Wall -Wextra -Werror'
make
mkdir debug
cd debug
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j
gdb src/nuspell/nuspell

You can also pass the `CXXFLAGS` directly to `make` without calling
`./configure`, but we don't recommend this way during long development
sessions.

If you like to develop and debug with an IDE, see documentation at
https://github.com/nuspell/nuspell/wiki/IDE-Setup

# Testing

Testing Nuspell (see tests in tests/ subdirectory):

make check
make test

or with Valgrind debugger:

make check
make test
VALGRIND=[Valgrind_tool] make check

For example:

make check
make test
VALGRIND=memcheck make check

# Documentation
Expand Down Expand Up @@ -218,13 +204,10 @@ running:
doxygen

The result can be viewed by opening `doxygen/html/index.html` in a web
browser. Doxygen will use Graphviz for generating all sorts of graphs
and PlantUML for generating UML diagrams. Make sure that the packages
plantuml and graphviz are installed before running Doxygen. The latter
is usually installed automatically when installing Doxygen.
browser.

# Dictionaries

Myspell, Hunspell and Nuspell dictionaries:

https://github.com/nuspell/nuspell/wiki/Dictionaries-and-Contacts
<https://github.com/nuspell/nuspell/wiki/Dictionaries-and-Contacts>
10 changes: 10 additions & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
find_program(RONN ronn)
if (RONN)
add_custom_command(OUTPUT nuspell.1
COMMAND
${RONN} -r --pipe ${CMAKE_CURRENT_SOURCE_DIR}/nuspell.1.md > nuspell.1
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/nuspell.1.md
COMMENT "Building manpage nuspell.1")
add_custom_target(nuspell-man-pages ALL DEPENDS nuspell.1)
install(FILES nuspell.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
endif()
1 change: 1 addition & 0 deletions external/Catch2
Submodule Catch2 added at 03d122
18 changes: 9 additions & 9 deletions nuspell.pc.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: @PACKAGE@
Name: @PROJECT_NAME@
Description: Nuspell spellchecking library
URL: @PACKAGE_URL@
Version: @VERSION@
Libs: -L${libdir} -lnuspell @BOOST_LOCALE_LDFLAGS@ @BOOST_LOCALE_LIBS@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -lnuspell @Boost_LOCALE_LIBRARY@
Requires: icu-uc
Cflags: -I${includedir} @BOOST_CPPFLAGS@
Cflags: -I${includedir} -I@Boost_INCLUDE_DIRS@
9 changes: 9 additions & 0 deletions src/hunspell/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_library(hunspell affentry.cxx affentry.hxx affixmgr.cxx affixmgr.hxx
atypes.hxx baseaffix.hxx csutil.cxx csutil.hxx
filemgr.cxx filemgr.hxx hashmgr.cxx hashmgr.hxx
htypes.hxx hunspell.cxx hunspell.h hunspell.hxx
hunzip.cxx hunzip.hxx langnum.hxx hunvisapi.h
phonet.cxx phonet.hxx replist.cxx replist.hxx
suggestmgr.cxx suggestmgr.hxx utf_info.hxx w_char.hxx)
target_compile_definitions(hunspell PUBLIC HUNSPELL_STATIC)
target_include_directories(hunspell INTERFACE ${PROJECT_SOURCE_DIR}/src)
71 changes: 71 additions & 0 deletions src/nuspell/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
add_library(nuspell
aff_data.cxx aff_data.hxx
dictionary.cxx dictionary.hxx
finder.cxx finder.hxx
locale_utils.cxx locale_utils.hxx
string_utils.hxx
structures.cxx structures.hxx)

target_compile_features(nuspell PUBLIC
cxx_aggregate_default_initializers
cxx_auto_type
cxx_constexpr
cxx_default_function_template_args
cxx_defaulted_functions
cxx_defaulted_move_initializers
cxx_delegating_constructors
cxx_deleted_functions
cxx_extern_templates
cxx_final
cxx_generalized_initializers
cxx_generic_lambdas
cxx_inheriting_constructors
cxx_inline_namespaces
cxx_lambdas
cxx_lambda_init_captures
cxx_noexcept
cxx_nullptr
cxx_override
cxx_range_for
cxx_return_type_deduction
cxx_right_angle_brackets
cxx_rvalue_references
cxx_static_assert
cxx_strong_enums
cxx_thread_local
cxx_trailing_return_types
cxx_unicode_literals
cxx_uniform_initialization
cxx_user_literals
cxx_variable_templates
cxx_variadic_macros
cxx_variadic_templates)

target_include_directories(nuspell
PRIVATE ${ICU_INCLUDE_DIRS}
INTERFACE ${PROJECT_SOURCE_DIR}/src)

target_link_libraries(nuspell
PUBLIC Boost::boost
PRIVATE Boost::locale
PRIVATE ${ICU_LIBRARIES})

install(TARGETS nuspell DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES
aff_data.hxx
dictionary.hxx
finder.hxx
locale_utils.hxx
string_utils.hxx
structures.hxx
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nuspell)

add_executable(nuspell-bin main.cxx)
set_target_properties(nuspell-bin PROPERTIES
OUTPUT_NAME nuspell)
target_link_libraries(nuspell-bin nuspell)

install(TARGETS nuspell-bin DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(verify verify.cxx)
target_link_libraries(verify nuspell hunspell)
2 changes: 1 addition & 1 deletion src/nuspell/verify.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <unistd.h>
#endif

#include "../hunspell/hunspell.hxx"
#include <hunspell/hunspell.hxx>

using namespace std;
using namespace nuspell;
Expand Down
Loading

0 comments on commit 8f0713e

Please sign in to comment.