Skip to content

Commit

Permalink
[FIXUP] cmake: Do not trigger cross-compiling unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Apr 24, 2024
1 parent b7dc7bf commit 6546686
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
30 changes: 14 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,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)
Expand Down
34 changes: 15 additions & 19 deletions cmake/module/Maintenance.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ 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()
set(c_compiler_command "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
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}
Expand Down Expand Up @@ -111,7 +107,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 INSTALL_NAME_TOOL=${CMAKE_INSTALL_NAME_TOOL} OTOOL=${OTOOL} STRIP=${CMAKE_STRIP} ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR}
Expand All @@ -133,19 +142,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()
9 changes: 8 additions & 1 deletion depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,16 @@ $(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@|$($(host_os)_cmake_system)|' \
-e 's|@host_arch@|$(host_arch)|' \
-e 's|@CC@|$(host_CC)|' \
-e 's|@CXX@|$(host_CXX)|' \
Expand Down
6 changes: 4 additions & 2 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

# 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(@depends_crosscompiling@)
set(CMAKE_SYSTEM_NAME @host_system@)
set(CMAKE_SYSTEM_PROCESSOR @host_arch@)
endif()

function(split_compiler_launcher env_compiler launcher compiler)
set(${launcher})
Expand Down

0 comments on commit 6546686

Please sign in to comment.