1#
2# Copyright 2019, Data61
3# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4# ABN 41 687 119 230.
5#
6# This software may be distributed and modified according to the terms of
7# the BSD 2-Clause license. Note that NO WARRANTY is provided.
8# See "LICENSE_BSD2.txt" for details.
9#
10# @TAG(DATA61_BSD)
11#
12
13set(CAMKES_TOOL_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE STRING "")
14mark_as_advanced(CAMKES_TOOL_DIR)
15
16option(CAmkESNoFPUByDefault "Set compilation flags to not use FPU. This is
17    currently only supported on x86 but other architectures may be added." OFF)
18mark_as_advanced(CAmkESNoFPUByDefault)
19
20macro(camkes_tool_import_libraries)
21    add_subdirectory(${CAMKES_TOOL_DIR} camkes-tool)
22endmacro()
23
24macro(camkes_tool_setup_camkes_build_environment)
25    find_package(seL4 REQUIRED)
26    find_package(elfloader-tool REQUIRED)
27    find_package(musllibc REQUIRED)
28    find_package(util_libs REQUIRED)
29    find_package(seL4_libs REQUIRED)
30    find_package(projects_libs REQUIRED)
31    find_package(capdl REQUIRED)
32    # Other project settings needed for static allocation.
33    # This is done early on so that it works for projects loaded before
34    # options processing in camkes-tool (notably, elfloader-tool).
35    if(CAmkESCapDLStaticAlloc)
36        # Need to compile the capDL loader for static alloc
37        SetCapDLLoaderStaticAlloc()
38        # Need to place the capDL loader ELF at the end of memory
39        SetElfloaderRootserversLast()
40    endif()
41
42    sel4_import_kernel()
43    elfloader_import_project()
44
45    include(${CAMKES_TOOL_DIR}/camkes.cmake)
46    # This sets up environment build flags and imports musllibc and runtime libraries.
47    config_set(LibSel4MuslcSysConstructorPriority LIB_SEL4_MUSLC_SYS_CONSTRUCTOR_PRIORITY 201)
48    musllibc_setup_build_environment_with_sel4runtime()
49    if(CAmkESNoFPUByDefault)
50        if(KernelArchX86)
51            add_compile_options(-mno-sse -mgeneral-regs-only -mno-80387 -mno-fp-ret-in-387)
52        endif()
53    endif()
54    sel4_import_libsel4()
55    util_libs_import_libraries()
56    sel4_libs_import_libraries()
57    projects_libs_import_libraries()
58    camkes_tool_import_libraries()
59    capdl_import_project()
60
61endmacro()
62
63include(FindPackageHandleStandardArgs)
64FIND_PACKAGE_HANDLE_STANDARD_ARGS(camkes-tool DEFAULT_MSG CAMKES_TOOL_DIR)
65