Initial commit

Change-Id: I26f6fdfd4962e2c724bf6b68893156f11d37d4b1
diff --git a/toolchains/aarch64/common_aarch64.cmake b/toolchains/aarch64/common_aarch64.cmake
new file mode 100644
index 0000000..99975d0
--- /dev/null
+++ b/toolchains/aarch64/common_aarch64.cmake
@@ -0,0 +1,42 @@
+#
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright LibTL Contributors.
+#
+
+include_guard()
+include(CheckCCompilerFlag)
+
+include(${CMAKE_CURRENT_LIST_DIR}/../common.cmake)
+
+set(CMAKE_SYSTEM_NAME "Generic")
+set(CMAKE_SYSTEM_PROCESSOR aarch64)
+
+add_compile_options(
+	-ffreestanding
+	-mbranch-protection=standard
+	-mgeneral-regs-only
+	-mstrict-align
+	-fpie)
+
+add_link_options(
+	"$<$<CONFIG:Debug>:-fno-omit-frame-pointer>"
+	"$<$<CONFIG:Relase>:-fomit-frame-pointer>")
+
+add_link_options(
+	-nostdlib
+	-Wl,-pie)
+
+# Detect applicable "march=" option supported by compiler
+function(detect_and_set_march)
+	set (march_list 9.2 9.1 9 8.8 8.7 8.6 8.5)
+
+	foreach(v ${march_list})
+		string(REPLACE "." "_" n ${v})
+		check_c_compiler_flag("-march=armv${v}-a" COMPILER_SUPPORTS_${n})
+		if(COMPILER_SUPPORTS_${n})
+			add_compile_options("-march=armv${v}-a")
+			return()
+		endif()
+	endforeach()
+	message(FATAL_ERROR "Suitable -march not detected. Please upgrade aarch64 compiler." )
+endfunction()
diff --git a/toolchains/aarch64/gnu.cmake b/toolchains/aarch64/gnu.cmake
new file mode 100644
index 0000000..a6e18f0
--- /dev/null
+++ b/toolchains/aarch64/gnu.cmake
@@ -0,0 +1,18 @@
+#
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright LibTL Contributors.
+#
+
+include_guard()
+
+include(${CMAKE_CURRENT_LIST_DIR}/common_aarch64.cmake)
+
+find_program(CMAKE_ASM_COMPILER
+    NAMES "$ENV{CROSS_COMPILE}gcc"
+    DOC "Path to an aarch64 compiler."
+    REQUIRED)
+
+find_program(CMAKE_C_COMPILER
+    NAMES "$ENV{CROSS_COMPILE}gcc"
+    DOC "Path to an aarch64 compiler."
+    REQUIRED)
diff --git a/toolchains/common.cmake b/toolchains/common.cmake
new file mode 100644
index 0000000..552a8c8
--- /dev/null
+++ b/toolchains/common.cmake
@@ -0,0 +1,27 @@
+#
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright LibTL Contributors.
+#
+
+include_guard()
+
+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)
+
+add_compile_options(
+	"-fno-common"
+	"-ffunction-sections"
+	"-fdata-sections"
+	"-Wall"
+	"-Werror"
+	"-gdwarf-4"
+	"$<$<CONFIG:Debug>:-Og>"
+	"$<$<CONFIG:Release>:-g>"
+	)
+
+add_link_options(
+	"-Wl,--gc-sections"
+	"-g"
+	)
diff --git a/toolchains/host/common_host.cmake b/toolchains/host/common_host.cmake
new file mode 100644
index 0000000..9e661d7
--- /dev/null
+++ b/toolchains/host/common_host.cmake
@@ -0,0 +1,16 @@
+#
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright LibTL Contributors.
+#
+
+include_guard()
+
+include(${CMAKE_CURRENT_LIST_DIR}/../common.cmake)
+
+foreach(language IN ITEMS ASM C CXX)
+    string(APPEND CMAKE_${language}_FLAGS_INIT "-fno-omit-frame-pointer -pg ")
+endforeach()
+
+# 'march=" option is not applicable for fake_host
+function(detect_and_set_march)
+endfunction()
diff --git a/toolchains/host/gnu.cmake b/toolchains/host/gnu.cmake
new file mode 100644
index 0000000..f470d1b
--- /dev/null
+++ b/toolchains/host/gnu.cmake
@@ -0,0 +1,17 @@
+#
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright LibTL Contributors.
+#
+
+include_guard()
+
+include(${CMAKE_CURRENT_LIST_DIR}/common_host.cmake)
+
+find_program(CMAKE_C_COMPILER
+    NAMES "gcc"
+    DOC "Path to gcc."
+    REQUIRED)
+
+set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
+
+string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--build-id=none ")
diff --git a/toolchains/host/llvm.cmake b/toolchains/host/llvm.cmake
new file mode 100644
index 0000000..d9da42a
--- /dev/null
+++ b/toolchains/host/llvm.cmake
@@ -0,0 +1,29 @@
+#
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright LibTL Contributors.
+#
+
+include_guard()
+
+include(${CMAKE_CURRENT_LIST_DIR}/common_host.cmake)
+
+find_program(CMAKE_C_COMPILER
+    NAMES "clang"
+    DOC "Path to clang."
+    REQUIRED)
+
+find_program(CMAKE_CXX_COMPILER
+    NAMES "clang++"
+    DOC "Path to clang++."
+    REQUIRED)
+
+set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
+
+foreach(language IN ITEMS ASM C CXX)
+    string(APPEND CMAKE_${language}_FLAGS_INIT "-Wno-unknown-warning-option ")
+    string(APPEND CMAKE_${language}_FLAGS_INIT "-Wno-unused-function ")
+    string(APPEND CMAKE_${language}_FLAGS_INIT "-fPIC ")
+endforeach()
+
+string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--build-id=none ")
+string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld ")