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

Improve cmake build system #90

Merged
merged 6 commits into from
Oct 31, 2018
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
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ addons:
- libusb-1.0-0-dev
- libbz2-dev
- libgnutls-dev
- libcurl4-gnutls-dev
- gettext

before_install:
# libcurl4-gnutls-dev should be installed after git clone because this package breaks git clone with following error:
# fatal: unable to access 'https://github.com/das-labor/neopg.git/': server certificate verification failed. CAfile: none CRLfile: none
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y libcurl4-gnutls-dev; fi

matrix:
include:
- compiler: gcc
Expand Down Expand Up @@ -276,6 +280,7 @@ install:
brew link --force gettext
# Already installed: cmake boost
else
git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt # This is needed because libcurl4-gnutls-dev pkgs breaks git clone with a certificate error.
git clone https://github.com/randombit/botan.git
(cd botan;
git checkout 2.3.0;
Expand Down
38 changes: 13 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ if(BUILD_DOC)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()

set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/src/Doxyfile.in)
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/neopg-tool/Doxyfile.in)
sphinxc0re marked this conversation as resolved.
Show resolved Hide resolved
set(DOXYFILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

configure_file(${DOXYFILE_IN} ${DOXYFILE} @ONLY)
Expand All @@ -140,26 +140,23 @@ if(BUILD_DOC)
endif()

find_package(PkgConfig)
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
pkg_check_modules(BOTAN2 REQUIRED botan-2)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
pkg_check_modules(GNUTLS REQUIRED gnutls)
pkg_check_modules(sqlite REQUIRED IMPORTED_TARGET sqlite3)
pkg_check_modules(botan-2 REQUIRED IMPORTED_TARGET botan-2)
pkg_check_modules(libusb-1.0 REQUIRED IMPORTED_TARGET libusb-1.0)
pkg_check_modules(gnutls REQUIRED IMPORTED_TARGET gnutls)
lambdafu marked this conversation as resolved.
Show resolved Hide resolved

find_package(CURL REQUIRED)
find_package(Boost COMPONENTS locale date_time REQUIRED)

# Example how to test for header files and functions with cmake:
# include(CheckIncludeFiles)
# check_include_files(malloc.h HAVE_MALLOC_H)
# include (CheckFunctionExists)
# check_function_exists (log HAVE_LOG)
# check_function_exists (exp HAVE_EXP)
find_package(CURL REQUIRED)
find_package(Threads)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/neopg-tool/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

add_subdirectory(${CMAKE_SOURCE_DIR}/legacy)
add_subdirectory(${CMAKE_SOURCE_DIR}/lib)
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
add_subdirectory(neopg)
add_subdirectory(legacy)
add_subdirectory(neopg-tool)
sphinxc0re marked this conversation as resolved.
Show resolved Hide resolved

install(EXPORT neopg NAMESPACE neopg:: DESTINATION lib/cmake/neopg)

# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES
Expand Down Expand Up @@ -197,12 +194,3 @@ add_custom_target(
COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
)


#if(CMAKE_COMPILER_IS_GNUCXX)
# target_compile_options(foo
# PUBLIC -fno-...)
#endif()
#target_compile_features(foo
#PUBLIC cxx_auto_type
#PRIVATE
#cxx_variadic_templates)
47 changes: 28 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,30 @@ With all dependencies installed NeoPG can be build with CMake.

```bash
$ git submodule update --init
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make test # opt: ARGS=-V or CTEST_OUTPUT_ON_FAILURE=1
$ cmake -H. -Bbuild
$ cmake --build build
$ cmake --build build --target test # opt: ARGS=-V or CTEST_OUTPUT_ON_FAILURE=1
```
To install (default is /usr/local)

```bash
$ cmake --build build --target install
```

To change default installation, set cmake parameter `CMAKE_INSTALL_PREFIX` for example:

```bash
$ cmake -H. -Build -DCMAKE_INSTALL_PREFIX=<path>
```

Select your compiler and language version by setting CXX and CXXSTD
environment variables, e.g.:

```bash
$ CXX=clang++-5 CXXSTD=14 cmake ..
$ CXX=clang++-5 CXXSTD=14 cmake -H. -Bbuild
```
or set cmake parameter `CMAKE_CXX_COMPILER` `CMAKE_CXX_STANDARD`


### Legacy support

Expand Down Expand Up @@ -120,18 +131,18 @@ Development builds have extra dependencies:
To enable a debug build, set the CMAKE_BUILD_TYPE flag (default is `Release`):

```bash
# cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON ..
# make coverage
$ cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON ..
$ cmake --build build --target coverage
```

Other targets:

```
$ make pretty # Run clang-format on all source files
$ make lint # Run cppcheck
$ make coverage # Just coverage.info for codecov.io
$ make coverage-html # Local HTML report
$ make coverage-data # Cobertura XML report
$ cmake --build build --target pretty # Run clang-format on all source files
$ cmake --build build --target lint # Run cppcheck
$ cmake --build build --target coverage # Just coverage.info for codecov.io
$ cmake --build build --target coverage-html # Local HTML report
$ cmake --build build --target coverage-data # Cobertura XML report
sphinxc0re marked this conversation as resolved.
Show resolved Hide resolved
```

## TODO
Expand Down Expand Up @@ -176,9 +187,8 @@ $ sudo dnf install -y \

# Clone repo and build
$ git clone --recursive git@github.com:das-labor/neopg.git
$ cd neopg/build
$ cmake ..
$ make
$ cmake -Hneopg -Bneopg/build
lambdafu marked this conversation as resolved.
Show resolved Hide resolved
$ cmake --build neopg/build
```

### macOS
Expand All @@ -202,9 +212,8 @@ Build it!
```
# Clone repo and build
$ git clone --recursive git@github.com:das-labor/neopg.git
$ cd neopg/build
$ cmake ..
$ make
$ cmake -Hneopg -Bneopg/build
$ cmake --build neopg/build
```

Have fun!
Loading