Improve cmake support. Add rpm generation

This commit is contained in:
Vladimir Romanov 2018-01-07 15:10:06 +03:00
parent 294d4ac0b9
commit 4ed8eddf42
6 changed files with 137 additions and 43 deletions

View File

@ -1,8 +1,17 @@
cmake_minimum_required(VERSION 2.8.7)
set(TARGET libmdbx)
set(TARGET mdbx)
project(${TARGET})
set(MDBX_VERSION_MAJOR 0)
set(MDBX_VERSION_MINOR 0)
set(MDBX_VERSION_PATCH 0)
set(MDBX_VERSION_STRING ${MDBX_VERSION_MAJOR}.${MDBX_VERSION_MINOR}.${MDBX_VERSION_PATCH})
add_definitions(-DMDBX_VERSION_MAJOR=${MDBX_VERSION_MAJOR})
add_definitions(-DMDBX_VERSION_MINOR=${MDBX_VERSION_MINOR})
add_definitions(-DMDBX_VERSION_PATCH=${MDBX_VERSION_PATCH})
enable_language(C)
enable_language(CXX)
@ -76,7 +85,7 @@ else ()
endif ()
endif ()
add_library(${TARGET} STATIC
set(${TARGET}_SRC
mdbx.h
src/bits.h
src/defs.h
@ -87,11 +96,90 @@ add_library(${TARGET} STATIC
src/version.c
)
target_include_directories(${TARGET} PUBLIC
add_library(${TARGET}_STATIC STATIC
${${TARGET}_SRC}
)
add_library(${TARGET} ALIAS ${TARGET}_STATIC)
add_library(${TARGET}_SHARED SHARED
${${TARGET}_SRC}
)
set_target_properties(${TARGET}_SHARED PROPERTIES
VERSION ${MDBX_VERSION_STRING}
SOVERSION ${MDBX_VERSION_MAJOR}
OUTPUT_NAME ${TARGET}
CLEAN_DIRECT_OUTPUT 1
)
set_target_properties(${TARGET}_STATIC PROPERTIES
VERSION ${MDBX_VERSION_STRING}
SOVERSION ${MDBX_VERSION_MAJOR}
OUTPUT_NAME ${TARGET}
CLEAN_DIRECT_OUTPUT 1
)
target_include_directories(${TARGET}_STATIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(${TARGET}_SHARED PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
install(TARGETS ${TARGET}_STATIC DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx)
install(TARGETS ${TARGET}_SHARED DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx)
install(FILES mdbx.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include COMPONENT mdbx-devel)
add_subdirectory(tutorial)
add_subdirectory(test)
add_subdirectory(src/tools)
add_subdirectory(pcrf_test)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_COMPONENT_INSTALL ON)
#Version
if (NOT "$ENV{BUILD_NUMBER}" STREQUAL "")
set(CPACK_PACKAGE_RELEASE $ENV{BUILD_NUMBER})
else ()
if (NOT "$ENV{CI_PIPELINE_ID}" STREQUAL "")
set(CPACK_PACKAGE_RELEASE $ENV{CI_PIPELINE_ID})
else ()
set(CPACK_PACKAGE_RELEASE 1)
endif ()
endif ()
set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE})
set(CPACK_PACKAGE_VERSION ${MDBX_VERSION_STRING})
set(CPACK_PACKAGE_VERSION_FULL ${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE})
set(CPACK_RPM_mdbx-devel_PACKAGE_REQUIRES "mdbx = ${CPACK_PACKAGE_VERSION}")
set(CPACK_RPM_SPEC_INSTALL_POST "/bin/true")
set(CPACK_RPM_mdbx_PACKAGE_NAME mdbx)
set(CPACK_RPM_mdbx-devel_PACKAGE_NAME mdbx-devel)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The revised and extended descendant of Symas LMDB")
set(CPACK_PACKAGE_VENDOR "???")
set(CPACK_PACKAGE_CONTACT "Vladimir Romanov")
set(CPACK_PACKAGE_RELOCATABLE false)
set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64")
set(CPACK_RPM_PACKAGE_REQUIRES "")
set(CPACK_RPM_PACKAGE_GROUP "Applications/Database")
set(CPACK_RPM_mdbx_FILE_NAME "${CPACK_RPM_mdbx_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_FULL}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
set(CPACK_RPM_mdbx-devel_FILE_NAME "${CPACK_RPM_mdbx-devel_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_FULL}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
/usr/local
/usr/local/bin
/usr/local/lib64
/usr/local/include
/usr/local/man
/usr/local/man/man1
)
include(CPack)

25
package.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
set -e
CONFIG=$1
if [[ -z "${CONFIG}" ]]; then
CONFIG=Debug
fi
DIRNAME=`dirname ${BASH_SOURCE[0]}`
DIRNAME=`readlink --canonicalize ${DIRNAME}`
if [[ -r /opt/rh/devtoolset-6/enable ]]; then
source /opt/rh/devtoolset-6/enable
fi
mkdir -p cmake-build-${CONFIG}
pushd cmake-build-${CONFIG} &> /dev/null
if [[ ! -r Makefile ]]; then
cmake .. -DCMAKE_BUILD_TYPE=${CONFIG}
fi
rm -f *.rpm
make -j8 package || exit 1
rm -f *-Unspecified.rpm
popd &> /dev/null

View File

@ -6,6 +6,6 @@ add_executable(${TARGET}
)
target_link_libraries(${TARGET}
libmdbx
mdbx
)

View File

@ -1,42 +1,23 @@
project(mdbx_tools)
add_executable(mdbx_chk
mdbx_chk.c
set(MDBX_TOOLS
mdbx_chk
mdbx_copy
mdbx_dump
mdbx_load
mdbx_stat
)
target_link_libraries(mdbx_chk
libmdbx
)
foreach (D_FILE ${MDBX_TOOLS})
add_executable(${D_FILE}
${D_FILE}.c
)
add_executable(mdbx_copy
mdbx_copy.c
)
target_link_libraries(mdbx_copy
libmdbx
)
add_executable(mdbx_dump
mdbx_dump.c
)
target_link_libraries(mdbx_dump
libmdbx
)
add_executable(mdbx_load
mdbx_load.c
)
target_link_libraries(mdbx_load
libmdbx
)
add_executable(mdbx_stat
mdbx_stat.c
)
target_link_libraries(mdbx_stat
libmdbx
)
target_link_libraries(${D_FILE}
mdbx
)
install(TARGETS ${D_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${D_FILE}.1)
install(FILES ${D_FILE}.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 COMPONENT mdbx)
endif()
endforeach ()

View File

@ -29,6 +29,6 @@ add_executable(${TARGET}
)
target_link_libraries(${TARGET}
libmdbx
mdbx
)

View File

@ -6,6 +6,6 @@ add_executable(${TARGET}
)
target_link_libraries(${TARGET}
libmdbx
mdbx
)