1#
2# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6
7cmake_minimum_required(VERSION 3.7.2)
8# Include our common helpers
9list(
10    APPEND
11        CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/helpers/ ${CMAKE_SOURCE_DIR}/projects/musllibc
12)
13
14include(check_arch_compiler)
15
16enable_language(C)
17enable_language(CXX)
18enable_language(ASM)
19
20# Hide cmake variables that will just confuse the user
21mark_as_advanced(
22    FORCE
23    CMAKE_INSTALL_PREFIX
24    CROSS_COMPILER_PREFIX
25    EXECUTABLE_OUTPUT_PATH
26    CMAKE_BACKWARDS_COMPATIBILITY
27    LIBRARY_OUTPUT_PATH
28    CMAKE_ASM_COMPILER
29    CMAKE_C_COMPILER
30)
31
32find_file(KERNEL_PATH kernel PATHS ${CMAKE_SOURCE_DIR} NO_CMAKE_FIND_ROOT_PATH)
33mark_as_advanced(FORCE KERNEL_PATH)
34if("${KERNEL_PATH}" STREQUAL "KERNEL_PATH-NOTFOUND")
35    message(FATAL_ERROR "Failed to find kernel. Consider cmake -DKERNEL_PATH=/path/to/kernel")
36endif()
37
38# Give an explicit build directory as there is no guarantee this is actually
39# subdirectory from the root source hierarchy
40add_subdirectory("${KERNEL_PATH}" kernel)
41# Include helpers from the kernel
42include(${KERNEL_HELPERS_PATH})
43
44include("${CMAKE_CURRENT_LIST_DIR}/common.cmake")
45
46# Due to some symlink madness in some project manifests we first get the realpath
47# for the current list directory and use that to find the elfloader
48# Both of these might not be subdirectories from our source root, so also
49# give them both explicit build directories
50get_filename_component(real_list "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
51# Include the elfloader before setting up user mode flags, as the elfloader does
52# not run as a user under the kernel
53add_subdirectory("${real_list}/../elfloader-tool" elfloader-tool)
54
55find_package(musllibc REQUIRED)
56# Make build options a visible choice, default it to Debug
57set(
58    CMAKE_BUILD_TYPE "Debug"
59    CACHE STRING "Set the user mode build type (kernel build ignores this)"
60)
61set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel")
62mark_as_advanced(CLEAR CMAKE_BUILD_TYPE)
63
64# Declare build flags for using musllibc in targets
65musllibc_set_environment_flags()
66
67# Now all platform compilation flags have been set, we can check the compiler against flags
68check_arch_compiler()
69
70add_subdirectory("${KERNEL_PATH}/libsel4" libsel4)
71