From 2c6c220e6626f2ac02fc32a2c14588fe126e1334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stolarczuk?= Date: Mon, 21 Dec 2020 17:01:42 +0100 Subject: [PATCH] cmake: add ROOT_DIR and make use of CURRENT_*_DIR variables --- CMakeLists.txt | 25 +++++++++++----------- cmake/check_compiling_issues.cmake | 2 +- cmake/functions.cmake | 34 +++++++++++++++--------------- cmake/packages.cmake | 2 +- doc/libpmemobj++.Doxyfile.in | 14 ++++++------ tests/compatibility/CMakeLists.txt | 2 +- tests/external/CMakeLists.txt | 4 ++-- 7 files changed, 42 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f6d32a815..2b25b0dd1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) @@ -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 @@ -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() diff --git a/cmake/check_compiling_issues.cmake b/cmake/check_compiling_issues.cmake index f1eb44f8d4..a96edf1d29 100644 --- a/cmake/check_compiling_issues.cmake +++ b/cmake/check_compiling_issues.cmake @@ -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 diff --git a/cmake/functions.cmake b/cmake/functions.cmake index 700fe01230..5451af5e64 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -68,40 +68,40 @@ 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} @@ -109,7 +109,7 @@ function(add_cppstyle name) 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}) @@ -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() @@ -167,8 +167,8 @@ 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() @@ -176,7 +176,7 @@ function(set_source_ver SRCVERSION) # 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) @@ -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() diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 4889712e7a..2f203d3bb6 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -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}) diff --git a/doc/libpmemobj++.Doxyfile.in b/doc/libpmemobj++.Doxyfile.in index 51ef0c9203..45141f364d 100644 --- a/doc/libpmemobj++.Doxyfile.in +++ b/doc/libpmemobj++.Doxyfile.in @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/compatibility/CMakeLists.txt b/tests/compatibility/CMakeLists.txt index 1ec502a6cb..f953795f52 100644 --- a/tests/compatibility/CMakeLists.txt +++ b/tests/compatibility/CMakeLists.txt @@ -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} diff --git a/tests/external/CMakeLists.txt b/tests/external/CMakeLists.txt index 6b79fd9261..f9e36ebe06 100644 --- a/tests/external/CMakeLists.txt +++ b/tests/external/CMakeLists.txt @@ -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()