diff --git a/.appveyor.yml b/.appveyor.yml index 388e4a77c2..aae0a4923c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -22,7 +22,6 @@ matrix: before_build: - cmake . -Bbuild -G "%GENERATOR%" - -DCMAKE_MODULE_PATH=c:/projects/libpmemobj-cpp -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake build_script: diff --git a/CMakeLists.txt b/CMakeLists.txt index f4e6b4c24e..593376563a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,20 +38,26 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) +# Treat CMAKE_CXX_STANDARD as a requirement +set(CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 11) + +include(FindPerl) include(FindThreads) include(CMakeDependentOption) include(CheckCXXSourceCompiles) +include(CheckCXXCompilerFlag) +include(GNUInstallDirs) +include(${CMAKE_SOURCE_DIR}/cmake/functions.cmake) option(BUILD_EXAMPLES "build examples" ON) - option(BUILD_TESTS "build tests" ON) - option(BUILD_DOC "build documentation" ON) - -option(TRACE_TESTS - "more verbose test outputs" OFF) - option(COVERAGE "run coverage test" OFF) +option(DEVELOPER_MODE "enable developer checks" OFF) +option(TRACE_TESTS "more verbose test outputs" OFF) +option(USE_ASAN "enable AddressSanitizer (debugging)" OFF) +option(USE_UBSAN "enable UndefinedBehaviorSanitizer (debugging)" OFF) set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/test CACHE STRING "working directory for tests") @@ -79,7 +85,10 @@ else() OUTPUT_STRIP_TRAILING_WHITESPACE) endif() -include(FindPerl) +find_package(PkgConfig QUIET) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) + if(NOT PERL_FOUND) message(FATAL_ERROR "Perl not found") endif() @@ -87,50 +96,26 @@ if (PERL_VERSION_STRING VERSION_LESS 5.16) message(FATAL_ERROR "Too old Perl (<5.16)") endif() -include(CheckCXXCompilerFlag) -include(GNUInstallDirs) -find_package(PkgConfig QUIET) - -include_directories(include) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PMEMOBJ REQUIRED libpmemobj>=1.4) +else() + find_package(PMEMOBJ REQUIRED 1.4) +endif() -# Treat CMAKE_CXX_STANDARD as a requirement -set(CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_STANDARD 11) +if(PKG_CONFIG_FOUND) + pkg_check_modules(VALGRIND QUIET valgrind) +else() + find_package(VALGRIND QUIET) +endif() -function(join SEP OUT VALUES) - string(REPLACE ";" "${SEP}" JOIN_TMP "${VALUES}") - set(${OUT} "${JOIN_TMP}" PARENT_SCOPE) -endfunction() - -# prepends prefix to list of strings -function(prepend var prefix) - set(listVar "") - foreach(f ${ARGN}) - list(APPEND listVar "${prefix}/${f}") - endforeach(f) - set(${var} "${listVar}" PARENT_SCOPE) -endfunction() - -# Checks whether flag is supported by current C++ compiler and appends -# it to the relevant cmake variable. -# 1st argument is a flag -# 2nd (optional) argument is a build type (debug, release) -macro(add_flag flag) - string(REPLACE - _ flag2 ${flag}) - string(REPLACE " " _ flag2 ${flag2}) - string(REPLACE = "_" flag2 ${flag2}) - set(check_name "CXX_HAS_${flag2}") - - check_cxx_compiler_flag(${flag} ${check_name}) - - if (${${check_name}}) - if (${ARGC} EQUAL 1) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") - else() - set(CMAKE_CXX_FLAGS_${ARGV1} "${CMAKE_CXX_FLAGS_${ARGV1}} ${flag}") - endif() - endif() -endmacro() +if(PKG_CONFIG_FOUND) + pkg_check_modules(LIBUNWIND QUIET libunwind) +else() + find_package(LIBUNWIND QUIET) +endif() +if(NOT LIBUNWIND_FOUND) + message(WARNING "libunwind not found. Stack traces from tests will not be reliable") +endif() add_flag(-Wall) add_flag(-Wpointer-arith) @@ -147,24 +132,6 @@ add_flag(-DDEBUG DEBUG) add_flag("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" RELEASE) -option(USE_ASAN "enable AddressSanitizer (debugging)" OFF) -option(USE_UBSAN "enable UndefinedBehaviorSanitizer (debugging)" OFF) - -macro(add_sanitizer_flag flag) - set(SAVED_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} -fsanitize=${flag}") - - check_cxx_compiler_flag("-fsanitize=${flag}" CXX_HAS_ASAN_UBSAN) - if(CXX_HAS_ASAN_UBSAN) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${flag}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${flag}") - else() - message("${flag} sanitizer not supported") - endif() - - set(CMAKE_REQUIRED_LIBRARIES ${SAVED_CMAKE_REQUIRED_LIBRARIES}) -endmacro() - if(USE_ASAN) add_sanitizer_flag(address) endif() @@ -178,67 +145,6 @@ endif() add_executable(check_license EXCLUDE_FROM_ALL utils/check_license/check-license.c) -# Generates cppstyle-$name and cppformat-$name targets and attaches them -# as dependencies of global "cppformat" target. -# cppstyle-$name target verifies C++ style of files in current source dir. -# cppformat-$name target reformats files in current source dir. -# If more arguments are used, then they are used as files to be checked -# instead. -# ${name} must be unique. -function(add_cppstyle name) - if(NOT CLANG_FORMAT) - return() - endif() - - if(${ARGC} EQUAL 1) - add_custom_target(cppstyle-${name} - COMMAND ${PERL_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/utils/cppstyle - ${CLANG_FORMAT} - check - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp - ) - add_custom_target(cppformat-${name} - COMMAND ${PERL_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/utils/cppstyle - ${CLANG_FORMAT} - format - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp - ) - else() - add_custom_target(cppstyle-${name} - COMMAND ${PERL_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/utils/cppstyle - ${CLANG_FORMAT} - check - ${ARGN} - ) - add_custom_target(cppformat-${name} - COMMAND ${PERL_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/utils/cppstyle - ${CLANG_FORMAT} - format - ${ARGN} - ) - endif() - - add_dependencies(cppstyle cppstyle-${name}) - add_dependencies(cppformat cppformat-${name}) -endfunction() - -# Generates check-whitespace-$name target and attaches it as a dependency -# of global "check-whitespace" target. -# ${name} must be unique. -function(add_check_whitespace name) - add_custom_target(check-whitespace-${name} - COMMAND ${PERL_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/utils/check_whitespace ${ARGN}) - - add_dependencies(check-whitespace check-whitespace-${name}) -endfunction() - add_custom_target(checkers ALL) add_custom_target(cppstyle) add_custom_target(cppformat) @@ -261,7 +167,6 @@ add_dependencies(check-whitespace check-whitespace-main) add_custom_target(tests) -option(DEVELOPER_MODE "enable developer checks" OFF) if(DEVELOPER_MODE) # add_flag(-Werror) XXX : fix warnings find_program(CLANG_FORMAT NAMES clang-format-3.9 clang-format-3.8) @@ -282,10 +187,12 @@ if(DEVELOPER_MODE) add_dependencies(checkers check-license) endif(DEVELOPER_MODE) -add_cppstyle("include" ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/*.hpp) -add_cppstyle("include-detail" ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/detail/*.hpp) -add_check_whitespace("include" ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/*.hpp) -add_check_whitespace("include-detail" ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/detail/*.hpp) +add_cppstyle(include ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/*.hpp) +add_cppstyle(include-detail ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/detail/*.hpp) +add_check_whitespace(include ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/*.hpp) +add_check_whitespace(include-detail ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/detail/*.hpp) +add_check_whitespace(cmake-main ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt) +add_check_whitespace(cmake-helpers ${CMAKE_CURRENT_SOURCE_DIR}/cmake/*.cmake) if(PKG_CONFIG_FOUND) pkg_check_modules(PMEMOBJ REQUIRED libpmemobj>=1.4) @@ -313,7 +220,7 @@ install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} install(DIRECTORY examples/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples FILES_MATCHING PATTERN "*.*pp") -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpmemobj++.pc.in +configure_file(${CMAKE_SOURCE_DIR}/cmake/libpmemobj++.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpmemobj++.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpmemobj++.pc @@ -321,19 +228,13 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpmemobj++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) -if(PKG_CONFIG_FOUND) - pkg_check_modules(VALGRIND QUIET valgrind) -else() - find_package(VALGRIND QUIET) -endif() - if(NOT WIN32) if(VALGRIND_FOUND) set(ENV{PATH} ${VALGRIND_PREFIX}/bin:$ENV{PATH}) @@ -349,14 +250,6 @@ if(NOT WIN32) endif() endif() -if(PKG_CONFIG_FOUND) - pkg_check_modules(LIBUNWIND QUIET libunwind) -else() - find_package(LIBUNWIND QUIET) -endif() -if(NOT LIBUNWIND_FOUND) - message(WARNING "libunwind not found. Stack traces from tests will not be reliable") -endif() if(NOT WIN32) set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) @@ -381,15 +274,15 @@ else() set(NO_GCC_VARIADIC_TEMPLATE_BUG TRUE) endif() +include_directories(include) + if(BUILD_TESTS) if(TEST_DIR) enable_testing() else() message(WARNING "TEST_DIR is empty - 'make test' will not work") endif() -endif() -if(BUILD_TESTS) add_subdirectory(tests) endif() @@ -404,57 +297,5 @@ elseif(BUILD_EXAMPLES) endif() if(NOT "${CPACK_GENERATOR}" STREQUAL "") - string(TOUPPER "${CPACK_GENERATOR}" CPACK_GENERATOR) - - if(NOT ("${CPACK_GENERATOR}" STREQUAL "DEB" OR - "${CPACK_GENERATOR}" STREQUAL "RPM")) - message(FATAL_ERROR "Wrong CPACK_GENERATOR value, valid generators are: DEB, RPM") - endif() - - set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") - set(CMAKE_INSTALL_TMPDIR /tmp CACHE PATH "Output dir for tmp") - set(CPACK_COMPONENTS_ALL_IN_ONE) - - # Filter out some of directories from %dir section, which are expected - # to exist in filesystem. Leaving them might lead to conflicts with other - # packages (for example with 'filesystem' package on fedora which specify - # /usr, /usr/local, etc.) - set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION - ${CPACK_PACKAGING_INSTALL_PREFIX} - ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} - ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig - ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_INCDIR} - ${CPACK_PACKAGING_INSTALL_PREFIX}/share - ${CPACK_PACKAGING_INSTALL_PREFIX}/share/doc) - - set(CPACK_PACKAGE_NAME "libpmemobj++") - set(CPACK_PACKAGE_VERSION ${VERSION}) - set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) - set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) - set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "c++ bindings to libpmemobj") - set(CPACK_PACKAGE_VENDOR "Intel") - - set(CPACK_RPM_PACKAGE_NAME "libpmemobj++-devel") - set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") - set(CPACK_RPM_PACKAGE_LICENSE "BSD") - set(CPACK_RPM_PACKAGE_ARCHITECTURE x86_64) - set(CPACK_RPM_PACKAGE_REQUIRES "libpmemobj-devel >= 1.4") - set(CPACK_RPM_CHANGELOG_FILE ${CMAKE_SOURCE_DIR}/ChangeLog) - - set(CPACK_DEBIAN_PACKAGE_NAME "libpmemobj++-dev") - set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}) - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64) - set(CPACK_DEBIAN_PACKAGE_DEPENDS "libpmemobj-dev (>= 1.4)") - set(CPACK_DEBIAN_PACKAGE_MAINTAINER "marcin.slusarz@intel.com") - - if("${CPACK_GENERATOR}" STREQUAL "RPM") - set(CPACK_PACKAGE_FILE_NAME - ${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE}) - elseif("${CPACK_GENERATOR}" STREQUAL "DEB") - set(CPACK_PACKAGE_FILE_NAME - ${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}) - endif() - - set(targetDestDir ${CMAKE_INSTALL_TMPDIR}) - include(CPack) + include(${CMAKE_SOURCE_DIR}/cmake/packages.cmake) endif() diff --git a/README.md b/README.md index bca8f7618d..c9f37e8407 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,6 @@ vcpkg integrate install ```sh ... cmake . -Bbuild -G "Visual Studio 14 2015 Win64" - -DCMAKE_MODULE_PATH=c:/projects/libpmemobj-cpp -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake msbuild build/ALL_BUILD.vcxproj diff --git a/FindPMEMOBJ.cmake b/cmake/FindPMEMOBJ.cmake similarity index 100% rename from FindPMEMOBJ.cmake rename to cmake/FindPMEMOBJ.cmake diff --git a/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in similarity index 100% rename from cmake_uninstall.cmake.in rename to cmake/cmake_uninstall.cmake.in diff --git a/cmake/functions.cmake b/cmake/functions.cmake new file mode 100644 index 0000000000..9c4d6ecd1c --- /dev/null +++ b/cmake/functions.cmake @@ -0,0 +1,145 @@ +# +# Copyright 2018, Intel Corporation +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# +# functions.cmake - helper functions for CMakeLists.txt +# + +function(join SEP OUT VALUES) + string(REPLACE ";" "${SEP}" JOIN_TMP "${VALUES}") + set(${OUT} "${JOIN_TMP}" PARENT_SCOPE) +endfunction() + +# prepends prefix to list of strings +function(prepend var prefix) + set(listVar "") + foreach(f ${ARGN}) + list(APPEND listVar "${prefix}/${f}") + endforeach(f) + set(${var} "${listVar}" PARENT_SCOPE) +endfunction() + +# Checks whether flag is supported by current C++ compiler and appends +# it to the relevant cmake variable. +# 1st argument is a flag +# 2nd (optional) argument is a build type (debug, release) +macro(add_flag flag) + string(REPLACE - _ flag2 ${flag}) + string(REPLACE " " _ flag2 ${flag2}) + string(REPLACE = "_" flag2 ${flag2}) + set(check_name "CXX_HAS_${flag2}") + + check_cxx_compiler_flag(${flag} ${check_name}) + + if (${${check_name}}) + if (${ARGC} EQUAL 1) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") + else() + set(CMAKE_CXX_FLAGS_${ARGV1} "${CMAKE_CXX_FLAGS_${ARGV1}} ${flag}") + endif() + endif() +endmacro() + +macro(add_sanitizer_flag flag) + set(SAVED_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} -fsanitize=${flag}") + + check_cxx_compiler_flag("-fsanitize=${flag}" CXX_HAS_ASAN_UBSAN) + if(CXX_HAS_ASAN_UBSAN) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${flag}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${flag}") + else() + message("${flag} sanitizer not supported") + endif() + + set(CMAKE_REQUIRED_LIBRARIES ${SAVED_CMAKE_REQUIRED_LIBRARIES}) +endmacro() + +# Generates cppstyle-$name and cppformat-$name targets and attaches them +# as dependencies of global "cppformat" target. +# cppstyle-$name target verifies C++ style of files in current source dir. +# cppformat-$name target reformats files in current source dir. +# If more arguments are used, then they are used as files to be checked +# instead. +# ${name} must be unique. +function(add_cppstyle name) + if(NOT CLANG_FORMAT) + return() + endif() + + if(${ARGC} EQUAL 1) + add_custom_target(cppstyle-${name} + COMMAND ${PERL_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/utils/cppstyle + ${CLANG_FORMAT} + check + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp + ) + add_custom_target(cppformat-${name} + COMMAND ${PERL_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/utils/cppstyle + ${CLANG_FORMAT} + format + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp + ) + else() + add_custom_target(cppstyle-${name} + COMMAND ${PERL_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/utils/cppstyle + ${CLANG_FORMAT} + check + ${ARGN} + ) + add_custom_target(cppformat-${name} + COMMAND ${PERL_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/utils/cppstyle + ${CLANG_FORMAT} + format + ${ARGN} + ) + endif() + + add_dependencies(cppstyle cppstyle-${name}) + add_dependencies(cppformat cppformat-${name}) +endfunction() + +# Generates check-whitespace-$name target and attaches it as a dependency +# of global "check-whitespace" target. +# ${name} must be unique. +function(add_check_whitespace name) + add_custom_target(check-whitespace-${name} + COMMAND ${PERL_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/utils/check_whitespace ${ARGN}) + + add_dependencies(check-whitespace check-whitespace-${name}) +endfunction() diff --git a/libpmemobj++.pc.in b/cmake/libpmemobj++.pc.in similarity index 100% rename from libpmemobj++.pc.in rename to cmake/libpmemobj++.pc.in diff --git a/cmake/packages.cmake b/cmake/packages.cmake new file mode 100644 index 0000000000..e749fc784d --- /dev/null +++ b/cmake/packages.cmake @@ -0,0 +1,88 @@ +# +# Copyright 2018, Intel Corporation +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# +# packages.cmake - CPack configuration for rpm and deb generation +# + +string(TOUPPER "${CPACK_GENERATOR}" CPACK_GENERATOR) + +if(NOT ("${CPACK_GENERATOR}" STREQUAL "DEB" OR + "${CPACK_GENERATOR}" STREQUAL "RPM")) + message(FATAL_ERROR "Wrong CPACK_GENERATOR value, valid generators are: DEB, RPM") +endif() + +set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +set(CMAKE_INSTALL_TMPDIR /tmp CACHE PATH "Output dir for tmp") +set(CPACK_COMPONENTS_ALL_IN_ONE) + +# Filter out some of directories from %dir section, which are expected +# to exist in filesystem. Leaving them might lead to conflicts with other +# packages (for example with 'filesystem' package on fedora which specify +# /usr, /usr/local, etc.) +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION + ${CPACK_PACKAGING_INSTALL_PREFIX} + ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig + ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_INCDIR} + ${CPACK_PACKAGING_INSTALL_PREFIX}/share + ${CPACK_PACKAGING_INSTALL_PREFIX}/share/doc) + +set(CPACK_PACKAGE_NAME "libpmemobj++") +set(CPACK_PACKAGE_VERSION ${VERSION}) +set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "c++ bindings to libpmemobj") +set(CPACK_PACKAGE_VENDOR "Intel") + +set(CPACK_RPM_PACKAGE_NAME "libpmemobj++-devel") +set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") +set(CPACK_RPM_PACKAGE_LICENSE "BSD") +set(CPACK_RPM_PACKAGE_ARCHITECTURE x86_64) +set(CPACK_RPM_PACKAGE_REQUIRES "libpmemobj-devel >= 1.4") +set(CPACK_RPM_CHANGELOG_FILE ${CMAKE_SOURCE_DIR}/ChangeLog) + +set(CPACK_DEBIAN_PACKAGE_NAME "libpmemobj++-dev") +set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}) +set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64) +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libpmemobj-dev (>= 1.4)") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "marcin.slusarz@intel.com") + +if("${CPACK_GENERATOR}" STREQUAL "RPM") + set(CPACK_PACKAGE_FILE_NAME + ${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE}) +elseif("${CPACK_GENERATOR}" STREQUAL "DEB") + set(CPACK_PACKAGE_FILE_NAME + ${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}) +endif() + +set(targetDestDir ${CMAKE_INSTALL_TMPDIR}) +include(CPack) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index aa2f3fdb0d..7ddb98ca4a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -34,6 +34,7 @@ link_directories(${PMEMOBJ_LIBRARY_DIRS}) add_cppstyle(examples-common ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) add_check_whitespace(examples-common ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) +add_check_whitespace(examples-cmake ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt) function(add_example name) set(srcs ${ARGN}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 37cc5a10d0..6d2a5dda52 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -87,8 +87,9 @@ else() set(NO_CHRONO_BUG TRUE) endif() -add_cppstyle("tests-common" ${CMAKE_CURRENT_SOURCE_DIR}/common/*.*pp) -add_check_whitespace("tests-common" ${CMAKE_CURRENT_SOURCE_DIR}/common/*.*pp) +add_cppstyle(tests-common ${CMAKE_CURRENT_SOURCE_DIR}/common/*.*pp) +add_check_whitespace(tests-common ${CMAKE_CURRENT_SOURCE_DIR}/common/*.*pp) +add_check_whitespace(tests-cmake ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt) function(build_test name) # skip posix tests diff --git a/utils/check_whitespace b/utils/check_whitespace index 70b3d82c21..091002bd36 100755 --- a/utils/check_whitespace +++ b/utils/check_whitespace @@ -132,7 +132,7 @@ sub check_whitespace_with_exc { $_ = basename($full); - return 0 unless /^(README.*|LICENSE.*|Makefile.*|.gitignore|TEST.*|RUNTESTS|check_whitespace|.*\.([chp13s]|sh|map|cpp|hpp|inc|PS1|ps1|py|md))$/; + return 0 unless /^(README.*|LICENSE.*|Makefile.*|CMakeLists.txt|.gitignore|TEST.*|RUNTESTS|check_whitespace|.*\.([chp13s]|sh|map|cpp|hpp|inc|PS1|ps1|py|md|cmake))$/; return 0 if -z; check_whitespace($full, $_);