Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1000 from lukaszstolarczuk/cmake-source-vars
Browse files Browse the repository at this point in the history
cmake: add ROOT_DIR and make use of CURRENT_*_DIR variables
  • Loading branch information
lukaszstolarczuk authored Dec 23, 2020
2 parents c8742a3 + 2c6c220 commit 2df10e8
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
25 changes: 13 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if(VERSION_PRERELEASE)
set(VERSION ${VERSION}-${VERSION_PRERELEASE})
endif()

set(LIBPMEMOBJCPP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBPMEMOBJ_REQUIRED_VERSION 1.9)
set(LIBPMEM_REQUIRED_VERSION 1.7)
# Only pmreorder in ver. >= 1.9 guarantees reliable output
Expand All @@ -43,7 +44,7 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LIBPMEMOBJCPP_ROOT_DIR}/cmake)

# ----------------------------------------------------------------- #
## CMake build options
Expand Down Expand Up @@ -94,7 +95,7 @@ include(CheckCXXSourceCompiles)
include(CheckCXXCompilerFlag)
include(GNUInstallDirs)

include(${CMAKE_SOURCE_DIR}/cmake/functions.cmake)
include(${LIBPMEMOBJCPP_ROOT_DIR}/cmake/functions.cmake)
# set SRCVERSION, it's more accurate and "current" than VERSION
set_source_ver(SRCVERSION)

Expand Down Expand Up @@ -165,8 +166,8 @@ add_custom_target(cppstyle)
add_custom_target(cppformat)
add_custom_target(check-whitespace)
add_custom_target(check-license
COMMAND ${CMAKE_SOURCE_DIR}/utils/check_license/check-headers.sh
${CMAKE_SOURCE_DIR}
COMMAND ${LIBPMEMOBJCPP_ROOT_DIR}/utils/check_license/check-headers.sh
${LIBPMEMOBJCPP_ROOT_DIR}
BSD-3-Clause)

if(CHECK_CPP_STYLE)
Expand Down Expand Up @@ -217,8 +218,8 @@ add_cppstyle(include-container-detail ${CMAKE_CURRENT_SOURCE_DIR}/include/libpme
add_cppstyle(include-detail ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/detail/*.hpp)
add_cppstyle(include-experimental ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/experimental/*.hpp)

add_check_whitespace(main ${CMAKE_SOURCE_DIR}/utils/check_license/*.sh
${CMAKE_SOURCE_DIR}/README.md)
add_check_whitespace(main ${LIBPMEMOBJCPP_ROOT_DIR}/utils/check_license/*.sh
${LIBPMEMOBJCPP_ROOT_DIR}/*.md)
add_check_whitespace(include ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/*.hpp)
add_check_whitespace(include-container ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/container/*.hpp)
add_check_whitespace(include-container-detail ${CMAKE_CURRENT_SOURCE_DIR}/include/libpmemobj++/container/detail/*.hpp)
Expand All @@ -230,7 +231,7 @@ add_check_whitespace(cmake-helpers ${CMAKE_CURRENT_SOURCE_DIR}/cmake/*.cmake)
# ----------------------------------------------------------------- #
## Configure make install/uninstall and packages
# ----------------------------------------------------------------- #
configure_file(${CMAKE_SOURCE_DIR}/cmake/version.hpp.in
configure_file(${LIBPMEMOBJCPP_ROOT_DIR}/cmake/version.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/version.hpp @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.hpp
Expand All @@ -242,21 +243,21 @@ install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
install(DIRECTORY examples/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples
FILES_MATCHING PATTERN "*.*pp")

configure_file(${CMAKE_SOURCE_DIR}/cmake/libpmemobj++.pc.in
configure_file(${LIBPMEMOBJCPP_ROOT_DIR}/cmake/libpmemobj++.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libpmemobj++.pc @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpmemobj++.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

configure_file(
"${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${LIBPMEMOBJCPP_ROOT_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)

configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/libpmemobj++-config.cmake.in
configure_package_config_file(${LIBPMEMOBJCPP_ROOT_DIR}/cmake/libpmemobj++-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libpmemobj++-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpmemobj++/cmake
PATH_VARS CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR)
Expand All @@ -275,7 +276,7 @@ include_directories(include)
# Run checks for known issues, it's required to enable/disable some tests and examples.
# It has to be executed (included) here, when environment is fully set up,
# all packages are found and all paths/variables are set.
include(${CMAKE_SOURCE_DIR}/cmake/check_compiling_issues.cmake)
include(${LIBPMEMOBJCPP_ROOT_DIR}/cmake/check_compiling_issues.cmake)

# ----------------------------------------------------------------- #
## Add/include sub-directories if build options enabled them
Expand Down Expand Up @@ -305,5 +306,5 @@ elseif(BUILD_EXAMPLES)
endif()

if(NOT "${CPACK_GENERATOR}" STREQUAL "")
include(${CMAKE_SOURCE_DIR}/cmake/packages.cmake)
include(${LIBPMEMOBJCPP_ROOT_DIR}/cmake/packages.cmake)
endif()
2 changes: 1 addition & 1 deletion cmake/check_compiling_issues.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if(NOT MSVC_VERSION)
NO_CLANG_BRACE_INITIALIZATION_NEWEXPR_BUG)

# Check for issues with older clang compilers which assert on delete persistent<[][]>.
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_SOURCE_DIR}/include ${LIBPMEMOBJ_INCLUDE_DIRS})
set(CMAKE_REQUIRED_INCLUDES ${LIBPMEMOBJCPP_ROOT_DIR}/include ${LIBPMEMOBJ_INCLUDE_DIRS})
set(CMAKE_REQUIRED_FLAGS "--std=c++11 -Wno-error -c")
CHECK_CXX_SOURCE_COMPILES(
"#include <libpmemobj++/make_persistent_array.hpp>
Expand Down
34 changes: 17 additions & 17 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,48 +68,48 @@ function(add_cppstyle name)
endif()

if(${ARGC} EQUAL 1)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/cppstyle-${name}-status
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cppstyle-${name}-status
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
COMMAND ${PERL_EXECUTABLE}
${CMAKE_SOURCE_DIR}/utils/cppstyle
${LIBPMEMOBJCPP_ROOT_DIR}/utils/cppstyle
${CLANG_FORMAT}
check
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/cppstyle-${name}-status
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/cppstyle-${name}-status
)

add_custom_target(cppformat-${name}
COMMAND ${PERL_EXECUTABLE}
${CMAKE_SOURCE_DIR}/utils/cppstyle
${LIBPMEMOBJCPP_ROOT_DIR}/utils/cppstyle
${CLANG_FORMAT}
format
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
)
else()
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/cppstyle-${name}-status
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cppstyle-${name}-status
DEPENDS ${ARGN}
COMMAND ${PERL_EXECUTABLE}
${CMAKE_SOURCE_DIR}/utils/cppstyle
${LIBPMEMOBJCPP_ROOT_DIR}/utils/cppstyle
${CLANG_FORMAT}
check
${ARGN}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/cppstyle-${name}-status
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/cppstyle-${name}-status
)

add_custom_target(cppformat-${name}
COMMAND ${PERL_EXECUTABLE}
${CMAKE_SOURCE_DIR}/utils/cppstyle
${LIBPMEMOBJCPP_ROOT_DIR}/utils/cppstyle
${CLANG_FORMAT}
format
${ARGN}
)
endif()

add_custom_target(cppstyle-${name}
DEPENDS ${CMAKE_BINARY_DIR}/cppstyle-${name}-status)
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cppstyle-${name}-status)

add_dependencies(cppstyle cppstyle-${name})
add_dependencies(cppformat cppformat-${name})
Expand All @@ -119,14 +119,14 @@ endfunction()
# of global "check-whitespace" target.
# ${name} must be unique.
function(add_check_whitespace name)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/check-whitespace-${name}-status
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-whitespace-${name}-status
DEPENDS ${ARGN}
COMMAND ${PERL_EXECUTABLE}
${CMAKE_SOURCE_DIR}/utils/check_whitespace ${ARGN}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/check-whitespace-${name}-status)
${LIBPMEMOBJCPP_ROOT_DIR}/utils/check_whitespace ${ARGN}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/check-whitespace-${name}-status)

add_custom_target(check-whitespace-${name}
DEPENDS ${CMAKE_BINARY_DIR}/check-whitespace-${name}-status)
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/check-whitespace-${name}-status)
add_dependencies(check-whitespace check-whitespace-${name})
endfunction()

Expand Down Expand Up @@ -167,16 +167,16 @@ endfunction()
# unless git is not available, then it's set to the recently released VERSION
function(set_source_ver SRCVERSION)
# if there's version file commited, use it
if(EXISTS "${CMAKE_SOURCE_DIR}/.version")
file(STRINGS ${CMAKE_SOURCE_DIR}/.version FILE_VERSION)
if(EXISTS "${LIBPMEMOBJCPP_ROOT_DIR}/.version")
file(STRINGS ${LIBPMEMOBJCPP_ROOT_DIR}/.version FILE_VERSION)
set(SRCVERSION ${FILE_VERSION} PARENT_SCOPE)
return()
endif()

# otherwise take it from git
execute_process(COMMAND git describe
OUTPUT_VARIABLE GIT_VERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${LIBPMEMOBJCPP_ROOT_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(GIT_VERSION)
Expand Down Expand Up @@ -206,7 +206,7 @@ function(set_source_ver SRCVERSION)
else()
execute_process(COMMAND git log -1 --format=%h
OUTPUT_VARIABLE GIT_COMMIT
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${LIBPMEMOBJCPP_ROOT_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(SRCVERSION ${GIT_COMMIT} PARENT_SCOPE)
return()
Expand Down
2 changes: 1 addition & 1 deletion cmake/packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ 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 >= ${LIBPMEMOBJ_REQUIRED_VERSION}")
#set(CPACK_RPM_CHANGELOG_FILE ${CMAKE_SOURCE_DIR}/ChangeLog)
#set(CPACK_RPM_CHANGELOG_FILE ${LIBPMEMOBJCPP_ROOT_DIR}/ChangeLog)

set(CPACK_DEBIAN_PACKAGE_NAME "libpmemobj++-dev")
set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
Expand Down
14 changes: 7 additions & 7 deletions doc/libpmemobj++.Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ COLS_IN_ALPHA_INDEX = 1
# spaces.
# Note: If this tag is empty the current directory is searched.

INPUT = @CMAKE_SOURCE_DIR@/include/libpmemobj++
INPUT += @CMAKE_SOURCE_DIR@/include/libpmemobj++/README.md
INPUT = @LIBPMEMOBJCPP_ROOT_DIR@/include/libpmemobj++
INPUT += @LIBPMEMOBJCPP_ROOT_DIR@/include/libpmemobj++/README.md

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down Expand Up @@ -127,14 +127,14 @@ RECURSIVE = YES
# run.

# temp_value.hpp: parsing error
EXCLUDE = @CMAKE_SOURCE_DIR@/include/libpmemobj++/detail/temp_value.hpp
EXCLUDE = @LIBPMEMOBJCPP_ROOT_DIR@/include/libpmemobj++/detail/temp_value.hpp

# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
# command).

EXAMPLE_PATH = @CMAKE_SOURCE_DIR@/examples
EXAMPLE_PATH += @CMAKE_SOURCE_DIR@/doc/shared
EXAMPLE_PATH = @LIBPMEMOBJCPP_ROOT_DIR@/examples
EXAMPLE_PATH += @LIBPMEMOBJCPP_ROOT_DIR@/doc/shared

# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
Expand Down Expand Up @@ -165,7 +165,7 @@ IMAGE_PATH =
# This tag requires that the tag FULL_PATH_NAMES is set to YES.

FULL_PATH_NAMES = YES
STRIP_FROM_PATH = @CMAKE_SOURCE_DIR@/include/
STRIP_FROM_PATH = @LIBPMEMOBJCPP_ROOT_DIR@/include/

# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
# path mentioned in the documentation of a class, which tells the reader which
Expand All @@ -174,7 +174,7 @@ STRIP_FROM_PATH = @CMAKE_SOURCE_DIR@/include/
# should specify the list of include paths that are normally passed to the
# compiler using the -I flag.

STRIP_FROM_INC_PATH = @CMAKE_SOURCE_DIR@/include/
STRIP_FROM_INC_PATH = @LIBPMEMOBJCPP_ROOT_DIR@/include/

#---------------------------------------------------------------------------
# Configuration options related to the LATEX output
Expand Down
2 changes: 1 addition & 1 deletion tests/compatibility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include(../ctest_helpers.cmake)
include(ExternalProject)

set(COMPATIBILITY_TEST_HEADERS_LOCATION ${CMAKE_BINARY_DIR}/compatibility)
set(COMPATIBILITY_TEST_HEADERS_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/compatibility)

function(add_libpmemobj_cpp version)
ExternalProject_Add(libpmemobj-cpp-${version}
Expand Down
4 changes: 2 additions & 2 deletions tests/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function(add_test_expect_failure name)
EXCLUDE_FROM_DEFAULT_BUILD TRUE)

add_test(NAME ${name}_fail_expected
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${name}_fail_expected
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR} --target ${name}_fail_expected
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_tests_properties(${name}_fail_expected PROPERTIES WILL_FAIL TRUE)
endfunction()
Expand Down

0 comments on commit 2df10e8

Please sign in to comment.