EtchDroid/cmake_utils/ndk_exec.cmake

120 lines
4.4 KiB
CMake

cmake_minimum_required(VERSION 3.4)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake")
endif()
include(${CMAKE_TOOLCHAIN_FILE})
# Set up stuff for autotools build to succeed
# Some of this code has been adapted from https://github.com/termux/termux-packages/blob/master/build-package.sh
if (ANDROID_ABI STREQUAL "arm64-v8a")
set(NDK_HOST "aarch64-linux-android")
elseif (ANDROID_ABI STREQUAL "armeabi-v7a")
set(NDK_HOST "arm-linux-androideabi")
set(CFLAGS "-march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb")
elseif (ANDROID_ABI STREQUAL "x86")
set(NDK_HOST "x86-linux-android")
set(CFLAGS "-march=i686 -msse3 -mstackrealign -mfpmath=sse")
elseif (ANDROID_ABI STREQUAL "x86_64")
set(NDK_HOST "x86_64-linux-android")
endif ()
if(NOT DEFINED ANDROID_HOST_TAG OR (DEFINED ANDROID_HOST_TAG AND ANDROID_HOST_TAG STREQUAL ""))
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(ANDROID_HOST_TAG linux-x86_64)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(ANDROID_HOST_TAG darwin-x86_64)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(ANDROID_HOST_TAG windows-x86_64)
endif()
endif()
if(NOT ${ANDROID_TOOLCHAIN_ROOT} MATCHES "${ANDROID_HOST_TAG}/?$")
set(ANDROID_TOOLCHAIN_ROOT "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_HOST_TAG}")
endif()
set(ENV{PATH} "${ANDROID_TOOLCHAIN_ROOT}/bin:$ENV{PATH}")
set(ENV{CFLAGS} "${CMAKE_C_FLAGS} -fPIE")
set(ENV{LDFLAGS} "${ANDROID_LINKER_FLAGS} -pie")
set(ENV{CXXFLAGS} "${CMAKE_CXX_FLAGS} -fPIE")
set(ENV{AS} "${NDK_HOST}-as")
set(ENV{CC} "${NDK_HOST}-gcc")
set(ENV{CXX} "${NDK_HOST}-g++")
set(ENV{AR} "${NDK_HOST}-ar")
set(ENV{CPP} "${NDK_HOST}-g++")
#set(ENV{CC_FOR_BUILD} "c")
set(ENV{LD} "${NDK_HOST}-ld")
set(ENV{OBJDUMP} "${NDK_HOST}-objdump")
set(ENV{RANLIB} "${NDK_HOST}-ranlib")
set(ENV{READELF} "${NDK_HOST}-readelf")
set(ENV{STRIP} "${NDK_HOST}-strip")
set(ENV{ac_cv_func_getpwent} "no")
set(ENV{ac_cv_func_getpwnam} "no")
set(ENV{ac_cv_func_getpwuid} "no")
set(ENV{ac_cv_func_sigsetmask} "no")
set(ENV{ac_cv_func_calloc_0_nonnull} "yes")
set(ENV{ac_cv_func_chown_works} "yes")
set(ENV{ac_cv_func_getgroups_works} "yes")
set(ENV{ac_cv_func_malloc_0_nonnull} "yes")
set(ENV{ac_cv_func_realloc_0_nonnull} "yes")
set(ENV{am_cv_func_working_getline} "yes")
set(ENV{gl_cv_func_dup2_works} "yes")
set(ENV{gl_cv_func_fcntl_f_dupfd_cloexec} "yes")
set(ENV{gl_cv_func_fcntl_f_dupfd_works} "yes")
set(ENV{gl_cv_func_fnmatch_posix} "yes")
set(ENV{gl_cv_func_getcwd_abort_bug} "no")
set(ENV{gl_cv_func_getcwd_null} "yes")
set(ENV{gl_cv_func_getcwd_path_max} "yes")
set(ENV{gl_cv_func_getcwd_posix_signature} "yes")
set(ENV{gl_cv_func_gettimeofday_clobber} "no")
set(ENV{gl_cv_func_gettimeofday_posix_signature} "yes")
set(ENV{gl_cv_func_link_works} "yes")
set(ENV{gl_cv_func_lstat_dereferences_slashed_symlink} "yes")
set(ENV{gl_cv_func_malloc_0_nonnull} "yes")
set(ENV{gl_cv_func_memchr_works} "yes")
set(ENV{gl_cv_func_mkdir_trailing_dot_works} "yes")
set(ENV{gl_cv_func_mkdir_trailing_slash_works} "yes")
set(ENV{gl_cv_func_mkfifo_works} "yes")
set(ENV{gl_cv_func_mknod_works} "yes")
set(ENV{gl_cv_func_realpath_works} "yes")
set(ENV{gl_cv_func_select_detects_ebadf} "yes")
set(ENV{gl_cv_func_snprintf_posix} "yes")
set(ENV{gl_cv_func_snprintf_retval_c99} "yes")
set(ENV{gl_cv_func_snprintf_truncation_c99} "yes")
set(ENV{gl_cv_func_stat_dir_slash} "yes")
set(ENV{gl_cv_func_stat_file_slash} "yes")
set(ENV{gl_cv_func_strerror_0_works} "yes")
set(ENV{gl_cv_func_symlink_works} "yes")
set(ENV{gl_cv_func_tzset_clobber} "no")
set(ENV{gl_cv_func_unlink_honors_slashes} "yes")
set(ENV{gl_cv_func_unlink_honors_slashes} "yes")
set(ENV{gl_cv_func_vsnprintf_posix} "yes")
set(ENV{gl_cv_func_vsnprintf_zerosize_c99} "yes")
set(ENV{gl_cv_func_wcwidth_works} "yes")
set(ENV{gl_cv_func_working_getdelim} "yes")
set(ENV{gl_cv_func_working_mkstemp} "yes")
set(ENV{gl_cv_func_working_mktime} "yes")
set(ENV{gl_cv_func_working_strerror} "yes")
set(ENV{gl_cv_header_working_fcntl_h} "yes")
set(ENV{gl_cv_C_locale_sans_EILSEQ} "yes")
string(REPLACE <NDK_HOST> "${NDK_HOST}" COMMAND "${COMMAND}")
message("NDK EXEC: ${COMMAND}")
message("CWD: ${CWD}")
separate_arguments(CMD UNIX_COMMAND "${COMMAND}")
message("SPLIT CMD: ${CMD}")
if(CWD)
message("ndkexec has cwd")
execute_process(
COMMAND ${CMD}
WORKING_DIRECTORY ${CWD}
)
else()
message("ndkexec no cwd")
execute_process(
COMMAND ${CMD}
)
endif()