cmake magick to make package usable and discoverable by another CMake projects, readme, pkgbuild
This commit is contained in:
parent
7377f13534
commit
f5612dc3c5
@ -1,17 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(lmdbal VERSION 0.2.0 LANGUAGES CXX)
|
||||
project(LMDBAL VERSION 0.2.0 LANGUAGES CXX)
|
||||
string(TOLOWER ${PROJECT_NAME} PROJECT_LOW)
|
||||
|
||||
cmake_policy(SET CMP0076 NEW)
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
|
||||
option(BUILD_STATIC "Builds library as static library" ON)
|
||||
option(BUILD_TESTS "Builds tests" ON)
|
||||
option(BUILD_STATIC "Builds library as static library" OFF)
|
||||
option(BUILD_TESTS "Builds tests" OFF)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||
@ -29,31 +30,64 @@ if (NOT CMAKE_BUILD_TYPE)
|
||||
endif ()
|
||||
|
||||
if (BUILD_STATIC)
|
||||
add_library(lmdbal STATIC ${SOURCES})
|
||||
add_library(${PROJECT_NAME} STATIC)
|
||||
else ()
|
||||
add_library(lmdbal SHARED ${SOURCES})
|
||||
add_library(${PROJECT_NAME} SHARED)
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${version})
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION 1)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY
|
||||
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION 1)
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY
|
||||
COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION
|
||||
)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
if (BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif ()
|
||||
|
||||
target_include_directories(lmdbal PUBLIC ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(lmdbal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(lmdbal PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
|
||||
target_include_directories(lmdbal PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_LOW}>"
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(lmdbal
|
||||
PRIVATE
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
lmdb
|
||||
)
|
||||
target_link_libraries(lmdbal PRIVATE lmdb)
|
||||
|
||||
install(TARGETS lmdbal
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}Config.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LOW}
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}ConfigVersion.cmake"
|
||||
VERSION "${version}"
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_LOW}Targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/lmdbal
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lmdbal
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_LOW}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_LOW}
|
||||
)
|
||||
|
||||
install(EXPORT ${PROJECT_LOW}Targets
|
||||
FILE ${PROJECT_LOW}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LOW}
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}Config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}ConfigVersion.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LOW}
|
||||
)
|
||||
|
77
README.md
Normal file
77
README.md
Normal file
@ -0,0 +1,77 @@
|
||||
# LMDBAL - Lightning Memory Data Base Abstraction Level
|
||||
|
||||
[![AUR license](https://img.shields.io/aur/license/lmdbal?style=flat-square)](https://git.macaw.me/blue/lmdbal/raw/branch/master/LICENSE.md)
|
||||
[![AUR version](https://img.shields.io/aur/version/lmdbal?style=flat-square)](https://aur.archlinux.org/packages/lmdbal/)
|
||||
[![Liberapay patrons](https://img.shields.io/liberapay/patrons/macaw.me?logo=liberapay&style=flat-square)](https://liberapay.com/macaw.me)
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- QT 5 *(lower versions might work but it wasn't tested)*
|
||||
- lmdb
|
||||
- CMake 3.16 or higher
|
||||
|
||||
### Using with CMake
|
||||
|
||||
#### As a system library
|
||||
|
||||
If you're using LMDBAL as a system library you probably have no control over it's build options. The easiest way to include the project is to add following
|
||||
|
||||
```
|
||||
find_package(lmdbal)
|
||||
if (LMDBAL_FOUND)
|
||||
target_include_directories(yourTarget PRIVATE {LMDBAL_INCLUDE_DIRS})
|
||||
target_link_libraries(yourTarget PRIVATE LMDBAL::LMDBAL)
|
||||
endif()
|
||||
```
|
||||
|
||||
#### As an embeded subproject
|
||||
//TODO
|
||||
|
||||
### Building
|
||||
|
||||
LMDBAL uses CMake as a build system.
|
||||
|
||||
Please check the prerequisites and install them before building.
|
||||
|
||||
Here is an easy way to build a project
|
||||
|
||||
```
|
||||
$ git clone https://git.macaw.me/blue/lmdbal
|
||||
$ cd lmdbal
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake .. [ *optional keys* ]
|
||||
$ cmake --build .
|
||||
$ cmake --install . --prefix install
|
||||
```
|
||||
|
||||
This way will create you a `lmdbal/build` directory with temporary files, and `lmdbal/build/install` with all the export files for installation to the system.
|
||||
|
||||
After `cmake ..` you can specify keys to alter the building process. In this context building keys are transfered like so
|
||||
|
||||
```
|
||||
cmake .. -D KEY1=VALUE1 -D KEY2=VALUE2 ...
|
||||
```
|
||||
|
||||
#### List of keys
|
||||
|
||||
Here is the list of keys you can pass to configuration phase of `cmake ..`:
|
||||
|
||||
- `CMAKE_BUILD_TYPE` - `Debug` just builds showing all warnings, `Release` builds with no warnings and applies optimizations (default is `Debug`);
|
||||
- `BUILD_STATIC` - `True` builds project as a static library, `False` builds as dynamic (default is `False`);
|
||||
- `BUILD_TESTS` - `True` build unit tests, `False` does not (default is `False`);
|
||||
- `QT_VERSION_MAJOR` - `5` links against Qt5, `6` links agains Qt6, there is no default, so, if you didn't specify it the project will chose automatically;
|
||||
|
||||
#### Running tests
|
||||
|
||||
If you built the library with `-D BUILD_TESTS=True`, then there will be `lmdbal/build/tests/runUnitTests` executable file. You can simply run it as
|
||||
|
||||
```
|
||||
./runUnitTests
|
||||
```
|
||||
|
||||
if you're in the same directory with it
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the GPLv3 License - see the [LICENSE.md](LICENSE.md) file for details
|
5
cmake/Config.cmake.in
Normal file
5
cmake/Config.cmake.in
Normal file
@ -0,0 +1,5 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/lmdbalTargets.cmake")
|
||||
|
||||
check_required_components(lmdbal)
|
23
packaging/Archlinux/PKGBUILD
Normal file
23
packaging/Archlinux/PKGBUILD
Normal file
@ -0,0 +1,23 @@
|
||||
# Maintainer: Yury Gubich <blue@macaw.me>
|
||||
pkgname=lmdbal
|
||||
pkgver=0.2.0
|
||||
pkgrel=1
|
||||
pkgdesc="LMDB Abstraction Layer, qt5 version"
|
||||
arch=('i686' 'x86_64')
|
||||
url="https://git.macaw.me/blue/lmdbal"
|
||||
license=('GPL3')
|
||||
depends=( 'lmdb' 'qt5-base')
|
||||
makedepends=('cmake>=3.16')
|
||||
optdepends=()
|
||||
|
||||
source=("$pkgname-$pkgver.tar.gz")
|
||||
sha256sums=('SKIP')
|
||||
build() {
|
||||
cd "$srcdir/$pkgname"
|
||||
cmake . -D CMAKE_INSTALL_PREFIX=/usr -D CMAKE_BUILD_TYPE=Release -D QT_VERSION_MAJOR=5
|
||||
cmake --build .
|
||||
}
|
||||
package() {
|
||||
cd "$srcdir/$pkgname"
|
||||
DESTDIR="$pkgdir/" cmake --install .
|
||||
}
|
@ -29,9 +29,9 @@ set(HEADERS
|
||||
operators.hpp
|
||||
)
|
||||
|
||||
target_sources(lmdbal PRIVATE
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
${SOURCES}
|
||||
${HEADERS}
|
||||
)
|
||||
|
||||
set_target_properties(lmdbal PROPERTIES PUBLIC_HEADER "${HEADERS}")
|
||||
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_LOW})
|
||||
|
@ -15,7 +15,7 @@ target_include_directories(runUnitTests PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCL
|
||||
target_link_libraries(
|
||||
runUnitTests
|
||||
GTest::gtest_main
|
||||
lmdbal
|
||||
${PROJECT_NAME}
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
|
Loading…
Reference in New Issue
Block a user