Synchronous toolchain.cmake files with CoreFX #9409
| set(TOOLCHAIN "arm-linux-gnueabihf") | ||
| -set(TOOLCHAIN_PREFIX ${TOOLCHAIN}-) | ||
| -#set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) |
| @@ -103,7 +103,7 @@ else (WIN32) | ||
| # Ensure that objcopy is present | ||
| if (DEFINED ENV{CROSSCOMPILE} AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD) | ||
| if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) | ||
| - find_program(OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) | ||
| + find_program(OBJCOPY ${TOOLCHAIN}-objcopy) |
To cross-compile for Android, we need to use objcopy from the Android toolchain, not the host. On Android, that would be ${CROSS_NDK_TOOLCHAIN}/bin/aarch64-linux-android-objcopy; previously we set ${TOOLCHAIN_PREFIX} to ${CROSS_NDK_TOOLCHAIN}/bin/aarch64-linux-android- so it worked.
If you set it to ${TOOLCHAIN} this will evaluate to aarch64-linux-android-objcopy and from what I get, CMake will look for this file in the bin folders on the host, which doesn't work.
Another option would be to set ${TOOLCHAIN_PREFIX} to ${CROSS_NDK_TOOLCHAIN}/bin/ on Android, leave it empty for Linux, and change this line to:
find_program(OBJCOPY ${TOOLCHAIN_PREFIX}${TOOLCHAIN}-objcopy)
What about replace ${TOOLCHAIN_PREFIX} to ${TOOLCHAIN} and redefine other macro for the previous ${TOOLCHAIN} variable? I can revise the find objcopy logic as you said. But I think this issue can be resolved by modifiying cross/android/arm64/toolchain.cmake file. What do you think?
| add_compile_options(-target armv7-linux-gnueabihf) | ||
| add_compile_options(-mthumb) | ||
| add_compile_options(-mfpu=vfpv3) | ||
| add_compile_options(--sysroot=${CROSS_ROOTFS}) | ||
| set(CROSS_LINK_FLAGS "${CROSS_LINK_FLAGS} -target ${TOOLCHAIN}") | ||
| -set(CROSS_LINK_FLAGS "${CROSS_LINK_FLAGS} -B ${CROSS_ROOTFS}/usr/lib/gcc/${TOOLCHAIN}") | ||
| +set(CROSS_LINK_FLAGS "${CROSS_LINK_FLAGS} -B${CROSS_ROOTFS}/usr/lib/gcc/${TOOLCHAIN}") |
We do the same on Android (to keep the files consistent), hence ${TOOLCHAIN} must be an absolute path, so we can't prefix ${TOOLCHAIN} like we could do with ${TOOLCHAIN_PREFIX}
As I suggest, you can define other macro for the previous ${TOOLCHAIN} and use it here.
|
@jyoungyun I left some comments; the gist of it is that for Android, we need to set a full path for Another option may be to agree that I think you could then leave /cc @janvorli |
|
@qmfrederik I think we can support android build without revising CMakeLists.txt. Here is my example.
I prefer not to create unnecessary define. So, if possible, I hope it will be implemented in existing structure. Let me know if something is wrong with me. If we need |
|
@jyoungyun Yup, we've done something similar in #9174 to support cross compiling for Android. When we did that, we hit a problem with Looking at the documentation for find_program, it looks like there are some alternatives we can try:
I can check the CMAKE_PREFIX_PATH option later today my time zone, and I'll get back to you. Would that be OK? |
|
@jyoungyun Yup, setting I've updated #9174 LGTM! |
|
@gkhanna79 @janvorli PTAL |
Remove unnecessary
TOOLCHAIN_PREFIXdefine and synchronous toolchain.cmake files with CoreFXRelated issue: dotnet/corefx#15882