minecraft-pi-reborn/cmake/base-toolchain.cmake

44 lines
1.8 KiB
CMake
Raw Normal View History

2021-10-29 02:57:47 +00:00
# Get Host Architecture
find_program(UNAME uname /bin /usr/bin /usr/local/bin REQUIRED)
execute_process(COMMAND "${UNAME}" "-m" OUTPUT_VARIABLE HOST_ARCHITECTURE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
2021-09-14 22:10:32 +00:00
# Pick GCC Version
macro(pick_gcc_version gcc_root gcc_version)
2021-09-14 23:29:48 +00:00
file(GLOB children RELATIVE "${gcc_root}" "${gcc_root}/*")
set("${gcc_version}" "")
foreach(child IN LISTS children)
if(IS_DIRECTORY "${gcc_root}/${child}" AND ("${${gcc_version}}" STREQUAL "" OR "${child}" GREATER_EQUAL "${${gcc_version}}"))
set("${gcc_version}" "${child}")
2021-09-14 22:10:32 +00:00
endif()
2021-09-14 23:29:48 +00:00
endforeach()
if("${${gcc_version}}" STREQUAL "")
message(FATAL_ERROR "Unable To Pick GCC Version")
2021-09-14 22:10:32 +00:00
endif()
endmacro()
# Setup Toolchain
macro(setup_toolchain target)
# Use ARM Cross-Compiler
set(CMAKE_C_COMPILER "clang")
set(CMAKE_C_COMPILER_TARGET "${target}")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_COMPILER_TARGET "${target}")
set(CMAKE_FIND_ROOT_PATH "/usr/${target}" "/usr/lib/${target}")
# Include Directories
2021-09-14 23:02:50 +00:00
pick_gcc_version("/usr/lib/gcc-cross/${target}" GCC_VERSION)
2021-09-21 02:47:33 +00:00
string(CONCAT NEW_FLAGS
"-nostdinc -nostdinc++ -Wno-unused-command-line-argument "
"-isystem /usr/${target}/include/c++/${GCC_VERSION} "
"-isystem /usr/${target}/include/c++/${GCC_VERSION}/${target} "
"-isystem /usr/${target}/include/c++/${GCC_VERSION}/backward "
"-isystem /usr/lib/gcc-cross/${target}/${GCC_VERSION}/include "
"-isystem /usr/lib/gcc-cross/${target}/${GCC_VERSION}/include-fixed "
"-isystem /usr/${target}/include "
"-isystem /usr/include"
2021-09-21 02:47:33 +00:00
)
2021-09-14 22:10:32 +00:00
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ${NEW_FLAGS}")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ${NEW_FLAGS}")
# Extra
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endmacro()