2018-11-08 01:51:56 +00:00
|
|
|
set(CROSS_ROOTFS $ENV{ROOTFS_DIR})
|
|
|
|
|
|
|
|
set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH})
|
2020-04-02 12:54:52 +00:00
|
|
|
if(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version)
|
|
|
|
set(CMAKE_SYSTEM_NAME FreeBSD)
|
2020-06-11 17:47:07 +00:00
|
|
|
elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc)
|
|
|
|
set(CMAKE_SYSTEM_NAME SunOS)
|
|
|
|
set(ILLUMOS 1)
|
2020-04-02 12:54:52 +00:00
|
|
|
else()
|
|
|
|
set(CMAKE_SYSTEM_NAME Linux)
|
|
|
|
endif()
|
2018-11-08 01:51:56 +00:00
|
|
|
set(CMAKE_SYSTEM_VERSION 1)
|
|
|
|
|
|
|
|
if(TARGET_ARCH_NAME STREQUAL "armel")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR armv7l)
|
|
|
|
set(TOOLCHAIN "arm-linux-gnueabi")
|
|
|
|
if("$ENV{__DistroRid}" MATCHES "tizen.*")
|
|
|
|
set(TIZEN_TOOLCHAIN "armv7l-tizen-linux-gnueabi/6.2.1")
|
|
|
|
endif()
|
|
|
|
elseif(TARGET_ARCH_NAME STREQUAL "arm")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR armv7l)
|
|
|
|
if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf)
|
|
|
|
set(TOOLCHAIN "armv6-alpine-linux-musleabihf")
|
|
|
|
else()
|
|
|
|
set(TOOLCHAIN "arm-linux-gnueabihf")
|
|
|
|
endif()
|
|
|
|
elseif(TARGET_ARCH_NAME STREQUAL "arm64")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
|
|
|
if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl)
|
|
|
|
set(TOOLCHAIN "aarch64-alpine-linux-musl")
|
|
|
|
else()
|
|
|
|
set(TOOLCHAIN "aarch64-linux-gnu")
|
|
|
|
endif()
|
2020-07-08 13:11:11 +00:00
|
|
|
if("$ENV{__DistroRid}" MATCHES "tizen.*")
|
|
|
|
set(TIZEN_TOOLCHAIN "aarch64-tizen-linux-gnu/9.2.0")
|
|
|
|
endif()
|
2018-11-08 01:51:56 +00:00
|
|
|
elseif(TARGET_ARCH_NAME STREQUAL "x86")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR i686)
|
|
|
|
set(TOOLCHAIN "i686-linux-gnu")
|
2020-04-02 12:54:52 +00:00
|
|
|
elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
|
|
|
|
set(triple "x86_64-unknown-freebsd11")
|
2020-06-11 17:47:07 +00:00
|
|
|
elseif (ILLUMOS)
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
|
|
|
|
set(TOOLCHAIN "x86_64-illumos")
|
2018-11-08 01:51:56 +00:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64 and x86 are supported!")
|
|
|
|
endif()
|
|
|
|
|
2019-11-08 23:46:49 +00:00
|
|
|
if(DEFINED ENV{TOOLCHAIN})
|
|
|
|
set(TOOLCHAIN $ENV{TOOLCHAIN})
|
|
|
|
endif()
|
|
|
|
|
2018-11-08 01:51:56 +00:00
|
|
|
# Specify include paths
|
2020-07-08 13:11:11 +00:00
|
|
|
if(DEFINED TIZEN_TOOLCHAIN)
|
|
|
|
if(TARGET_ARCH_NAME STREQUAL "armel")
|
2018-11-08 01:51:56 +00:00
|
|
|
include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/)
|
|
|
|
include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/armv7l-tizen-linux-gnueabi)
|
|
|
|
endif()
|
2020-07-08 13:11:11 +00:00
|
|
|
if(TARGET_ARCH_NAME STREQUAL "arm64")
|
|
|
|
include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/)
|
|
|
|
include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/aarch64-tizen-linux-gnu)
|
|
|
|
endif()
|
2018-11-08 01:51:56 +00:00
|
|
|
endif()
|
|
|
|
|
2020-03-08 12:38:05 +00:00
|
|
|
if("$ENV{__DistroRid}" MATCHES "android.*")
|
|
|
|
if(TARGET_ARCH_NAME STREQUAL "arm")
|
|
|
|
set(ANDROID_ABI armeabi-v7a)
|
|
|
|
elseif(TARGET_ARCH_NAME STREQUAL "arm64")
|
|
|
|
set(ANDROID_ABI arm64-v8a)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# extract platform number required by the NDK's toolchain
|
|
|
|
string(REGEX REPLACE ".*\\.([0-9]+)-.*" "\\1" ANDROID_PLATFORM "$ENV{__DistroRid}")
|
|
|
|
|
|
|
|
set(ANDROID_TOOLCHAIN clang)
|
|
|
|
set(FEATURE_EVENT_TRACE 0) # disable event trace as there is no lttng-ust package in termux repository
|
|
|
|
set(CMAKE_SYSTEM_LIBRARY_PATH "${CROSS_ROOTFS}/usr/lib")
|
|
|
|
set(CMAKE_SYSTEM_INCLUDE_PATH "${CROSS_ROOTFS}/usr/include")
|
|
|
|
|
|
|
|
# include official NDK toolchain script
|
|
|
|
include(${CROSS_ROOTFS}/../build/cmake/android.toolchain.cmake)
|
2020-06-11 17:47:07 +00:00
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
2020-04-02 12:54:52 +00:00
|
|
|
# we cross-compile by instructing clang
|
|
|
|
set(CMAKE_C_COMPILER_TARGET ${triple})
|
|
|
|
set(CMAKE_CXX_COMPILER_TARGET ${triple})
|
|
|
|
set(CMAKE_ASM_COMPILER_TARGET ${triple})
|
|
|
|
set(CMAKE_SYSROOT "${CROSS_ROOTFS}")
|
2020-06-11 17:47:07 +00:00
|
|
|
elseif(ILLUMOS)
|
|
|
|
set(CMAKE_SYSROOT "${CROSS_ROOTFS}")
|
|
|
|
|
|
|
|
include_directories(SYSTEM ${CROSS_ROOTFS}/include)
|
|
|
|
|
|
|
|
set(TOOLSET_PREFIX ${TOOLCHAIN}-)
|
|
|
|
function(locate_toolchain_exec exec var)
|
|
|
|
string(TOUPPER ${exec} EXEC_UPPERCASE)
|
|
|
|
if(NOT "$ENV{CLR_${EXEC_UPPERCASE}}" STREQUAL "")
|
|
|
|
set(${var} "$ENV{CLR_${EXEC_UPPERCASE}}" PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(EXEC_LOCATION_${exec}
|
|
|
|
NAMES
|
|
|
|
"${TOOLSET_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}"
|
|
|
|
"${TOOLSET_PREFIX}${exec}")
|
|
|
|
|
|
|
|
if (EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND")
|
|
|
|
message(FATAL_ERROR "Unable to find toolchain executable. Name: ${exec}, Prefix: ${TOOLSET_PREFIX}.")
|
|
|
|
endif()
|
|
|
|
set(${var} ${EXEC_LOCATION_${exec}} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
set(CMAKE_SYSTEM_PREFIX_PATH "${CROSS_ROOTFS}")
|
|
|
|
|
|
|
|
locate_toolchain_exec(gcc CMAKE_C_COMPILER)
|
|
|
|
locate_toolchain_exec(g++ CMAKE_CXX_COMPILER)
|
|
|
|
|
|
|
|
set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lssp")
|
|
|
|
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lssp")
|
2020-03-08 12:38:05 +00:00
|
|
|
else()
|
|
|
|
set(CMAKE_SYSROOT "${CROSS_ROOTFS}")
|
|
|
|
|
|
|
|
set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/usr")
|
|
|
|
set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/usr")
|
|
|
|
set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/usr")
|
|
|
|
endif()
|
2018-11-08 01:51:56 +00:00
|
|
|
|
|
|
|
# Specify link flags
|
|
|
|
|
2020-07-29 16:57:31 +00:00
|
|
|
function(add_toolchain_linker_flag Flag)
|
|
|
|
set(Config "${ARGV1}")
|
|
|
|
set(CONFIG_SUFFIX "")
|
|
|
|
if (NOT Config STREQUAL "")
|
|
|
|
set(CONFIG_SUFFIX "_${Config}")
|
|
|
|
endif()
|
|
|
|
set("CMAKE_EXE_LINKER_FLAGS${CONFIG_SUFFIX}" "${CMAKE_EXE_LINKER_FLAGS${CONFIG_SUFFIX}} ${Flag}" PARENT_SCOPE)
|
|
|
|
set("CMAKE_SHARED_LINKER_FLAGS${CONFIG_SUFFIX}" "${CMAKE_SHARED_LINKER_FLAGS${CONFIG_SUFFIX}} ${Flag}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2018-11-08 01:51:56 +00:00
|
|
|
if(TARGET_ARCH_NAME STREQUAL "armel")
|
|
|
|
if(DEFINED TIZEN_TOOLCHAIN) # For Tizen only
|
2020-07-29 16:57:31 +00:00
|
|
|
add_toolchain_linker_flag("-B${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}")
|
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib")
|
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib")
|
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}")
|
2018-11-08 01:51:56 +00:00
|
|
|
endif()
|
2020-07-08 13:11:11 +00:00
|
|
|
elseif(TARGET_ARCH_NAME STREQUAL "arm64")
|
|
|
|
if(DEFINED TIZEN_TOOLCHAIN) # For Tizen only
|
2020-07-29 16:57:31 +00:00
|
|
|
add_toolchain_linker_flag("-B${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}")
|
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib64")
|
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib64")
|
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}")
|
|
|
|
|
|
|
|
add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/lib64")
|
|
|
|
add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/usr/lib64")
|
|
|
|
add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}")
|
2020-07-08 13:11:11 +00:00
|
|
|
endif()
|
2018-11-08 01:51:56 +00:00
|
|
|
elseif(TARGET_ARCH_NAME STREQUAL "x86")
|
2020-07-29 16:57:31 +00:00
|
|
|
add_toolchain_linker_flag(-m32)
|
2020-06-11 17:47:07 +00:00
|
|
|
elseif(ILLUMOS)
|
2020-07-29 16:57:31 +00:00
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib/amd64")
|
|
|
|
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/amd64/lib")
|
2018-11-08 01:51:56 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Specify compile options
|
|
|
|
|
2020-06-11 17:47:07 +00:00
|
|
|
if((TARGET_ARCH_NAME MATCHES "^(arm|armel|arm64)$" AND NOT "$ENV{__DistroRid}" MATCHES "android.*") OR ILLUMOS)
|
2018-11-08 01:51:56 +00:00
|
|
|
set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN})
|
|
|
|
set(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN})
|
|
|
|
set(CMAKE_ASM_COMPILER_TARGET ${TOOLCHAIN})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(TARGET_ARCH_NAME MATCHES "^(arm|armel)$")
|
|
|
|
add_compile_options(-mthumb)
|
2020-02-11 13:49:59 +00:00
|
|
|
if (NOT DEFINED CLR_ARM_FPU_TYPE)
|
|
|
|
set (CLR_ARM_FPU_TYPE vfpv3)
|
|
|
|
endif (NOT DEFINED CLR_ARM_FPU_TYPE)
|
|
|
|
|
|
|
|
add_compile_options (-mfpu=${CLR_ARM_FPU_TYPE})
|
|
|
|
if (NOT DEFINED CLR_ARM_FPU_CAPABILITY)
|
|
|
|
set (CLR_ARM_FPU_CAPABILITY 0x7)
|
|
|
|
endif (NOT DEFINED CLR_ARM_FPU_CAPABILITY)
|
|
|
|
|
|
|
|
add_definitions (-DCLR_ARM_FPU_CAPABILITY=${CLR_ARM_FPU_CAPABILITY})
|
|
|
|
|
2018-11-08 01:51:56 +00:00
|
|
|
if(TARGET_ARCH_NAME STREQUAL "armel")
|
|
|
|
add_compile_options(-mfloat-abi=softfp)
|
|
|
|
endif()
|
|
|
|
elseif(TARGET_ARCH_NAME STREQUAL "x86")
|
|
|
|
add_compile_options(-m32)
|
|
|
|
add_compile_options(-Wno-error=unused-command-line-argument)
|
|
|
|
endif()
|
|
|
|
|
2020-07-08 13:11:11 +00:00
|
|
|
if(DEFINED TIZEN_TOOLCHAIN)
|
|
|
|
if(TARGET_ARCH_NAME MATCHES "^(armel|arm64)$")
|
|
|
|
add_compile_options(-Wno-deprecated-declarations) # compile-time option
|
|
|
|
add_compile_options(-D__extern_always_inline=inline) # compile-time option
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-11-08 23:46:49 +00:00
|
|
|
# Set LLDB include and library paths for builds that need lldb.
|
2018-11-08 01:51:56 +00:00
|
|
|
if(TARGET_ARCH_NAME MATCHES "^(arm|armel|x86)$")
|
|
|
|
if(TARGET_ARCH_NAME STREQUAL "x86")
|
|
|
|
set(LLVM_CROSS_DIR "$ENV{LLVM_CROSS_HOME}")
|
|
|
|
else() # arm/armel case
|
|
|
|
set(LLVM_CROSS_DIR "$ENV{LLVM_ARM_HOME}")
|
|
|
|
endif()
|
|
|
|
if(LLVM_CROSS_DIR)
|
|
|
|
set(WITH_LLDB_LIBS "${LLVM_CROSS_DIR}/lib/" CACHE STRING "")
|
|
|
|
set(WITH_LLDB_INCLUDES "${LLVM_CROSS_DIR}/include" CACHE STRING "")
|
|
|
|
set(LLDB_H "${WITH_LLDB_INCLUDES}" CACHE STRING "")
|
|
|
|
set(LLDB "${LLVM_CROSS_DIR}/lib/liblldb.so" CACHE STRING "")
|
|
|
|
else()
|
|
|
|
if(TARGET_ARCH_NAME STREQUAL "x86")
|
|
|
|
set(WITH_LLDB_LIBS "${CROSS_ROOTFS}/usr/lib/i386-linux-gnu" CACHE STRING "")
|
|
|
|
set(CHECK_LLVM_DIR "${CROSS_ROOTFS}/usr/lib/llvm-3.8/include")
|
|
|
|
if(EXISTS "${CHECK_LLVM_DIR}" AND IS_DIRECTORY "${CHECK_LLVM_DIR}")
|
|
|
|
set(WITH_LLDB_INCLUDES "${CHECK_LLVM_DIR}")
|
|
|
|
else()
|
|
|
|
set(WITH_LLDB_INCLUDES "${CROSS_ROOTFS}/usr/lib/llvm-3.6/include")
|
|
|
|
endif()
|
|
|
|
else() # arm/armel case
|
|
|
|
set(WITH_LLDB_LIBS "${CROSS_ROOTFS}/usr/lib/${TOOLCHAIN}" CACHE STRING "")
|
|
|
|
set(WITH_LLDB_INCLUDES "${CROSS_ROOTFS}/usr/lib/llvm-3.6/include" CACHE STRING "")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|