Skip to content

Commit 669b19d

Browse files
committed
First hack at adding C and linker flags to our CMake config, for Android-arm
1 parent 37390e5 commit 669b19d

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

runtime/CMakeLists.txt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,27 @@ set(COMPILE_ALL_D_FILES_AT_ONCE ON CACHE BOOL "Comp
4040
set(RT_CFLAGS "" CACHE STRING "Runtime extra C compiler flags, separated by ' '")
4141
set(LD_FLAGS "" CACHE STRING "Runtime extra C linker flags, separated by ' '")
4242
set(C_SYSTEM_LIBS AUTO CACHE STRING "C system libraries for linking shared libraries and test runners, separated by ';'")
43-
set(TARGET_SYSTEM AUTO CACHE STRING "Targeted platform for cross-compilation (e.g., 'Linux;UNIX', 'Darwin;APPLE;UNIX', 'Windows;MSVC')")
43+
set(TARGET_SYSTEM AUTO CACHE STRING "Target OS/toolchain for cross-compilation (e.g., 'Linux;UNIX', 'Darwin;APPLE;UNIX', 'Windows;MSVC')")
44+
set(TARGET_PLATFORM AUTO CACHE STRING "Target platform for cross-compilation, shortcut variable with format OS-arch (e.g., 'Linux-arm', 'Mac-x64', 'Windows-aarch64', 'Android-x86')")
4445

4546
set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
4647

48+
if(RT_CFLAGS STREQUAL "" AND "${TARGET_PLATFORM}" MATCHES "Android")
49+
set(RT_CFLAGS_UNCONFIGURED True)
50+
if("${TARGET_PLATFORM}" MATCHES "arm")
51+
set(RT_CFLAGS "-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security")
52+
endif()
53+
endif()
54+
55+
if(LD_FLAGS STREQUAL "" AND "${TARGET_PLATFORM}" MATCHES "Android")
56+
set(LD_FLAGS_UNCONFIGURED True)
57+
if("${TARGET_PLATFORM}" MATCHES "arm")
58+
set(LD_FLAGS "-Wl,-z,nocopyreloc -lgcc -target armv7-none-linux-androideabi -no-canonical-prefixes -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings -fPIE -pie")
59+
endif()
60+
endif()
61+
4762
# Auto-detect TARGET_SYSTEM
48-
if("${TARGET_SYSTEM}" STREQUAL "AUTO")
63+
if("${TARGET_PLATFORM}" STREQUAL "AUTO")
4964
set(TARGET_SYSTEM ${CMAKE_SYSTEM_NAME})
5065
# Additionally add MSVC, APPLE and/or UNIX
5166
if(MSVC)
@@ -57,6 +72,26 @@ if("${TARGET_SYSTEM}" STREQUAL "AUTO")
5772
if(UNIX)
5873
list(APPEND TARGET_SYSTEM "UNIX")
5974
endif()
75+
else()
76+
if("${TARGET_PLATFORM}" MATCHES "Windows")
77+
set(TARGET_SYSTEM "Windows;MSVC")
78+
if("${TARGET_PLATFORM}" MATCHES "x64")
79+
# stub example, fill in with the rest
80+
list(APPEND D_FLAGS "-mtriple=x86_64-pc-windows-msvc")
81+
endif()
82+
elseif("${TARGET_PLATFORM}" MATCHES "Android")
83+
set(TARGET_SYSTEM "Android;Linux;UNIX")
84+
set(ANDROID_API "21")
85+
if("${TARGET_PLATFORM}" MATCHES "arm")
86+
list(APPEND D_FLAGS "-mtriple=armv7-none-linux-android")
87+
if (RT_CFLAGS_UNCONFIGURED AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
88+
append("-gcc-toolchain $ENV{NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fno-integrated-as -isystem $ENV{NDK}/platforms/android-${ANDROID_API}/arch-arm/usr/include" RT_CFLAGS)
89+
endif()
90+
if (LD_FLAGS_UNCONFIGURED AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
91+
append("--sysroot=$ENV{NDK}/platforms/android-${ANDROID_API}/arch-arm -gcc-toolchain $ENV{NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fuse-ld=bfd" LD_FLAGS)
92+
endif()
93+
endif()
94+
endif()
6095
endif()
6196

6297
if("${TARGET_SYSTEM}" MATCHES "UNIX")

0 commit comments

Comments
 (0)