diff --git a/cmake/modules/ExternalLibraryHelper.cmake b/cmake/modules/ExternalLibraryHelper.cmake index 48cae279dc..c80c91fa19 100644 --- a/cmake/modules/ExternalLibraryHelper.cmake +++ b/cmake/modules/ExternalLibraryHelper.cmake @@ -1,58 +1,58 @@ include(FindPackageMessage) # Find a library component, set the variables and create an imported target. # Variable names are compliant with cmake standards. function(find_component LIB COMPONENT) cmake_parse_arguments(ARG "" "" "HINTS;INCLUDE_DIRS;INTERFACE_LINK_LIBRARIES;NAMES;PATHS;PATH_SUFFIXES" ${ARGN} ) # If the component is not requested, skip the search. if(${LIB}_FIND_COMPONENTS AND NOT ${COMPONENT} IN_LIST ${LIB}_FIND_COMPONENTS) return() endif() find_library(${LIB}_${COMPONENT}_LIBRARY NAMES ${ARG_NAMES} PATHS "" ${ARG_PATHS} HINTS "" ${ARG_HINTS} PATH_SUFFIXES "" ${ARG_PATH_SUFFIXES} ) mark_as_advanced(${LIB}_${COMPONENT}_LIBRARY) if(${LIB}_${COMPONENT}_LIBRARY) # On success, set the standard FOUND variable... set(${LIB}_${COMPONENT}_FOUND TRUE PARENT_SCOPE) # ... and append the library path to the LIBRARIES variable ... list(APPEND ${LIB}_LIBRARIES "${${LIB}_${COMPONENT}_LIBRARY}" ${ARG_INTERFACE_LINK_LIBRARIES} ) list(REMOVE_DUPLICATES ${LIB}_LIBRARIES) set(${LIB}_LIBRARIES ${${LIB}_LIBRARIES} PARENT_SCOPE) - + # ... and create an imported target for the component, if not already # done. if(NOT TARGET ${LIB}::${COMPONENT}) add_library(${LIB}::${COMPONENT} UNKNOWN IMPORTED) set_target_properties(${LIB}::${COMPONENT} PROPERTIES IMPORTED_LOCATION "${${LIB}_${COMPONENT}_LIBRARY}" ) set_property(TARGET ${LIB}::${COMPONENT} PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ARG_INCLUDE_DIRS} ) set_property(TARGET ${LIB}::${COMPONENT} PROPERTY INTERFACE_LINK_LIBRARIES ${ARG_INTERFACE_LINK_LIBRARIES} ) endif() find_package_message("${LIB}_${COMPONENT}" "Found ${LIB} component ${COMPONENT}: ${${LIB}_${COMPONENT}_LIBRARY}" "[${${LIB}_${COMPONENT}_LIBRARY}][${ARG_INCLUDE_DIRS}]" ) endif() endfunction() diff --git a/cmake/modules/FindBerkeleyDB.cmake b/cmake/modules/FindBerkeleyDB.cmake index 7930f197f5..7956e306be 100644 --- a/cmake/modules/FindBerkeleyDB.cmake +++ b/cmake/modules/FindBerkeleyDB.cmake @@ -1,172 +1,172 @@ # Copyright (c) 2017-2020 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. #.rst # FindBerkeleyDB # ------------- # # This is inspired by https://github.com/sum01/FindBerkeleyDB. # # Find the Berkeley database (versions >= 5.x) libraries The following # components are available:: # C # CXX # # This will define the following variables:: # # BerkeleyDB_FOUND - system has Berkeley DB lib # BerkeleyDB_INCLUDE_DIRS - the Berkeley DB include directories # BerkeleyDB_LIBRARIES - Libraries needed to use Berkeley DB # BerkeleyDB_VERSION - The library version MAJOR.MINOR.PATCH # BerkeleyDB_VERSION_MAJOR - Major version number # BerkeleyDB_VERSION_MINOR - Minor version number # BerkeleyDB_VERSION_PATCH - Patch version number # # And the following imported target:: # # BerkeleyDB::C # BerkeleyDB::CXX # Generate a list of all the possible versioned library name variants given a -# list of separators. +# list of separators. function(generate_versions_variants VARIANTS LIB MAJOR MINOR) set(SEPARATORS "" "." "-" "_" ) set(${VARIANTS} "${LIB}") foreach(_separator1 IN LISTS SEPARATORS) list(APPEND ${VARIANTS} "${LIB}${_separator1}${MAJOR}") foreach(_separator2 IN LISTS SEPARATORS) list(APPEND ${VARIANTS} "${LIB}${_separator1}${MAJOR}${_separator2}${MINOR}") endforeach() endforeach() set(${VARIANTS} ${${VARIANTS}} PARENT_SCOPE) endfunction() include(BrewHelper) find_brew_prefix(BREW_HINT berkeley-db) # If the include directory is user supplied, skip the search if(NOT BerkeleyDB_INCLUDE_DIR) # Berkeley DB 5 including latest minor release. generate_versions_variants(_BerkeleyDB_PATH_SUFFIXES_5_3 db 5 3) # Berkeley DB 6 including latest minor release. generate_versions_variants(_BerkeleyDB_PATH_SUFFIXES_6_2 db 6 2) # Berkeley DB 18 including latest minor release (current). generate_versions_variants(_BerkeleyDB_PATH_SUFFIXES_18_1 db 18 1) set(_BerkeleyDB_PATH_SUFFIXES ${_BerkeleyDB_PATH_SUFFIXES_5_3} ${_BerkeleyDB_PATH_SUFFIXES_6_2} ${_BerkeleyDB_PATH_SUFFIXES_18_1} ) list(REMOVE_DUPLICATES _BerkeleyDB_PATH_SUFFIXES) # Try to find the db.h header. # If the header is not found the user can supply the correct path by passing # the `BerkeleyDB_ROOT` variable to cmake. find_path(BerkeleyDB_INCLUDE_DIR NAMES db.h HINTS ${BREW_HINT} PATH_SUFFIXES ${_BerkeleyDB_PATH_SUFFIXES} ) endif() # There is a single common include directory. # Set the BerkeleyDB_INCLUDE_DIRS variable which is the expected standard output # variable name for the include directories. set(BerkeleyDB_INCLUDE_DIRS "${BerkeleyDB_INCLUDE_DIR}") mark_as_advanced(BerkeleyDB_INCLUDE_DIR) if(NOT DEFINED BerkeleyDB_VERSION) # Extract version information from the db.h header. if(BerkeleyDB_INCLUDE_DIR) # Read the version from file db.h into a variable. file(READ "${BerkeleyDB_INCLUDE_DIR}/db.h" _BerkeleyDB_DB_HEADER) - + # Parse the version into variables. string(REGEX REPLACE ".*DB_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MAJOR "${_BerkeleyDB_DB_HEADER}" ) string(REGEX REPLACE ".*DB_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" BerkeleyDB_VERSION_MINOR "${_BerkeleyDB_DB_HEADER}" ) # Patch version example on non-crypto installs: x.x.xNC string(REGEX REPLACE ".*DB_VERSION_PATCH[ \t]+([0-9]+(NC)?).*" "\\1" BerkeleyDB_VERSION_PATCH "${_BerkeleyDB_DB_HEADER}" ) else() # Set some garbage values to the versions since we didn't find a file to # read. set(BerkeleyDB_VERSION_MAJOR "0") set(BerkeleyDB_VERSION_MINOR "0") set(BerkeleyDB_VERSION_PATCH "0") endif() # Cache the result. set(BerkeleyDB_VERSION_MAJOR ${BerkeleyDB_VERSION_MAJOR} CACHE INTERNAL "BerekeleyDB major version number" ) set(BerkeleyDB_VERSION_MINOR ${BerkeleyDB_VERSION_MINOR} CACHE INTERNAL "BerekeleyDB minor version number" ) set(BerkeleyDB_VERSION_PATCH ${BerkeleyDB_VERSION_PATCH} CACHE INTERNAL "BerekeleyDB patch version number" ) # The actual returned/output version variable (the others can be used if # needed). set(BerkeleyDB_VERSION "${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}.${BerkeleyDB_VERSION_PATCH}" CACHE INTERNAL "BerekeleyDB full version" ) endif() include(ExternalLibraryHelper) # Different systems sometimes have a version in the lib name... # and some have a dash or underscore before the versions. # Generate all combinations from the separators "" (none), ".", "-" and "_". generate_versions_variants( _db_variants db "${BerkeleyDB_VERSION_MAJOR}" "${BerkeleyDB_VERSION_MINOR}" ) find_component(BerkeleyDB C NAMES ${_db_variants} HINTS ${BREW_HINT} PATH_SUFFIXES ${_db_variants} INCLUDE_DIRS ${BerkeleyDB_INCLUDE_DIRS} ) generate_versions_variants( _db_cxx_variants db_cxx "${BerkeleyDB_VERSION_MAJOR}" "${BerkeleyDB_VERSION_MINOR}" ) find_component(BerkeleyDB CXX NAMES ${_db_cxx_variants} HINTS ${BREW_HINT} PATH_SUFFIXES ${_db_variants} INCLUDE_DIRS ${BerkeleyDB_INCLUDE_DIRS} ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(BerkeleyDB REQUIRED_VARS BerkeleyDB_INCLUDE_DIR VERSION_VAR BerkeleyDB_VERSION HANDLE_COMPONENTS ) diff --git a/cmake/modules/FindGMP.cmake b/cmake/modules/FindGMP.cmake index b42c237366..b8a29272a9 100644 --- a/cmake/modules/FindGMP.cmake +++ b/cmake/modules/FindGMP.cmake @@ -1,97 +1,97 @@ # Copyright (c) 2017-2020 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. #.rst # FindGMP # ------------- # # Find the GNU Multiple Precision Arithmetic library. The following components # are available:: # gmp # # This will define the following variables:: # # GMP_FOUND - system has GMP lib # GMP_INCLUDE_DIRS - the GMP include directories # GMP_LIBRARIES - Library needed to use GMP # GMP_VERSION - The library version MAJOR.MINOR.PATCH # GMP_VERSION_MAJOR - The library MAJOR version number # GMP_VERSION_MINOR - The library MINOR version number # GMP_VERSION_PATCH - The library PATCH version number # # And the following imported target:: # # GMP::gmp include(BrewHelper) find_brew_prefix(BREW_HINT gmp) find_path(GMP_INCLUDE_DIR NAMES gmp.h HINTS ${BREW_HINT} ) set(GMP_INCLUDE_DIRS "${GMP_INCLUDE_DIR}") mark_as_advanced(GMP_INCLUDE_DIR) if(NOT DEFINED GMP_VERSION) # Extract version information from the gmp.h header. if(GMP_INCLUDE_DIR) # Read the version from file gmp.h into a variable. file(READ "${GMP_INCLUDE_DIR}/gmp.h" _GMP_HEADER) - + # Parse the version into variables. string(REGEX REPLACE ".*__GNU_MP_VERSION[ \t]+([0-9]+).*" "\\1" GMP_VERSION_MAJOR "${_GMP_HEADER}" ) string(REGEX REPLACE ".*__GNU_MP_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" GMP_VERSION_MINOR "${_GMP_HEADER}" ) string(REGEX REPLACE ".*__GNU_MP_VERSION_PATCHLEVEL[ \t]+([0-9]+).*" "\\1" GMP_VERSION_PATCH "${_GMP_HEADER}" ) else() # Set some garbage values to the versions since we didn't find a file to # read. set(GMP_VERSION_MAJOR "0") set(GMP_VERSION_MINOR "0") set(GMP_VERSION_PATCH "0") endif() # Cache the result. set(GMP_VERSION_MAJOR ${GMP_VERSION_MAJOR} CACHE INTERNAL "GMP major version number" ) set(GMP_VERSION_MINOR ${GMP_VERSION_MINOR} CACHE INTERNAL "GMP minor version number" ) set(GMP_VERSION_PATCH ${GMP_VERSION_PATCH} CACHE INTERNAL "GMP patch version number" ) # The actual returned/output version variable (the others can be used if # needed). set(GMP_VERSION "${GMP_VERSION_MAJOR}.${GMP_VERSION_MINOR}.${GMP_VERSION_PATCH}" CACHE INTERNAL "GMP full version" ) endif() include(ExternalLibraryHelper) find_component(GMP gmp NAMES gmp HINTS ${BREW_HINT} INCLUDE_DIRS ${GMP_INCLUDE_DIRS} ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GMP REQUIRED_VARS GMP_INCLUDE_DIR VERSION_VAR GMP_VERSION HANDLE_COMPONENTS ) diff --git a/cmake/modules/FindMiniUPnPc.cmake b/cmake/modules/FindMiniUPnPc.cmake index 829e6cbe76..0d4a66d7ec 100644 --- a/cmake/modules/FindMiniUPnPc.cmake +++ b/cmake/modules/FindMiniUPnPc.cmake @@ -1,79 +1,79 @@ # Copyright (c) 2019-2020 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. #.rst # FindMiniUPnPc # ------------- # # Find the MiniUPnPc library. The following # components are available:: # miniupnpc # # This will define the following variables:: # # MiniUPnPc_FOUND - system has MiniUPnPc lib # MiniUPnPc_INCLUDE_DIRS - the MiniUPnPc include directories # MiniUPnPc_LIBRARIES - Libraries needed to use MiniUPnPc # MiniUPnPc_VERSION - The library version MAJOR.MINOR.PATCH # # And the following imported target:: # # MiniUPnPc::miniupnpc include(BrewHelper) find_brew_prefix(BREW_HINT miniupnpc) find_package(PkgConfig) pkg_check_modules(PC_MiniUPnPc QUIET libqrencode) find_path(MiniUPnPc_INCLUDE_DIR NAMES miniupnpc.h HINTS ${BREW_HINT} PATHS ${PC_MiniUPnPc_INCLUDE_DIRS} PATH_SUFFIXES miniupnpc ) set(MiniUPnPc_INCLUDE_DIRS "${MiniUPnPc_INCLUDE_DIR}") mark_as_advanced(MiniUPnPc_INCLUDE_DIR) if(NOT DEFINED MiniUPnPc_VERSION) # Extract version information from the miniupnpc.h header. if(MiniUPnPc_INCLUDE_DIR) # Read the version from file miniupnpc.h into a variable. file(READ "${MiniUPnPc_INCLUDE_DIR}/miniupnpc.h" _MiniUPnPc_HEADER) - + # Parse the version into variable. string(REGEX REPLACE ".*MINIUPNPC_VERSION[ \t]+\"([0-9]+\.[0-9]+(\.[0-9]+)?)\".*" "\\1" MiniUPnPc_VERSION "${_MiniUPnPc_HEADER}" ) else() # Set some garbage values to the versions since we didn't find a file to # read. set(MiniUPnPc_VERSION "0.0.0") endif() set(MiniUPnPc_VERSION "${MiniUPnPc_VERSION}" CACHE INTERNAL "MiniUPnPc full version" ) endif() include(ExternalLibraryHelper) find_component(MiniUPnPc miniupnpc NAMES miniupnpc HINTS ${BREW_HINT} PATHS ${PC_MiniUPnPc_LIBRARY_DIRS} PATH_SUFFIXES miniupnpc INCLUDE_DIRS ${MiniUPnPc_INCLUDE_DIRS} INTERFACE_LINK_LIBRARIES "$<$:ws2_32;iphlpapi>" ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(MiniUPnPc REQUIRED_VARS MiniUPnPc_INCLUDE_DIR VERSION_VAR MiniUPnPc_VERSION HANDLE_COMPONENTS ) diff --git a/cmake/modules/FindZeroMQ.cmake b/cmake/modules/FindZeroMQ.cmake index 06d8d31ea1..a3025d641a 100644 --- a/cmake/modules/FindZeroMQ.cmake +++ b/cmake/modules/FindZeroMQ.cmake @@ -1,103 +1,103 @@ # Copyright (c) 2017-2020 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # .rst: # FindZeroMQ # -------------- # # Find the ZeroMQ library. The following conponents are # available:: # zmq # # This will define the following variables:: # # ZeroMQ_FOUND - True if the ZeroMQ library is found. # ZeroMQ_INCLUDE_DIRS - List of the header include directories. # ZeroMQ_LIBRARIES - List of the libraries. # ZeroMQ_VERSION - The library version MAJOR.MINOR.PATCH # ZeroMQ_VERSION_MAJOR - Major version number # ZeroMQ_VERSION_MINOR - Minor version number # ZeroMQ_VERSION_PATCH - Patch version number # # And the following imported targets:: # # ZeroMQ::zmq find_path(ZeroMQ_INCLUDE_DIR NAMES zmq.h ) set(ZeroMQ_INCLUDE_DIRS "${ZeroMQ_INCLUDE_DIR}") mark_as_advanced(ZeroMQ_INCLUDE_DIR) if(NOT DEFINED ZeroMQ_VERSION) # Extract version information from the zmq.h header. if(ZeroMQ_INCLUDE_DIR) # Read the version from file zmq.h into a variable. file(READ "${ZeroMQ_INCLUDE_DIR}/zmq.h" _ZMQ_HEADER) - + # Parse the version into variables. string(REGEX REPLACE ".*ZMQ_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" ZeroMQ_VERSION_MAJOR "${_ZMQ_HEADER}" ) string(REGEX REPLACE ".*ZMQ_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" ZeroMQ_VERSION_MINOR "${_ZMQ_HEADER}" ) # Patch version example on non-crypto installs: x.x.xNC string(REGEX REPLACE ".*ZMQ_VERSION_PATCH[ \t]+([0-9]+(NC)?).*" "\\1" ZeroMQ_VERSION_PATCH "${_ZMQ_HEADER}" ) else() # Set some garbage values to the versions since we didn't find a file to # read. set(ZeroMQ_VERSION_MAJOR "0") set(ZeroMQ_VERSION_MINOR "0") set(ZeroMQ_VERSION_PATCH "0") endif() # Cache the result. set(ZeroMQ_VERSION_MAJOR ${ZeroMQ_VERSION_MAJOR} CACHE INTERNAL "ZeroMQ major version number" ) set(ZeroMQ_VERSION_MINOR ${ZeroMQ_VERSION_MINOR} CACHE INTERNAL "ZeroMQ minor version number" ) set(ZeroMQ_VERSION_PATCH ${ZeroMQ_VERSION_PATCH} CACHE INTERNAL "ZeroMQ patch version number" ) # The actual returned/output version variable (the others can be used if # needed). set(ZeroMQ_VERSION "${ZeroMQ_VERSION_MAJOR}.${ZeroMQ_VERSION_MINOR}.${ZeroMQ_VERSION_PATCH}" CACHE INTERNAL "ZeroMQ full version" ) endif() include(ExternalLibraryHelper) # The dependency to iphlpapi starts from 4.2.0 if(ZeroMQ_VERSION VERSION_LESS 4.2.0) set(_ZeroMQ_WINDOWS_LIBRARIES "$<$:ws2_32;rpcrt4>") else() set(_ZeroMQ_WINDOWS_LIBRARIES "$<$:ws2_32;rpcrt4;iphlpapi>") endif() find_component(ZeroMQ zmq NAMES zmq INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIRS} INTERFACE_LINK_LIBRARIES "${_ZeroMQ_WINDOWS_LIBRARIES}" ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(ZeroMQ REQUIRED_VARS ZeroMQ_INCLUDE_DIR VERSION_VAR ZeroMQ_VERSION HANDLE_COMPONENTS ) diff --git a/cmake/modules/NativeExecutable.cmake b/cmake/modules/NativeExecutable.cmake index f4756d305f..bf73cc1d14 100644 --- a/cmake/modules/NativeExecutable.cmake +++ b/cmake/modules/NativeExecutable.cmake @@ -1,132 +1,132 @@ # Allow to easily build native executable. # Useful for cross compilation. if(NOT DEFINED __IS_NATIVE_BUILD) # Check if we are in a native build or not. set(__IS_NATIVE_BUILD 0 CACHE INTERNAL "Indicate if this is a native build") endif() if(__IS_NATIVE_BUILD AND CMAKE_CROSSCOMPILING) message(FATAL_ERROR "A native build cannot be cross compiled") endif() # It is imperative that NATIVE_BUILD_DIR be in the cache. set(NATIVE_BUILD_DIR "${CMAKE_BINARY_DIR}/native" CACHE PATH "The path of the native build directory" FORCE) # Only ninja support depfiles and this is a hard error with other generators # so we need a nice wrapper to handle this mess. include(CustomCommandWithDepFile) function(add_native_executable NAME) if(__IS_NATIVE_BUILD) add_executable(${NAME} EXCLUDE_FROM_ALL ${ARGN}) # Multi-configuration generators (VS, Xcode) append a per-configuration - # subdirectory to the specified directory unless the + # subdirectory to the specified directory unless the # `RUNTIME_OUTPUT_DIRECTORY` property is defined using a generator # expression. # Since we don't care about the build configuration for native # executables, we can simply drop this subdirectory. # Doing so ensure that the path to the binary can always be retrieved. set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<0:>" ) else() set(NATIVE_TARGET "${NAME}") file(RELATIVE_PATH RELATIVE_PATH "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") if(RELATIVE_PATH) string(PREPEND NATIVE_TARGET "${RELATIVE_PATH}/") endif() if("${CMAKE_GENERATOR}" MATCHES "Ninja") set(TARGET "${NATIVE_TARGET}") else() set(TARGET "${NAME}") endif() set(NATIVE_BINARY "${NATIVE_BUILD_DIR}/${NATIVE_TARGET}") set(NATIVE_LINK "${CMAKE_CURRENT_BINARY_DIR}/native-${NAME}") configure_file( "${CMAKE_SOURCE_DIR}/cmake/templates/NativeBuildRunner.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/build_native_${NAME}.sh" ) # We create a symlink because cmake craps itself if the imported # executable has the same name as the executable itself. # https://cmake.org/pipermail/cmake/2019-May/069480.html add_custom_command_with_depfile( OUTPUT "${NATIVE_LINK}" COMMENT "Building native ${NATIVE_TARGET}" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/build_native_${NAME}.sh" DEPENDS native-cmake-build "${CMAKE_CURRENT_BINARY_DIR}/build_native_${NAME}.sh" ${ARGN} DEPFILE "${NATIVE_LINK}.d" VERBATIM USES_TERMINAL ) add_executable(${NAME} IMPORTED GLOBAL) set_target_properties(${NAME} PROPERTIES IMPORTED_LOCATION "${NATIVE_BINARY}") # This obviously cannot depend on a file for some mysterious reasons only # the cmake gods are aware of, so we need a phony custom target. add_custom_target("build-native-${NAME}" DEPENDS "${NATIVE_LINK}") add_dependencies(${NAME} "build-native-${NAME}") endif() endfunction(add_native_executable) function(native_target_include_directories) if(__IS_NATIVE_BUILD) target_include_directories(${ARGN}) endif() endfunction(native_target_include_directories) function(native_add_cmake_flags) set_property(GLOBAL APPEND PROPERTY _NATIVE_BUILD_CMAKE_FLAGS ${ARGN}) endfunction(native_add_cmake_flags) # Internal machinery function(_gen_native_cmake_target) message(STATUS "Configuring native build in ${NATIVE_BUILD_DIR}") get_property(ARGSLIST GLOBAL PROPERTY _NATIVE_BUILD_CMAKE_FLAGS) list(SORT ARGSLIST) list(REMOVE_DUPLICATES ARGSLIST) list(JOIN ARGSLIST " " ARGS) file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/config") configure_file( "${CMAKE_SOURCE_DIR}/cmake/templates/NativeCmakeRunner.cmake.in" "${CMAKE_BINARY_DIR}/config/run_native_cmake.sh" ) endfunction(_gen_native_cmake_target) function(_gen_native_cmake_hook VAR ACCESS) # When CMAKE_CURRENT_LIST_DIR is set to empty, we execute everything. if("${VAR}" STREQUAL "CMAKE_CURRENT_LIST_DIR" AND "${CMAKE_CURRENT_LIST_DIR}" STREQUAL "" AND "${ACCESS}" STREQUAL "MODIFIED_ACCESS") _gen_native_cmake_target() endif() endfunction(_gen_native_cmake_hook) if(NOT __IS_NATIVE_BUILD AND NOT TARGET native-cmake-build) # Set a hook to execute when everything is set. variable_watch(CMAKE_CURRENT_LIST_DIR _gen_native_cmake_hook) add_custom_command_with_depfile( OUTPUT "${NATIVE_BUILD_DIR}/CMakeCache.txt" COMMENT "Preparing native build..." COMMAND "${CMAKE_BINARY_DIR}/config/run_native_cmake.sh" DEPENDS "${CMAKE_BINARY_DIR}/config/run_native_cmake.sh" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" DEPFILE "${NATIVE_BUILD_DIR}/CMakeFiles/CMakeCache.txt.d" VERBATIM USES_TERMINAL ) add_custom_target(native-cmake-build DEPENDS "${NATIVE_BUILD_DIR}/CMakeCache.txt") # Add the native directory to the list of file to cleanup. set_property(DIRECTORY "${CMAKE_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${NATIVE_BUILD_DIR}") endif() diff --git a/cmake/modules/SanitizeHelper.cmake b/cmake/modules/SanitizeHelper.cmake index e01b8e4140..3169673e46 100644 --- a/cmake/modules/SanitizeHelper.cmake +++ b/cmake/modules/SanitizeHelper.cmake @@ -1,39 +1,39 @@ macro(_sanitize REPLACEMENT_REGEX REPLACEMENT_STRING RAW_VAR SANITIZED_VAR) string(REGEX REPLACE "${REPLACEMENT_REGEX}" "${REPLACEMENT_STRING}" ${SANITIZED_VAR} "${RAW_VAR}") endmacro() # Sanitize a variable according to cmake rules # https://cmake.org/cmake/help/v3.10/manual/cmake-language.7.html#variable-references # The NUL and ';' characters cannot be escaped in this context (see CMP0053) macro(sanitize_variable PREFIX RAW_VAR SANITIZED_VAR) # Escaping characters not in the supported list (see documentation) will # work as long as the variable is not cached. - + # Variable caching is achieved by writing the variable to a CMakeCache.txt # file, where the escaped chars get interpreted. The issue occurs when the # cache is read, as the chars are not getting escaped again and cause the # read to fail. - + # The safe way to sanitize a variable is not to escape these chars, but # rather to replace them with a known supported one, here '_' is chosen. # Not: this could lead to name collision in some rare case. These case can # be handled manually by using a different prefix. _sanitize("([^a-zA-Z0-9/_.+-])" "_" "${PREFIX}${RAW_VAR}" ${SANITIZED_VAR}) endmacro() # Sanitize a variable intended to be used in a C/CXX #define statement. # This is useful when using CHECK__COMPILER_FLAG or similar functions. macro(sanitize_c_cxx_definition PREFIX RAW_VAR SANITIZED_VAR) # Only allow for alphanum chars plus underscore. This will prevent the # compiler to issue a warning like: # `ISO C99 requires whitespace after the macro name [-Wc99-extensions]` _sanitize("([^a-zA-Z0-9_])" "_" "${PREFIX}${RAW_VAR}" ${SANITIZED_VAR}) endmacro() # Sanitize a variable intended to be used as a cmake target name. macro(sanitize_target_name PREFIX RAW_VAR SANITIZED_VAR) # Target names may contain upper and lower case letters, numbers, # underscore, dot, plus and minus. _sanitize("([^a-zA-Z0-9_.+-])" "-" "${PREFIX}${RAW_VAR}" ${SANITIZED_VAR}) endmacro() diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt index 0b073c4edc..30f218d9de 100644 --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -1,71 +1,71 @@ # Copyright (c) 2018 The Bitcoin developers project(bitcoin-bench) set(BENCH_DATA_RAW_FILES data/block413567.raw ) # Process raw files. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/data") foreach(_raw_file ${BENCH_DATA_RAW_FILES}) string(APPEND _generated_header_output "${CMAKE_CURRENT_BINARY_DIR}/${_raw_file}" ".h" ) list(APPEND BENCH_DATA_GENERATED_HEADERS ${_generated_header_output}) get_filename_component(_test_name ${_raw_file} NAME_WE) add_custom_command( OUTPUT "${_generated_header_output}" - COMMAND + COMMAND "${Python_EXECUTABLE}" "data/convert-raw-to-header.py" "${_test_name}" "${_raw_file}" > "${_generated_header_output}" COMMENT "Transforming raw file ${_raw_file} into header" MAIN_DEPEDENCY "${_raw_file}" DEPENDS "data/convert-raw-to-header.py" VERBATIM WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) endforeach() add_executable(bitcoin-bench base58.cpp bench.cpp bench_bitcoin.cpp cashaddr.cpp ccoins_caching.cpp checkblock.cpp checkqueue.cpp crypto_aes.cpp crypto_hash.cpp duplicate_inputs.cpp examples.cpp gcs_filter.cpp lockedpool.cpp mempool_eviction.cpp merkle_root.cpp prevector.cpp rollingbloom.cpp rpc_mempool.cpp util_time.cpp # TODO: make a test library ../test/setup_common.cpp # Add the generated headers to trigger the conversion command ${BENCH_DATA_GENERATED_HEADERS} ) target_link_libraries(bitcoin-bench common bitcoinconsensus server) if(BUILD_BITCOIN_WALLET) target_sources(bitcoin-bench PRIVATE coin_selection.cpp) target_link_libraries(bitcoin-bench wallet) endif() add_custom_target(bench-bitcoin COMMAND bitcoin-bench USES_TERMINAL) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index cc56322d64..04ae3130ca 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -1,594 +1,594 @@ # Copyright (c) 2018 The Bitcoin developers project(bitcoin-qt) # This ensure that AUTOMOC doesn't run on generated files. cmake_policy(SET CMP0071 OLD) include(BrewHelper) find_brew_prefix(QT5_PREFIX qt5) set(QT_REQUIRED_COMPONENTS Core Widgets Network Test) if(ENABLE_NOTIFICATIONS) list(APPEND QT_REQUIRED_COMPONENTS DBus) endif() find_package(Qt5 5.5.1 COMPONENTS ${QT_REQUIRED_COMPONENTS} REQUIRED HINTS "${QT5_PREFIX}") # Localisation add_subdirectory(locale) add_custom_command(OUTPUT temp_bitcoin_locale.qrc COMMAND cmake ARGS -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bitcoin_locale.qrc" temp_bitcoin_locale.qrc MAIN_DEPENDENCY bitcoin_locale.qrc VERBATIM ) add_custom_command(OUTPUT qrc_bitcoin_locale.cpp COMMAND Qt5::rcc ARGS temp_bitcoin_locale.qrc -name bitcoin_locale -o qrc_bitcoin_locale.cpp MAIN_DEPENDENCY temp_bitcoin_locale.qrc DEPENDS locales VERBATIM ) # UI elements # qt5_wrap_ui() generates the files in the CMAKE_CURRENT_BINARY_DIR. As there # is no option to change the output directory, moving the files to the forms # subdirectory requires to override the variable. It is reset to its actual # value after the call so it does not impact the other sections of this # CMakeLists.txt file. set(SAVE_CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/forms") # It seems that some generators (at least the Unix Makefiles one) doesn't create # the build directory required by a custom command, so do it manually. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) qt5_wrap_ui(UI_GENERATED_HEADERS forms/addressbookpage.ui forms/askpassphrasedialog.ui forms/coincontroldialog.ui forms/editaddressdialog.ui forms/helpmessagedialog.ui forms/intro.ui forms/modaloverlay.ui forms/openuridialog.ui forms/optionsdialog.ui forms/overviewpage.ui forms/receivecoinsdialog.ui forms/receiverequestdialog.ui forms/debugwindow.ui forms/sendcoinsdialog.ui forms/sendcoinsentry.ui forms/signverifymessagedialog.ui forms/transactiondescdialog.ui ) set(CMAKE_CURRENT_BINARY_DIR ${SAVE_CMAKE_CURRENT_BINARY_DIR}) # Qt MOC set(CMAKE_AUTOMOC ON) # Handle qrc resources qt5_add_resources(QRC_BITCOIN_CPP bitcoin.qrc) add_library(bitcoin-qt-base bantablemodel.cpp bitcoin.cpp bitcoinaddressvalidator.cpp bitcoinamountfield.cpp bitcoingui.cpp bitcoinunits.cpp clientmodel.cpp csvmodelwriter.cpp guiutil.cpp intro.cpp modaloverlay.cpp networkstyle.cpp notificator.cpp optionsdialog.cpp optionsmodel.cpp peertablemodel.cpp platformstyle.cpp qvalidatedlineedit.cpp qvaluecombobox.cpp rpcconsole.cpp splashscreen.cpp trafficgraphwidget.cpp utilitydialog.cpp # Handle ui files ${UI_GENERATED_HEADERS} # Translations ${BITCOIN_QM_FILES} # Handle qrc files ${QRC_BITCOIN_CPP} qrc_bitcoin_locale.cpp ) # Add the minimal integration plugin, and other plugins according to the target # platform. set(QT_PLUGIN_COMPONENTS QMinimalIntegrationPlugin) set(QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_MINIMAL=1) # Linux support if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") list(APPEND QT_PLUGIN_COMPONENTS QXcbIntegrationPlugin) list(APPEND QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_XCB=1) endif() # Windows support if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") list(APPEND QT_PLUGIN_COMPONENTS QWindowsIntegrationPlugin) list(APPEND QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_WINDOWS=1) target_sources(bitcoin-qt-base PRIVATE winshutdownmonitor.cpp) endif() # OSX support if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") list(APPEND QT_PLUGIN_COMPONENTS QCocoaIntegrationPlugin) list(APPEND QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_COCOA=1) target_sources(bitcoin-qt-base PRIVATE macdockiconhandler.mm macnotificationhandler.mm ) set_property(TARGET bitcoin-qt-base PROPERTY AUTOMOC_MOC_OPTIONS "-DQ_OS_MAC") target_link_libraries(bitcoin-qt-base "-framework Foundation" "-framework ApplicationServices" "-framework AppKit" ) endif() # Find out more about Qt. This is similar to # http://code.qt.io/cgit/qt/qtwebkit.git/tree/Source/cmake/OptionsQt.cmake get_target_property(QT_CORE_TYPE Qt5::Core TYPE) if(QT_CORE_TYPE MATCHES STATIC) set(QT_STATIC_BUILD ON) endif() # Determine the Qt libraries directory from the QT5::Core library location get_target_property(QT_CORE_LIB_LOCATION Qt5::Core LOCATION) get_filename_component(QT5_LIB_DIR "${QT_CORE_LIB_LOCATION}" DIRECTORY) set(STATIC_DEPENDENCIES_CMAKE_FILE "${CMAKE_BINARY_DIR}/QtStaticDependencies.cmake") if(EXISTS ${STATIC_DEPENDENCIES_CMAKE_FILE}) file(REMOVE ${STATIC_DEPENDENCIES_CMAKE_FILE}) endif() set(CONVERT_PRL_PATH "${CONTRIB_PATH}/qt/convert-prl-libs-to-cmake.pl") macro(CONVERT_PRL_LIBS_TO_CMAKE _qt_component) if(TARGET Qt5::${_qt_component}) get_target_property(_lib_location Qt5::${_qt_component} LOCATION) execute_process(COMMAND ${PERL_EXECUTABLE} "${CONVERT_PRL_PATH}" --lib "${_lib_location}" --qt_lib_install_dir "${QT5_LIB_DIR}" --out "${STATIC_DEPENDENCIES_CMAKE_FILE}" --component "${_qt_component}" --compiler "${CMAKE_CXX_COMPILER_ID}" ) endif() endmacro() if(QT_STATIC_BUILD) list(APPEND QT_REQUIRED_COMPONENTS ${QT_PLUGIN_COMPONENTS}) foreach(qt_module ${QT_REQUIRED_COMPONENTS}) CONVERT_PRL_LIBS_TO_CMAKE(${qt_module}) endforeach() # HACK: We must explicitly add LIB path of the Qt installation # to correctly find qtpcre link_directories("${QT5_LIB_DIR}") # Now that we generated the dependencies, import them. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CONVERT_PRL_PATH}") if(NOT EXISTS ${STATIC_DEPENDENCIES_CMAKE_FILE}) message(FATAL_ERROR "Unable to find ${STATIC_DEPENDENCIES_CMAKE_FILE}") endif() include(${STATIC_DEPENDENCIES_CMAKE_FILE}) list(REMOVE_DUPLICATES STATIC_LIB_DEPENDENCIES) # According to Qt documentation (https://doc.qt.io/qt-5/plugins-howto.html): # "Plugins can be linked statically into your application. # If you build the static version of Qt, this is the only option for # including Qt's predefined plugins." # So if the Qt build is static, the plugins should also be static and we # need to define QT_STATICPLUGIN to tell the code to import . target_compile_definitions(bitcoin-qt-base PUBLIC -DQT_STATICPLUGIN=1) # Add the platform plugin definition if required # Setting this definition tells the code what is the target for Q_IMPORT_PLUGIN(). foreach(qt_platform_definition ${QT_PLUGIN_PLATFORM_DEFINITIONS}) target_compile_definitions(bitcoin-qt-base PUBLIC "${qt_platform_definition}") endforeach() # Link the required plugins foreach(qt_plugin ${QT_PLUGIN_COMPONENTS}) target_link_libraries(bitcoin-qt-base Qt5::${qt_plugin}) endforeach() endif() target_link_libraries(bitcoin-qt-base server rpcclient Qt5::Widgets Qt5::Network ) if(ENABLE_NOTIFICATIONS) target_link_libraries(bitcoin-qt-base Qt5::DBus) endif() if(ENABLE_BIP70) # Do protobuf codegen find_package(Protobuf REQUIRED) protobuf_generate_cpp(PROTOBUF_SOURCES PROTOBUF_HEADERS paymentrequest.proto) - + add_library(bitcoin-qt-protobuf OBJECT # Protobuf codegen ${PROTOBUF_HEADERS} ${PROTOBUF_SOURCES} ) target_include_directories(bitcoin-qt-protobuf PUBLIC ${Protobuf_INCLUDE_DIRS}) target_link_libraries(bitcoin-qt-protobuf ${Protobuf_LIBRARIES}) # Don't run clang-tidy on generated files if(ENABLE_CLANG_TIDY) include(ClangTidy) target_disable_clang_tidy(bitcoin-qt-protobuf) endif() target_link_libraries(bitcoin-qt-base OpenSSL::SSL bitcoin-qt-protobuf ) endif() # Wallet if(BUILD_BITCOIN_WALLET) # Automoc option. set(AUTOMOC_MOC_OPTIONS -DENABLE_WALLET=1) # Add wallet functionality to bitcoin-qt target_sources(bitcoin-qt-base PRIVATE addressbookpage.cpp addresstablemodel.cpp askpassphrasedialog.cpp coincontroldialog.cpp coincontroltreewidget.cpp editaddressdialog.cpp openuridialog.cpp overviewpage.cpp paymentserver.cpp receivecoinsdialog.cpp receiverequestdialog.cpp recentrequeststablemodel.cpp sendcoinsdialog.cpp sendcoinsentry.cpp signverifymessagedialog.cpp transactiondesc.cpp transactiondescdialog.cpp transactionfilterproxy.cpp transactionrecord.cpp transactiontablemodel.cpp transactionview.cpp walletcontroller.cpp walletframe.cpp walletmodel.cpp walletmodeltransaction.cpp walletview.cpp ) # Add BIP70 functionality to bitcoin-qt if(ENABLE_BIP70) target_sources(bitcoin-qt-base PRIVATE paymentrequestplus.cpp ) endif() target_link_libraries(bitcoin-qt-base wallet) if(ENABLE_QRCODE) find_package(QREncode REQUIRED) target_link_libraries(bitcoin-qt-base QREncode::qrencode) endif() endif() # The executable add_executable(bitcoin-qt WIN32 main.cpp) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") target_sources(bitcoin-qt PRIVATE res/bitcoin-qt-res.rc) endif() target_link_libraries(bitcoin-qt bitcoin-qt-base) include(BinaryTest) add_to_symbols_check(bitcoin-qt) add_to_security_check(bitcoin-qt) include(InstallationHelper) install_target(bitcoin-qt) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(BITCOINQT_BUNDLE_ICON "res/icons/bitcoin.icns") get_filename_component(BITCOINQT_BUNDLE_ICON_NAME "${BITCOINQT_BUNDLE_ICON}" NAME ) set(INFO_PLIST_STRINGS_FILE "Base.lproj/InfoPlist.strings") set(INFO_PLIST_STRINGS_PATH "${CMAKE_CURRENT_BINARY_DIR}/${INFO_PLIST_STRINGS_FILE}") file(WRITE "${INFO_PLIST_STRINGS_PATH}" "{ CFBundleDisplayName = \"${PACKAGE_NAME}\"; CFBundleName = \"${PACKAGE_NAME}\"; }" ) set(EMPTY_LPROJ_FILE "${CMAKE_CURRENT_BINARY_DIR}/empty.lproj") file(TOUCH "${EMPTY_LPROJ_FILE}") target_sources(bitcoin-qt PRIVATE "${BITCOINQT_BUNDLE_ICON}" "${INFO_PLIST_STRINGS_PATH}" "${EMPTY_LPROJ_FILE}" ) string(JOIN ";" BITCOINQT_BUNDLE_RESOURCES "${BITCOINQT_BUNDLE_ICON}" "${EMPTY_LPROJ_FILE}" ) set(BITCOIN_QT_OSX_BUNDLE_NAME "BitcoinABC-Qt") set_target_properties(bitcoin-qt PROPERTIES MACOSX_BUNDLE ON OUTPUT_NAME "${BITCOIN_QT_OSX_BUNDLE_NAME}" MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/share/qt/Info.plist.cmake.in" MACOSX_BUNDLE_BUNDLE_NAME "${BITCOIN_QT_OSX_BUNDLE_NAME}" MACOSX_BUNDLE_BUNDLE_VERSION "${bitcoin-abc_VERSION}" MACOSX_BUNDLE_GUI_IDENTIFIER "org.bitcoinabc.${BITCOIN_QT_OSX_BUNDLE_NAME}" MACOSX_BUNDLE_ICON_FILE "${BITCOINQT_BUNDLE_ICON_NAME}" MACOSX_BUNDLE_INFO_STRING "${bitcoin-abc_VERSION}, Copyright © 2009-${COPYRIGHT_YEAR} ${COPYRIGHT_HOLDERS_FINAL}" MACOSX_BUNDLE_LONG_VERSION_STRING "${bitcoin-abc_VERSION}" MACOSX_BUNDLE_SHORT_VERSION_STRING "${bitcoin-abc_VERSION}" RESOURCE "${BITCOINQT_BUNDLE_RESOURCES}" ) # The InfoPlist.strings files should be located in a resource subdirectory. # This is not supported by the RESOURCE property and require the use of the # MACOSX_PACKAGE_LOCATION property instead. The RESOURCE documentation has # an example demonstrating this behavior (see the appres.txt file): # https://cmake.org/cmake/help/latest/prop_tgt/RESOURCE.html set_source_files_properties( "${INFO_PLIST_STRINGS_PATH}" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${INFO_PLIST_STRINGS_FILE}" ) # Create a stripped version of the application bundle to be used in the DMG. # Since the LOCATION property and the BundleUtilities package are deprecated # by cmake, only generator expressions can be used to determine the path to # the bundle and its executable. However the generator expressions are # solved at build time, making them unusable to do path computation at # configuration time. # The paths here are then hard-coded, which is safe since the structure of # an application bundle is well-known and specified by Apple. Note that this # will only work for building MacOS application bundle as the IOS structure # is slightly different. set(STRIPPED_BUNDLE "${CMAKE_CURRENT_BINARY_DIR}/stripped/${BITCOIN_QT_OSX_BUNDLE_NAME}.app") add_custom_command( OUTPUT "${STRIPPED_BUNDLE}" COMMAND ${CMAKE_COMMAND} -E copy_directory "$" "${STRIPPED_BUNDLE}" COMMAND ${CMAKE_STRIP} -u -r "${STRIPPED_BUNDLE}/Contents/MacOS/${BITCOIN_QT_OSX_BUNDLE_NAME}" DEPENDS bitcoin-qt ) include(DoOrFail) find_program_or_fail(CMAKE_INSTALL_NAME_TOOL "install_name_tool") find_program_or_fail(CMAKE_OTOOL "otool") set(QT_INSTALLER_SUPPORTED_LANGUAGES "da" "de" "es" "hu" "ru" "uk" "zh_CN" "zh_TW" ) string(JOIN "," QT_LOCALES ${QT_INSTALLER_SUPPORTED_LANGUAGES}) get_target_property(QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) execute_process( - COMMAND + COMMAND "${QMAKE_EXECUTABLE}" -query QT_INSTALL_TRANSLATIONS OUTPUT_VARIABLE QT_TRANSLATION_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ) function(get_qt_translation_dir QT_TRANSLATION_DIR) foreach(_locale ${ARGN}) find_path(_qt_translation_dir "qt_${_locale}.qm" HINTS "${QT_TRANSLATION_DIR}" PATH_SUFFIXES "translations" ) # Ensure that all the translation files are found, and are located # in the same directory. if(NOT _qt_translation_dir OR (_qt_translation_dir_previous AND (NOT _qt_translation_dir_previous STREQUAL _qt_translation_dir))) return() endif() set(_qt_translation_dir_previous _qt_translation_dir) endforeach() set(QT_TRANSLATION_DIR ${_qt_translation_dir} PARENT_SCOPE) endfunction() get_qt_translation_dir(QT_TRANSLATION_DIR ${QT_INSTALLER_SUPPORTED_LANGUAGES}) if(NOT QT_TRANSLATION_DIR) message(FATAL_ERROR "Qt translation files are not found") endif() set(MACDEPLOY_DIR "${CMAKE_SOURCE_DIR}/contrib/macdeploy") set(MACDEPLOYQTPLUS "${MACDEPLOY_DIR}/macdeployqtplus") set(DMG_DIST "${CMAKE_BINARY_DIR}/dist") add_custom_command( OUTPUT "${DMG_DIST}" COMMAND "INSTALLNAMETOOL=${CMAKE_INSTALL_NAME_TOOL}" "OTOOL=${CMAKE_OTOOL}" "STRIP=${CMAKE_STRIP}" "${Python_EXECUTABLE}" "${MACDEPLOYQTPLUS}" "${STRIPPED_BUNDLE}" -translations-dir "${QT_TRANSLATION_DIR}" -add-qt-tr "${QT_LOCALES}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" DEPENDS "${STRIPPED_BUNDLE}" ) # Building the DMG background image requires several steps: # 1/ The SVG file must be edited to display the package name # 2/ The SVG file should be transformed into a couple PNG files, on for # low resolution screens and one for high resolution screens. # 3/ The PNG files must be transformed into a multi-resolution TIFF file. # The names are not set arbitrarily, they follow Apple's guidelines for # resolution independent bitmap images (see `man tiffutil`). set(BACKGROUND_SVG "background.svg") configure_file( "${CMAKE_SOURCE_DIR}/contrib/macdeploy/background.svg.cmake.in" "${BACKGROUND_SVG}" ) include(ImageHelper) set(BACKGROUND_PNG_LOWRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp.png") set(BACKGROUND_PNG_HIRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp@2x.png") set(BACKGROUND_TIFF_LOWRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp.tiff") set(BACKGROUND_TIFF_HIRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp@2x.tiff") set(BACKGROUND_TIFF_NAME "background.tiff") set(BACKGROUND_TIFF_MULTIRES "${CMAKE_BINARY_DIR}/${BACKGROUND_TIFF_NAME}") convert_svg_to_png("${BACKGROUND_SVG}" "${BACKGROUND_PNG_LOWRES}" 36) convert_svg_to_png("${BACKGROUND_SVG}" "${BACKGROUND_PNG_HIRES}" 72) convert_png_to_tiff("${BACKGROUND_PNG_LOWRES}" "${BACKGROUND_TIFF_LOWRES}") convert_png_to_tiff("${BACKGROUND_PNG_HIRES}" "${BACKGROUND_TIFF_HIRES}") cat_multi_resolution_tiff("${BACKGROUND_TIFF_MULTIRES}" "${BACKGROUND_TIFF_LOWRES}" "${BACKGROUND_TIFF_HIRES}") set(BACKGROUND_DIST_DIR "${DMG_DIST}/.background") set(BACKGROUND_DIST_TIFF "${BACKGROUND_DIST_DIR}/${BACKGROUND_TIFF_NAME}") add_custom_command( OUTPUT "${BACKGROUND_DIST_TIFF}" COMMAND ${CMAKE_COMMAND} -E make_directory "${BACKGROUND_DIST_DIR}" COMMAND ${CMAKE_COMMAND} -E copy "${BACKGROUND_TIFF_MULTIRES}" "${BACKGROUND_DIST_TIFF}" DEPENDS "${BACKGROUND_TIFF_MULTIRES}" "${DMG_DIST}" ) string(REPLACE " " "-" OSX_VOLNAME "${PACKAGE_NAME}") file(WRITE "${CMAKE_BINARY_DIR}/osx_volname" "${OSX_VOLNAME}") set(DMG_DSSTORE "${DMG_DIST}/.DS_Store") set(GEN_DSSTORE "${MACDEPLOY_DIR}/custom_dsstore.py") add_custom_command( OUTPUT "${DMG_DSSTORE}" COMMAND "${Python_EXECUTABLE}" "${GEN_DSSTORE}" "${DMG_DSSTORE}" "${OSX_VOLNAME}" DEPENDS "${GEN_DSSTORE}" "${DMG_DIST}" ) set(OSX_APPLICATION_DIR "Applications") set(OSX_APPLICATION_SYMLINK "${DMG_DIST}/${OSX_APPLICATION_DIR}") add_custom_command( OUTPUT "${OSX_APPLICATION_SYMLINK}" COMMAND ${CMAKE_COMMAND} -E create_symlink "/${OSX_APPLICATION_DIR}" "${OSX_APPLICATION_SYMLINK}" DEPENDS "${DMG_DIST}" ) add_custom_target(osx-deploydir DEPENDS "${OSX_APPLICATION_SYMLINK}" "${DMG_DSSTORE}" "${BACKGROUND_DIST_TIFF}" ) if(CMAKE_CROSSCOMPILING) find_program_or_fail(GENISOIMAGE_EXECUTABLE genisoimage) add_custom_target(osx-dmg COMMAND "${GENISOIMAGE_EXECUTABLE}" -no-cache-inodes -D -l -probe -V "${OSX_VOLNAME}" -no-pad -r -dir-mode 0755 -apple -o "${OSX_VOLNAME}.dmg" "${DMG_DIST}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" ) add_dependencies(osx-dmg osx-deploydir) else() add_custom_target(osx-dmg COMMAND "${Python_EXECUTABLE}" "${MACDEPLOYQTPLUS}" "${STRIPPED_BUNDLE}" -translations-dir "${QT_TRANSLATION_DIR}" -add-qt-tr "${QT_LOCALES}" -dmg -fancy "${MACDEPLOY_DIR}/fancy.plist" -volname "${OSX_VOLNAME}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" DEPENDS "${STRIPPED_BUNDLE}" "${BACKGROUND_TIFF_MULTIRES}" ) endif() endif() # Test tests add_subdirectory(test)