-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIXUP] cmake: Do not trigger cross-compiling unnecessarily #125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this has just taken on the depends macos ccache hack behaviour for everything, and I still don't understand why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not only about "ccache hack". Consider the following example:
The output There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Where are we doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't understand why we need to do anything other than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
bitcoin/depends/hosts/darwin.mk Lines 87 to 94 in 7973a67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It demonstrates that the value of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get some documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure. That's what I can suggest to consider:
# if CMAKE_${lang}_COMPILER is a list, use the first item as
# CMAKE_${lang}_COMPILER and the rest as CMAKE_${lang}_COMPILER_ARG1
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean a comment in our code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. A comment has been added. |
||||||||||||||||||
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() |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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@) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really dislike that we still have to have this logic (and the depends counterpart), and I still don't really understand why it's needed. Now that the depends hacks are being removed, shouldn't we just be able to set In any case, according to the docs, if we are setting
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right. But CMake internally still uses it, which might affect its behaviour (feature tests, compiler invocation string, testing framework etc). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW, we are not doing this on the master branch: Lines 193 to 197 in 7fcf4e9
From the CMake source code, it follows that it is used for Android and Darwin platforms. For example, on Darwin, it affects on which flags will be used by default ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This seems like a more correct thing to do, so that's fine, but apparently it will have no effect with lld. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW, in depends we do: cross_compiling=maybe
host_alias="@HOST@" Which I believe pretty much has the same effect for autotools that @hebasto is describing here for CMake. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we should at least be documenting why we are avoiding this behaviour (besides calling something that isn't cross-compiling, cross-compiling, which is just confusing). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but I don't understand this point. We are not trying to avoid something, rather following the CMake docs. When we want to enable cross-compiling, we set the When we don't want to enable cross-compiling, we skip touching the Anyway, I'll be happy to add a comment to this code. Do you mind suggesting a good wording for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is what we are avoiding. Otherwise CMake decides things are cross-compilation, even when they are not. Otherwise we'd be free to set this all the time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hebasto, for the wording, if @fanquake allows me here and agrees with it, perhaps something like:
If it's too long, I'd just get the first 2 lines and add the link to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
An explanatory comment has been added. |
||||||||||||
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}) | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that ccache and env can't be used simultaneously? Basically meaning that ccache can't be used for darwin builds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does not.
The current implementation works flawlessly for ccache + darwin. It appends ccache command to the
CMAKE_{C.CXX}_COMPILER_LAUNCHER
variables afterenv
.UPD. The resulted compiler invocation string looks like
env ... ccache ... clang ...