-
Notifications
You must be signed in to change notification settings - Fork 1.1k
When crosscompiling, build host tools externally. #5170
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
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 |
---|---|---|
|
@@ -338,6 +338,48 @@ set(SOURCE_FILES | |
WrapCalls.cpp | ||
) | ||
|
||
## | ||
# Build time tools | ||
## | ||
|
||
if (CMAKE_CROSSCOMPILING) | ||
# Note: using CMAKE_EXECUTABLE_SUFFIX breaks cross-OS builds involving Windows. | ||
include(ExternalProject) | ||
ExternalProject_Add(host-tools | ||
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. super-duper-nit: I find it hard to quickly read the keywords-vs-arg-values here; I wonder if it would be more obvious with indentation like:
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. The formatter in CLion is not very smart and it tramples such indentation 😞 I could add some blank lines to make it a bit more readable. 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. Didn't know there existed an autoformatter for CMake. Does it exist anywhere other than CLion? 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. Not that I'm aware of. There are two open-source CMake formatters I'm aware of. I've tried both. One, cmake-format does a bad job, the linter is even worse. The other, gersemi, is not very configurable, is in pre-alpha state and led to a huge diff. |
||
BUILD_BYPRODUCTS | ||
"<INSTALL_DIR>/bin/build_halide_h${CMAKE_EXECUTABLE_SUFFIX}" | ||
"<INSTALL_DIR>/bin/binary2cpp${CMAKE_EXECUTABLE_SUFFIX}" | ||
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/tools | ||
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/host-tools | ||
CMAKE_ARGS | ||
-D CMAKE_TOOLCHAIN_FILE=${Halide_HOST_TOOLCHAIN_FILE} | ||
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
-D CMAKE_INSTALL_PREFIX=<INSTALL_DIR> | ||
BUILD_ALWAYS YES) | ||
|
||
# We avoid a full super-build by manually creating imported targets here. | ||
# If we start adding lots of build-time tools, we should migrate to the | ||
# export() mechanism, which would also avoid the cross-OS bug. | ||
ExternalProject_Get_Property(host-tools INSTALL_DIR) | ||
|
||
add_executable(build_halide_h IMPORTED GLOBAL) | ||
set_target_properties(build_halide_h | ||
PROPERTIES | ||
IMPORTED_LOCATION "${INSTALL_DIR}/bin/build_halide_h${CMAKE_EXECUTABLE_SUFFIX}" | ||
CROSSCOMPILING_EMULATOR "") | ||
add_dependencies(build_halide_h host-tools) | ||
|
||
add_executable(binary2cpp IMPORTED GLOBAL) | ||
set_target_properties(binary2cpp | ||
PROPERTIES | ||
IMPORTED_LOCATION "${INSTALL_DIR}/bin/binary2cpp${CMAKE_EXECUTABLE_SUFFIX}" | ||
CROSSCOMPILING_EMULATOR "") | ||
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. What happens if we don't explicitly set 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'm not 100% sure how CMake will treat it given that it's an imported target, but for non-imported executable targets, it wants |
||
add_dependencies(binary2cpp host-tools) | ||
else () | ||
# Do the safe, reliable thing when not cross-compiling. | ||
add_subdirectory(tools) | ||
endif () | ||
|
||
## | ||
# Build and import the runtime. | ||
## | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(host-tools) | ||
|
||
# Require standard C++14 | ||
set(CMAKE_CXX_STANDARD 14) | ||
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. ...don't we actually only require C++11? 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. IIRC when we went through and looked at our list of supported compilers (GCC 5+, Clang 9+, MSVC 2017+), C++14 was the GCD among them. |
||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
add_executable(binary2cpp binary2cpp.cpp) | ||
add_executable(build_halide_h build_halide_h.cpp) | ||
add_executable(find_inverse find_inverse.cpp) | ||
|
||
# Don't install when included via add_subdirectory. | ||
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | ||
include(GNUInstallDirs) | ||
install(TARGETS build_halide_h binary2cpp find_inverse | ||
EXPORT host-tools | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
endif () |
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.
I'm a little confused by this comment -- it breaks the builds but we use it anyway?
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.
It doesn't break any existing scenarios, it just isn't a supported scenario without going full superbuild. I can make this clearer.