diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b1f65e0..75bb66e62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,124 +1,125 @@ # Copyright (c) 2017 The Bitcoin developers cmake_minimum_required(VERSION 3.16) set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_SOURCE_DIR}/cmake/modules/OverrideInitFlags.cmake" ) project(bitcoin-abc VERSION 0.22.1 DESCRIPTION "Bitcoin ABC is a full node implementation of the Bitcoin Cash protocol." HOMEPAGE_URL "https://www.bitcoinabc.org" ) # Package information set(PACKAGE_NAME "Bitcoin ABC") set(PACKAGE_BUGREPORT "https://github.com/Bitcoin-ABC/bitcoin-abc/issues") # Copyright set(COPYRIGHT_YEAR 2020) set(COPYRIGHT_HOLDERS "The %s developers") set(COPYRIGHT_HOLDERS_SUBSTITUTION Bitcoin) string(REPLACE "%s" ${COPYRIGHT_HOLDERS_SUBSTITUTION} COPYRIGHT_HOLDERS_FINAL ${COPYRIGHT_HOLDERS}) # Add path for custom modules list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) # Make contrib script accessible. set(CONTRIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/contrib) # Default to RelWithDebInfo configuration if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Select the configuration for the build" FORCE) set(__NO_USER_CMAKE_BUILD_TYPE ON CACHE BOOL "True if the user didn't set a build type on the command line") endif() # Find the python interpreter. This is required for several targets. find_package(Python 3.5 COMPONENTS Interpreter REQUIRED) # Add the magic targets `check-*` add_custom_target(check-all) add_custom_target(check) add_custom_target(check-extended) add_custom_target(check-upgrade-activated) add_custom_target(check-upgrade-activated-extended) # Add the global install targets add_custom_target(install-all) add_custom_target(install-debug) +add_custom_target(install-all-debug) 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" ) option(ENABLE_COVERAGE "Enable coverage" OFF) option(ENABLE_BRANCH_COVERAGE "Enable branch coverage" OFF) if(ENABLE_COVERAGE) include(Coverage) enable_coverage(${ENABLE_BRANCH_COVERAGE}) include(AddCompilerFlags) # If no build type is manually defined, override the optimization level. # Otherwise, alert the user than the coverage result might be useless. if(__NO_USER_CMAKE_BUILD_TYPE) set_c_optimization_level(0) # Setting -Og instead of -O0 is a workaround for the GCC bug 90380: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90380 # # This bug is fixed upstream, but is not widely distributed yet. # Fixed in GCC versions: # - GCC 7.x: versions <= 7.2 are unaffected # - GCC 8.x: versions >= 8.3.1 # - GCC 9.x: versions >= 9.1.1 # - GCC 10.x: all versions set_cxx_optimization_level(g) else() message(WARNING "It is advised to not enforce CMAKE_BUILD_TYPE to get the best coverage results") endif() exclude_from_coverage( "depends" "src/bench" "src/crypto/ctaes" "src/leveldb" "src/univalue" ) add_custom_target_coverage(check) add_custom_target_coverage(check-all) add_custom_target_coverage(check-extended) add_custom_target_coverage(check-upgrade-activated) add_custom_target_coverage(check-upgrade-activated-extended) endif() add_subdirectory(src) add_subdirectory(test) add_subdirectory(contrib) add_subdirectory(doc) include(PackageOptions.cmake) diff --git a/cmake/modules/InstallationHelper.cmake b/cmake/modules/InstallationHelper.cmake index 8ad7fac0d..edca39fb1 100644 --- a/cmake/modules/InstallationHelper.cmake +++ b/cmake/modules/InstallationHelper.cmake @@ -1,157 +1,177 @@ # This file contains facilities for installing the files. include(GNUInstallDirs) include(SanitizeHelper) function(_add_install_target COMPONENT) + cmake_parse_arguments(ARG + "EXCLUDE_FROM_ALL" + "" + "DEPENDS" + ${ARGN} + ) + sanitize_target_name("install-" "${COMPONENT}" INSTALL_TARGET) if(NOT TARGET ${INSTALL_TARGET}) add_custom_target(${INSTALL_TARGET} COMMENT "Installing component ${COMPONENT}" COMMAND "${CMAKE_COMMAND}" -E env CMAKE_INSTALL_ALWAYS=ON "${CMAKE_COMMAND}" -DCOMPONENT="${COMPONENT}" -DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" -P cmake_install.cmake WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" ) if(TARGET install-all) add_dependencies(install-all ${INSTALL_TARGET}) endif() endif() # Other arguments are additional dependencies - if(ARGN) - add_dependencies(${INSTALL_TARGET} ${ARGN}) + if(ARG_DEPENDS) + add_dependencies(${INSTALL_TARGET} ${ARG_DEPENDS}) endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") if(NOT TARGET "install-${COMPONENT}-debug") add_custom_target("install-${COMPONENT}-debug" COMMENT "Splitting out the debug symbols for component ${COMPONENT}" COMMAND "${CMAKE_SOURCE_DIR}/cmake/utils/split-installed-component.sh" "${CMAKE_BINARY_DIR}/contrib/devtools/split-debug.sh" "${CMAKE_BINARY_DIR}/install_manifest_${COMPONENT}.txt" "${CMAKE_INSTALL_BINDIR}" "${CMAKE_INSTALL_LIBDIR}" DEPENDS "${INSTALL_TARGET}" "${CMAKE_BINARY_DIR}/contrib/devtools/split-debug.sh" ) endif() - if(TARGET install-debug) + if(NOT ARG_EXCLUDE_FROM_ALL AND TARGET install-debug) add_dependencies(install-debug "install-${COMPONENT}-debug") endif() + + if(TARGET install-all-debug) + add_dependencies(install-all-debug "install-${COMPONENT}-debug") + endif() endif() endfunction() function(install_target _target) cmake_parse_arguments(ARG - "" + "EXCLUDE_FROM_ALL" "COMPONENT" "" ${ARGN} ) if(NOT ARG_COMPONENT) set(ARG_COMPONENT ${PROJECT_NAME}) endif() + if(ARG_EXCLUDE_FROM_ALL) + set(INSTALL_EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL) + endif() + + set(COMMON_INSTALL_ARGUMENTS + COMPONENT ${ARG_COMPONENT} + ${INSTALL_EXCLUDE_FROM_ALL} + ${ARG_UNPARSED_ARGUMENTS} + ) + install( TARGETS ${_target} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - COMPONENT ${ARG_COMPONENT} - ${ARG_UNPARSED_ARGUMENTS} + ${COMMON_INSTALL_ARGUMENTS} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - COMPONENT ${ARG_COMPONENT} - ${ARG_UNPARSED_ARGUMENTS} + ${COMMON_INSTALL_ARGUMENTS} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - COMPONENT ${ARG_COMPONENT} - ${ARG_UNPARSED_ARGUMENTS} + ${COMMON_INSTALL_ARGUMENTS} PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - COMPONENT ${ARG_COMPONENT} - ${ARG_UNPARSED_ARGUMENTS} + ${COMMON_INSTALL_ARGUMENTS} ) - _add_install_target("${ARG_COMPONENT}" ${_target}) + _add_install_target("${ARG_COMPONENT}" + ${INSTALL_EXCLUDE_FROM_ALL} + DEPENDS ${_target} + ) endfunction() function(install_shared_library NAME) cmake_parse_arguments(ARG "EXCLUDE_FROM_ALL" "" "PUBLIC_HEADER" ${ARGN} ) set(_sources ${ARG_UNPARSED_ARGUMENTS}) get_target_property(_target_type ${NAME} TYPE) if(_target_type STREQUAL "SHARED_LIBRARY") set(_shared_name "${NAME}") target_sources(${NAME} PRIVATE ${_sources}) else() set(_shared_name "${NAME}-shared") add_library(${_shared_name} SHARED ${_sources}) target_link_libraries(${_shared_name} ${NAME}) endif() if(ARG_PUBLIC_HEADER) set_property(TARGET ${_shared_name} PROPERTY PUBLIC_HEADER ${ARG_PUBLIC_HEADER}) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") # FIXME For compatibility reason with autotools, the version is set # to 0.0.0 (major being actually 0). This is obviously wrong and the # version of the library should reflect the version of the release. # On platforms other than linux, only the major version (0) is used. # Replace the VERSION line with the statement below to set the # correct version: # set(_properties VERSION "${CMAKE_PROJECT_VERSION}") list(APPEND _properties VERSION "${CMAKE_PROJECT_VERSION_MAJOR}.0.0") else() list(APPEND _properties VERSION "${CMAKE_PROJECT_VERSION_MAJOR}") endif() # For autotools compatibility, rename the library to ${OUTPUT_NAME}-0.dll if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") list(APPEND _properties OUTPUT_NAME "${NAME}-${CMAKE_PROJECT_VERSION_MAJOR}") # DLL_EXPORT is defined by libtool, and is expected by some sources. target_compile_definitions(${_shared_name} PRIVATE DLL_EXPORT) else() list(APPEND _properties OUTPUT_NAME "${NAME}") endif() list(APPEND _properties SOVERSION "${CMAKE_PROJECT_VERSION_MAJOR}") set_target_properties(${_shared_name} PROPERTIES ${_properties}) # Forward EXCLUDE_FROM_ALL if set if(ARG_EXCLUDE_FROM_ALL) set(FORWARD_EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL) endif() install_target(${_shared_name} ${FORWARD_EXCLUDE_FROM_ALL}) endfunction() function(install_manpages) set(MAN_DESTINATION "${CMAKE_INSTALL_MANDIR}/man1") install( FILES ${ARGN} DESTINATION "${MAN_DESTINATION}" COMPONENT manpages ) _add_install_target(manpages) endfunction()