diff --git a/CMakeLists.txt b/CMakeLists.txt index 68170f488..e3705e478 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,48 +1,72 @@ # Copyright (c) 2017 The Bitcoin developers cmake_minimum_required(VERSION 3.12) project(bitcoin-abc VERSION 0.20.5 DESCRIPTION "Bitcoin ABC is a full node implementation of the Bitcoin Cash protocol." HOMEPAGE_URL "https://www.bitcoinabc.org" ) # Add path for custom modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ) # Make contrib script accessible. set(CONTRIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/contrib) # If ccache is available, then use it. find_program(CCACHE ccache) if(CCACHE) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE}) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE}) endif(CCACHE) # Default to RelWithDebInfo configuration if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Select the configuration for the build" FORCE) endif() # Find the python interpreter. This is required for several targets. find_package(PythonInterp 3.4 REQUIRED) # Add the magic targets `check-*` add_custom_target(check-all) add_custom_target(check) 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 index 000000000..bbeeb91f9 --- /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 index 4e55395aa..83a52e968 100644 --- a/cmake/modules/PackageOptions.cmake +++ b/cmake/modules/PackageOptions.cmake @@ -1,19 +1,23 @@ # Package options set(CPACK_PACKAGE_VENDOR "The Bitcoin developers") set(CPACK_PACKAGE_DESCRIPTION "Bitcoin ABC is a Bitcoin Cash full node implementation.") set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}") set(CPACK_PACKAGE_INSTALL_DIRECTORY "Bitcoin-abc") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING") if(CMAKE_CROSSCOMPILING) set(CPACK_SYSTEM_NAME "${TOOLCHAIN_PREFIX}") endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/share/pixmaps/nsis-header.bmp") set(CPACK_GENERATOR "ZIP") else() 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 index 000000000..707104f01 --- /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 index 0dcd1f031..1626213a4 100644 --- a/contrib/devtools/CMakeLists.txt +++ b/contrib/devtools/CMakeLists.txt @@ -1,24 +1,38 @@ # Copyright (c) 2019 The Bitcoin developers add_custom_target(check-devtools) set(DEVTOOLS_TESTS_PYTHON ./chainparams/test_make_chainparams.py ) foreach(TEST ${DEVTOOLS_TESTS_PYTHON}) get_filename_component(TESTNAME ${TEST} NAME) get_filename_component(TESTPATH ${TEST} ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}) get_filename_component(WORKDIR ${TESTPATH} DIRECTORY) add_custom_target("check-devtools-${TESTNAME}" WORKING_DIRECTORY ${WORKDIR} COMMAND "${PYTHON_EXECUTABLE}" "./${TESTNAME}" ) add_dependencies(check-devtools "check-devtools-${TESTNAME}") endforeach() 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 index dfe5dba63..85f8efa2a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,95 +1,103 @@ ### # Create config.ini file for tests ### set(abs_top_srcdir ${CMAKE_SOURCE_DIR}) set(abs_top_builddir ${CMAKE_BINARY_DIR}) if(CMAKE_SYSTEM_NAME MATCHES "Windows") set(EXEEXT ".exe") endif() if(NOT BUILD_BITCOIN_WALLET) set(ENABLE_WALLET_TRUE "#") endif() if(NOT BUILD_BITCOIN_TX OR NOT BUILD_BITCOIN_TX) set(BUILD_BITCOIN_UTILS_TRUE "#") endif() if(NOT BUILD_BITCOIN_ZMQ) set(ENABLE_ZMQ_TRUE "#") endif() # Create build ini file configure_file(config.ini.in config.ini @ONLY) ### # Setup symlinks for testing ### macro(make_link src dest) add_custom_command( OUTPUT "${dest}" COMMAND ${CMAKE_COMMAND} -E create_symlink "${src}" "${dest}" COMMENT "make_link ${src} -> ${dest}" MAIN_DEPENDENCY "${src}" ) endmacro() file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/util/) make_link( ${CMAKE_CURRENT_SOURCE_DIR}/functional/test_runner.py ${CMAKE_CURRENT_BINARY_DIR}/functional/test_runner.py ) make_link( ${CMAKE_CURRENT_SOURCE_DIR}/functional/create_cache.py ${CMAKE_CURRENT_BINARY_DIR}/functional/create_cache.py ) make_link( ${CMAKE_CURRENT_SOURCE_DIR}/util/bitcoin-util-test.py ${CMAKE_CURRENT_BINARY_DIR}/util/bitcoin-util-test.py ) make_link( ${CMAKE_CURRENT_SOURCE_DIR}/util/rpcauth-test.py ${CMAKE_CURRENT_BINARY_DIR}/util/rpcauth-test.py ) add_custom_target(check-functional COMMAND "${PYTHON_EXECUTABLE}" ./functional/test_runner.py DEPENDS ../src/bitcoind ../src/bitcoin-cli ${CMAKE_CURRENT_BINARY_DIR}/functional/test_runner.py ${CMAKE_CURRENT_BINARY_DIR}/functional/create_cache.py ) add_dependencies(check-all check-functional) if(BUILD_BITCOIN_TX) add_custom_target(check-bitcoin-util COMMAND ${CMAKE_COMMAND} -E echo "Running test/util/bitcoin-util-test.py..." COMMAND "${PYTHON_EXECUTABLE}" ./util/bitcoin-util-test.py DEPENDS ../src/bitcoin-tx ${CMAKE_CURRENT_BINARY_DIR}/util/bitcoin-util-test.py ) add_dependencies(check check-bitcoin-util) endif() add_custom_target(check-rpcauth COMMAND ${CMAKE_COMMAND} -E echo "Running test/util/rpcauth-test.py..." COMMAND "${PYTHON_EXECUTABLE}" ./util/rpcauth-test.py DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/util/rpcauth-test.py ) add_dependencies(check check-rpcauth) + +include(PackageHelper) +exclude_from_source_package( + # Subdirectories + "cache/" + "lint/" + "sanitizer_suppressions/" +)