diff --git a/CMakeLists.txt b/CMakeLists.txt index 941c97573a854..e93067c7b23f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -556,22 +556,20 @@ else() ) endif() -if(CMAKE_CROSSCOMPILING) - target_compile_definitions(core_base_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS}) - target_compile_definitions(core_depends_release_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_RELWITHDEBINFO}) - target_compile_definitions(core_depends_debug_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_DEBUG}) - - # If {C,CXX}FLAGS variables are defined during building depends and - # configuring this build system, their content might be duplicated. - if(DEFINED ENV{CFLAGS}) - deduplicate_flags(CMAKE_C_FLAGS) - endif() - if(DEFINED ENV{CXXFLAGS}) - deduplicate_flags(CMAKE_CXX_FLAGS) - endif() - if(DEFINED ENV{LDFLAGS}) - deduplicate_flags(CMAKE_EXE_LINKER_FLAGS) - endif() +target_compile_definitions(core_base_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS}) +target_compile_definitions(core_depends_release_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_RELWITHDEBINFO}) +target_compile_definitions(core_depends_debug_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_DEBUG}) + +# If {C,CXX,LD}FLAGS variables are defined during building depends and +# configuring this build system, their content might be duplicated. +if(DEFINED ENV{CFLAGS}) + deduplicate_flags(CMAKE_C_FLAGS) +endif() +if(DEFINED ENV{CXXFLAGS}) + deduplicate_flags(CMAKE_CXX_FLAGS) +endif() +if(DEFINED ENV{LDFLAGS}) + deduplicate_flags(CMAKE_EXE_LINKER_FLAGS) endif() add_subdirectory(src) diff --git a/cmake/module/Maintenance.cmake b/cmake/module/Maintenance.cmake index 1d4d61a4b38a2..68c639abc5be2 100644 --- a/cmake/module/Maintenance.cmake +++ b/cmake/module/Maintenance.cmake @@ -30,11 +30,15 @@ function(add_maintenance_targets) else() set(exe_format ELF) endif() - if(CMAKE_CROSSCOMPILING) - list(JOIN DEPENDS_C_COMPILER_WITH_LAUNCHER " " c_compiler_command) - else() - set(c_compiler_command ${CMAKE_C_COMPILER}) - endif() + + # In CMake, the components of the compiler invocation are separated into three distinct variables: + # - CMAKE_C_COMPILER_LAUNCHER: a semicolon-separated list of launchers or tools to precede the compiler (e.g., env or ccache). + # - CMAKE_C_COMPILER: the full path to the compiler binary itself (e.g., /usr/bin/clang). + # - CMAKE_C_COMPILER_ARG1: a string containing initial compiler options (e.g., --target=x86_64-apple-darwin -nostdlibinc). + # By concatenating these variables, we form the complete command line to be passed to a Python script via the CC environment variable. + list(JOIN CMAKE_C_COMPILER_LAUNCHER " " c_compiler_command) + string(STRIP "${c_compiler_command} ${CMAKE_C_COMPILER}" c_compiler_command) + string(STRIP "${c_compiler_command} ${CMAKE_C_COMPILER_ARG1}" c_compiler_command) add_custom_target(test-security-check COMMAND ${CMAKE_COMMAND} -E env CC=${c_compiler_command} CFLAGS=${CMAKE_C_FLAGS} LDFLAGS=${CMAKE_EXE_LINKER_FLAGS} ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/devtools/test-security-check.py TestSecurityChecks.test_${exe_format} COMMAND ${CMAKE_COMMAND} -E env CC=${c_compiler_command} CFLAGS=${CMAKE_C_FLAGS} LDFLAGS=${CMAKE_EXE_LINKER_FLAGS} ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_${exe_format} @@ -111,7 +115,20 @@ function(add_macos_deploy_target) ) string(REPLACE " " "-" osx_volname ${PACKAGE_NAME}) - if(CMAKE_CROSSCOMPILING) + if(CMAKE_HOST_APPLE) + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/${osx_volname}.zip + COMMAND ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR} -zip + DEPENDS ${CMAKE_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt + VERBATIM + ) + add_custom_target(deploydir + DEPENDS ${CMAKE_BINARY_DIR}/${osx_volname}.zip + ) + add_custom_target(deploy + DEPENDS ${CMAKE_BINARY_DIR}/${osx_volname}.zip + ) + else() add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/dist/${macos_app}/Contents/MacOS/Bitcoin-Qt COMMAND OTOOL=${OTOOL} ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR} @@ -133,19 +150,6 @@ function(add_macos_deploy_target) DEPENDS ${CMAKE_BINARY_DIR}/dist/${osx_volname}.zip ) add_dependencies(deploy deploydir) - else() - add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/${osx_volname}.zip - COMMAND ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR} -zip - DEPENDS ${CMAKE_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt - VERBATIM - ) - add_custom_target(deploydir - DEPENDS ${CMAKE_BINARY_DIR}/${osx_volname}.zip - ) - add_custom_target(deploy - DEPENDS ${CMAKE_BINARY_DIR}/${osx_volname}.zip - ) endif() endif() endfunction() diff --git a/depends/Makefile b/depends/Makefile index fac703966a03f..a51602780c7ab 100644 --- a/depends/Makefile +++ b/depends/Makefile @@ -258,9 +258,17 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_ $< > $@ touch $@ +ifeq ($(host),$(build)) + crosscompiling=FALSE +else + crosscompiling=TRUE +endif + $(host_prefix)/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_$(final_build_id) @mkdir -p $(@D) - sed -e 's|@host_system@|$($(host_os)_cmake_system)|' \ + sed -e 's|@depends_crosscompiling@|$(crosscompiling)|' \ + -e 's|@host_system_name@|$($(host_os)_cmake_system_name)|' \ + -e 's|@host_system_version@|$($(host_os)_cmake_system_version)|' \ -e 's|@host_arch@|$(host_arch)|' \ -e 's|@CC@|$(host_CC)|' \ -e 's|@CXX@|$(host_CXX)|' \ diff --git a/depends/funcs.mk b/depends/funcs.mk index 5f3ebb6dca0b3..7a07729b9cd69 100644 --- a/depends/funcs.mk +++ b/depends/funcs.mk @@ -187,7 +187,7 @@ ifeq ($($(1)_type),build) $(1)_cmake += -DCMAKE_INSTALL_RPATH:PATH="$$($($(1)_type)_prefix)/lib" else ifneq ($(host),$(build)) -$(1)_cmake += -DCMAKE_SYSTEM_NAME=$($(host_os)_cmake_system) +$(1)_cmake += -DCMAKE_SYSTEM_NAME=$($(host_os)_cmake_system_name) $(1)_cmake += -DCMAKE_C_COMPILER_TARGET=$(host) $(1)_cmake += -DCMAKE_CXX_COMPILER_TARGET=$(host) endif diff --git a/depends/hosts/android.mk b/depends/hosts/android.mk index a1c8c56dbafa1..48ab3260c5d3e 100644 --- a/depends/hosts/android.mk +++ b/depends/hosts/android.mk @@ -12,4 +12,4 @@ android_CXXFLAGS=-std=$(CXX_STANDARD) android_AR=$(ANDROID_TOOLCHAIN_BIN)/llvm-ar android_RANLIB=$(ANDROID_TOOLCHAIN_BIN)/llvm-ranlib -android_cmake_system=Android +android_cmake_system_name=Android diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index 639259ace349d..27653e3eba410 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -108,4 +108,7 @@ darwin_release_CXXFLAGS=$(darwin_release_CFLAGS) darwin_debug_CFLAGS=-O1 -g darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS) -darwin_cmake_system=Darwin +darwin_cmake_system_name=Darwin +# Darwin version, which corresponds to OSX_MIN_VERSION. +# See https://en.wikipedia.org/wiki/Darwin_(operating_system) +darwin_cmake_system_version=20.1 diff --git a/depends/hosts/freebsd.mk b/depends/hosts/freebsd.mk index 055097b03ddc8..8cef32e231cff 100644 --- a/depends/hosts/freebsd.mk +++ b/depends/hosts/freebsd.mk @@ -28,4 +28,4 @@ x86_64_freebsd_CC=$(default_host_CC) -m64 x86_64_freebsd_CXX=$(default_host_CXX) -m64 endif -freebsd_cmake_system=FreeBSD +freebsd_cmake_system_name=FreeBSD diff --git a/depends/hosts/linux.mk b/depends/hosts/linux.mk index f5ce2bb0b8557..e2f34265d153e 100644 --- a/depends/hosts/linux.mk +++ b/depends/hosts/linux.mk @@ -39,4 +39,7 @@ i686_linux_CXX=$(default_host_CXX) -m32 x86_64_linux_CC=$(default_host_CC) -m64 x86_64_linux_CXX=$(default_host_CXX) -m64 endif -linux_cmake_system=Linux + +linux_cmake_system_name=Linux +# Refer to doc/dependencies.md for the minimum required kernel. +linux_cmake_system_version=3.17.0 diff --git a/depends/hosts/mingw32.mk b/depends/hosts/mingw32.mk index 4c657358f6a57..c09f7b1e3a8db 100644 --- a/depends/hosts/mingw32.mk +++ b/depends/hosts/mingw32.mk @@ -19,4 +19,6 @@ mingw32_debug_CXXFLAGS=$(mingw32_debug_CFLAGS) mingw32_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -mingw32_cmake_system=Windows +mingw32_cmake_system_name=Windows +# Windows 7 (NT 6.1). +mingw32_cmake_system_version=6.1 diff --git a/depends/hosts/netbsd.mk b/depends/hosts/netbsd.mk index f33b2d2889571..16dff92d428a3 100644 --- a/depends/hosts/netbsd.mk +++ b/depends/hosts/netbsd.mk @@ -36,4 +36,4 @@ x86_64_netbsd_CC=$(default_host_CC) -m64 x86_64_netbsd_CXX=$(default_host_CXX) -m64 endif -netbsd_cmake_system=NetBSD +netbsd_cmake_system_name=NetBSD diff --git a/depends/hosts/openbsd.mk b/depends/hosts/openbsd.mk index bdd36dc9b35de..63f6d73d55598 100644 --- a/depends/hosts/openbsd.mk +++ b/depends/hosts/openbsd.mk @@ -28,4 +28,4 @@ x86_64_openbsd_CC=$(default_host_CC) -m64 x86_64_openbsd_CXX=$(default_host_CXX) -m64 endif -openbsd_cmake_system=OpenBSD +openbsd_cmake_system_name=OpenBSD diff --git a/depends/toolchain.cmake.in b/depends/toolchain.cmake.in index c10c08451c8d0..3efe32fbea55a 100644 --- a/depends/toolchain.cmake.in +++ b/depends/toolchain.cmake.in @@ -4,8 +4,16 @@ # This file is expected to be highly volatile and may still change substantially. -set(CMAKE_SYSTEM_NAME @host_system@) -set(CMAKE_SYSTEM_PROCESSOR @host_arch@) +# If CMAKE_SYSTEM_NAME is set within a toolchain file, CMake will also +# set CMAKE_CROSSCOMPILING to TRUE, even if CMAKE_SYSTEM_NAME matches +# CMAKE_HOST_SYSTEM_NAME. To avoid potential misconfiguration of CMake, +# it is best not to touch CMAKE_SYSTEM_NAME unless cross-compiling is +# intended. +if(@depends_crosscompiling@) + set(CMAKE_SYSTEM_NAME @host_system_name@) + set(CMAKE_SYSTEM_VERSION @host_system_version@) + set(CMAKE_SYSTEM_PROCESSOR @host_arch@) +endif() function(split_compiler_launcher env_compiler launcher compiler) set(${launcher})