forked from CTSRD-CHERI/cheribsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
117 lines (105 loc) · 5.34 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
set(CMAKE_CROSSCOMPILING ON)
set(CMAKE_SYSTEM_NAME FreeBSD)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
cmake_minimum_required(VERSION 3.8)
project(CheriBSD LANGUAGES NONE)
set(TARGET "" CACHE STRING "Target machine.")
set(TARGET_ARCH "" CACHE STRING "Target machine arch.")
if (NOT TARGET)
message(FATAL_ERROR "TARGET must be set!")
endif()
if (NOT TARGET_ARCH)
message(FATAL_ERROR "TARGET_ARCH must be set!")
endif()
set(MACHINE_HEADERS "${CMAKE_SOURCE_DIR}/sys/${TARGET}/include")
if("${TARGET}" STREQUAL "mips")
if("${TARGET_ARCH}" STREQUAL "mips64")
add_compile_options(-mabi=n64)
set(CLANG_TRIPLE mips64-unknown-freebsd12)
else()
message(FATAL_ERROR "Unsupported MIPS TARGET_ARCH: ${TARGET}:${TARGET_ARCH}!")
endif()
else()
message(FATAL_ERROR "Unsupported TARGET: ${TARGET}:${TARGET_ARCH}!")
endif()
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/sys)
set(TMPSYSROOT ${CMAKE_BINARY_DIR}/sysroot/usr)
add_compile_options(--sysroot=${CMAKE_BINARY_DIR}/sysroot/)
# Create symlinks
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${MACHINE_HEADERS} ${TMPSYSROOT}/include/machine)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/sys/sys/errno.h ${TMPSYSROOT}/include/errno.h)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/sys/sys/fcntl.h ${TMPSYSROOT}/include/fcntl.h)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/sys/sys/_stdarg.h ${TMPSYSROOT}/include/stdarg.h)
# TODO: should only be for CHERI
file(MAKE_DIRECTORY ${TMPSYSROOT}/include/c++)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/contrib/subrepo-cheri-libc++/include ${TMPSYSROOT}/include/c++/v1)
file(MAKE_DIRECTORY ${TMPSYSROOT}/kern_opt)
file(WRITE ${CMAKE_BINARY_DIR}/kern_opt/opt_ddb.h "#define DDB 1\n")
file(WRITE ${CMAKE_BINARY_DIR}/kern_opt/opt_ktrace.h "#define KTRACE 1\n")
file(WRITE ${CMAKE_BINARY_DIR}/kern_opt/opt_global.h "#define KDB 1
// #define COMPAT_FREEBSD11 1
#define COMPAT_CHERIABI 1
#define COMPAT_FREEBSD32
#define COMPAT_FREEBSD64
#define CPU_CHERI 1
// #define INVARIANT_SUPPORT 1
#define CPU_MALTA 1
// #define COMPAT_FREEBSD32 1
#define TICK_USE_YAMON_FREQ defined
#define YAMON 1
// Pretend that we have capabilities
#define __CHERI__
#define __has_feature(x) __fake_has_feature_##x
#define __fake_has_feature_capabilities 1
// But we don't really so define __capability to nothing
#define __capability
// And provide the builtins for code completion
long __builtin_cheri_length_get(void* __capability);
long __builtin_cheri_base_get(void* __capability);
long __builtin_cheri_offset_get(void* __capability);
long __builtin_cheri_address_get(void* __capability);
long __builtin_cheri_flags_get(void* __capability);
long __builtin_cheri_perms_get(void* __capability);
long __builtin_cheri_sealed_get(void* __capability);
long __builtin_cheri_tag_get(void* __capability);
long __builtin_cheri_type_get(void* __capability));
void* __capability __builtin_cheri_perms_and(void* __capability, long);
void* __capability __builtin_cheri_tag_clear(void* __capability);
void* __capability __builtin_cheri_offset_increment(void* __capability, long);
void* __capability __builtin_cheri_offset_set(void* __capability, long);
void* __capability __builtin_cheri_address_set(void* __capability, long);
void* __capability __builtin_cheri_flags_set(void* __capability, long);
void* __capability __builtin_cheri_seal(void* __capability, void* __capability);
void* __capability __builtin_cheri_unseal(void* __capability, void* __capability);
void __builtin_cheri_perms_check(void* __capability, long);
void __builtin_cheri_type_check(void* __capability, void* __capability);
void* __capability __builtin_cheri_global_data_get(void);
void* __capability __builtin_cheri_program_counter_get(void);
void* __capability __builtin_cheri_stack_get(void);
// #define INVARIANTS 1
// #define MAC 1
// #define AUDIT 1")
set(CMAKE_C_COMPILER_TARGET ${CLANG_TRIPLE})
set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TRIPLE})
set(CMAKE_SYSROOT ${CMAKE_BINARY_DIR}/sysroot)
enable_language(C)
enable_language(CXX)
# Ensure that we can find the clang builtin headers
add_compile_options(-nobuiltininc)
add_compile_options(-v)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-resource-dir OUTPUT_VARIABLE BUILTIN_HEADERS_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "BUILTIN_HEADERS_DIR=${BUILTIN_HEADERS_DIR}")
add_compile_options(-idirafter ${BUILTIN_HEADERS_DIR}/include)
add_subdirectory(libexec/rtld-cheri-elf)
file(GLOB_RECURSE FAKE_KERNEL_SRCS_MIPS sys/mips "*.c")
file(GLOB_RECURSE FAKE_KERNEL_SRCS_DDB sys/ddb "*.c")
file(GLOB_RECURSE FAKE_KERNEL_SRCS_CHERI sys/cheri "*.c")
file(GLOB_RECURSE FAKE_KERNEL_SRCS_CHERIABI sys/compat/cheriabi "*.c")
file(GLOB_RECURSE FAKE_KERNEL_SRCS_KERN sys/kern "*.c")
file(GLOB_RECURSE FAKE_KERNEL_SRCS_LIBKERN sys/libkern "*.c")
add_library(fake_kernel STATIC ${FAKE_KERNEL_SRCS_MIPS} ${FAKE_KERNEL_SRCS_DDB} ${FAKE_KERNEL_SRCS_CHERI} ${FAKE_KERNEL_SRCS_CHERIABI} ${FAKE_KERNEL_SRCS_KERN} ${FAKE_KERNEL_SRCS_LIBKERN})
target_compile_definitions(fake_kernel PRIVATE _KERNEL=1)
target_include_directories(fake_kernel PRIVATE ${CMAKE_SOURCE_DIR}/sys)
target_include_directories(fake_kernel PRIVATE ${CMAKE_BINARY_DIR}/kern_opt)
target_compile_options(fake_kernel PRIVATE -include ${CMAKE_BINARY_DIR}/kern_opt/opt_global.h)