diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,11 +38,35 @@ add_custom_target(check-symbols) add_custom_target(check-security) +include(PackageHelper) +exclude_git_ignored_files_from_source_package() + +# Ignore hidden files and directories (starting with a '.') +set_property(GLOBAL APPEND PROPERTY SOURCE_PACKAGE_IGNORE_FILES "/\\\\.") + +# If the build is out-of-tree, then the build directory can be ignored. +if(NOT CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR) + set_property(GLOBAL APPEND PROPERTY SOURCE_PACKAGE_IGNORE_FILES + "${CMAKE_BINARY_DIR}/" + ) +endif() + +exclude_from_source_package( + # Subdirectories + "arcanist/" + "depends/" + + # Files + "[^.]+[.]md$" + "Dockerfile-doxygen" +) + add_subdirectory(src) add_subdirectory(test) -add_subdirectory(contrib/devtools) +add_subdirectory(contrib) add_subdirectory(doc) include(PackageOptions) +get_property(CPACK_SOURCE_IGNORE_FILES GLOBAL PROPERTY SOURCE_PACKAGE_IGNORE_FILES) include(CPack) diff --git a/cmake/modules/PackageHelper.cmake b/cmake/modules/PackageHelper.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/PackageHelper.cmake @@ -0,0 +1,74 @@ +# Facilities for building packages + +function(exclude_from_source_package) + foreach(_regex ${ARGN}) + set_property(GLOBAL APPEND PROPERTY SOURCE_PACKAGE_IGNORE_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/${_regex}" + ) + endforeach() +endfunction() + +function(exclude_git_ignored_files_from_source_package) + find_package(Git) + # Bail out if git is not installed. + if(NOT GIT_FOUND) + return() + endif() + + set(_git_ignored_files_output_file + "${CMAKE_CURRENT_BINARY_DIR}/git_ignored_files.txt" + ) + # Make git output a list of the ignored files and directories, and store it + # to a file. + execute_process( + COMMAND "${GIT_EXECUTABLE}" "status" "--ignored" "--porcelain" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_FILE "${_git_ignored_files_output_file}" + RESULT_VARIABLE _git_result + ) + + # If something goes wrong with the git command, don't proceed the output. + if(NOT _git_result EQUAL 0) + return() + endif() + + # Parse the file line by line. + # The --porcelain option ensures the output will remain stable. + # The ignored files/directories lines start with a double exclamation point. + file(STRINGS "${_git_ignored_files_output_file}" _git_ignored_files) + + foreach(_git_ignored_file ${_git_ignored_files}) + # Remove leading and trailing spaces. + string(STRIP "${_git_ignored_file}" _git_ignored_file) + + # Remove the leading exclamation points and the space. + string(REGEX REPLACE + "^!! (.+)" "\\1" + _git_ignored_file + "${_git_ignored_file}" + ) + # Only process the ignored files. + if(NOT CMAKE_MATCH_1) + continue() + endif() + + # Full path + get_filename_component(_git_ignored_file + "${_git_ignored_file}" + ABSOLUTE + ) + + if(IS_DIRECTORY "${_git_ignored_file}") + # get_filename_component() removes the trailing /, add it back. + string(APPEND _git_ignored_file "/") + else() + # Avoid partial match on file names. + string(APPEND _git_ignored_file "$") + endif() + + # Add the file to the ignored list. + set_property(GLOBAL APPEND PROPERTY SOURCE_PACKAGE_IGNORE_FILES + "${_git_ignored_file}" + ) + endforeach() +endfunction() diff --git a/cmake/modules/PackageOptions.cmake b/cmake/modules/PackageOptions.cmake --- a/cmake/modules/PackageOptions.cmake +++ b/cmake/modules/PackageOptions.cmake @@ -17,3 +17,7 @@ set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/share/pixmaps/bitcoin-abc128.png") set(CPACK_GENERATOR "TGZ") endif() + +# CPack source package options +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") +set(CPACK_SOURCE_GENERATOR "TGZ") diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/contrib/CMakeLists.txt @@ -0,0 +1,23 @@ +add_subdirectory(devtools) + +include(PackageHelper) +exclude_from_source_package( + # Subdirectories + "debian/" + "gitian/" + "gitian-descriptors/" + "gitian-signing/" + "qos/" + "seeds/" + "teamcity/" + "testgen/" + # FIXME Can be packaged once it gets updated to work with Bitcoin ABC + "verifybinaries/" + "zmq/" + + # Files + "bitcoin-qt.pro" + "gitian-build.py" + "README.md" + "valgrind.supp" +) diff --git a/contrib/devtools/CMakeLists.txt b/contrib/devtools/CMakeLists.txt --- a/contrib/devtools/CMakeLists.txt +++ b/contrib/devtools/CMakeLists.txt @@ -22,3 +22,17 @@ add_dependencies(check check-devtools) add_dependencies(check-all check-devtools) + +include(PackageHelper) +exclude_from_source_package( + # Files + "bitcoind-exit-on-log.sh" + "circular-dependencies.py" + "copyright_header.py" + "extract_strings_qt.py" + "gitian-build.py" + "optimize-pngs.py" + "README.md" + "test-security-check.py" + "update-translations.py" +) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -93,3 +93,11 @@ ) add_dependencies(check check-rpcauth) + +include(PackageHelper) +exclude_from_source_package( + # Subdirectories + "cache/" + "lint/" + "sanitizer_suppressions/" +)