-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
96 lines (83 loc) · 2.59 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
cmake_minimum_required(VERSION 3.10)
project(mipos-examples)
# Detect if the compiler is GCC or Clang and set flags
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(COMPILER_FLAGS "-fno-common")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(APPLE)
# Set the C flags
set(CMAKE_C_FLAGS
"-v -g -Wno-incompatible-pointer-types -Wno-pointer-sign \
-fno-common -Wparentheses-equality \
-DMIPOS_TARGET_SIMU \
-DENABLE_MIPOS_FS \
-DENABLE_MIPOS_STDIO \
-DENABLE_MIPOS_CONSOLE \
-DENABLE_MIPOS_MALLOC \
-DENABLE_MIPOS_MPOOL"
)
# Set architecture to x86_64
set(CMAKE_OSX_ARCHITECTURES "x86_64")
set(LINKER_FLAGS "-Wl,--warn-common")
else()
set(CMAKE_C_FLAGS
"-g -m32 -fPIC -fPIE -Wno-incompatible-pointer-types -Wno-pointer-sign \
-fno-common \
-DMIPOS_TARGET_SIMU \
-DENABLE_MIPOS_FS \
-DENABLE_MIPOS_STDIO \
-DENABLE_MIPOS_CONSOLE \
-DENABLE_MIPOS_MALLOC \
-DENABLE_MIPOS_MPOOL"
)
endif()
# Include directories
include_directories(mipos mipos/arch/simu fatfs)
# MIPOS library
add_library(mipos STATIC
mipos/mipos_console.c
mipos/mipos_tfs.c
mipos/mipos_kernel.c
mipos/mipos_malloc.c
mipos/mipos_mpool.c
mipos/mipos_queue.c
mipos/mipos_stdio.c
mipos/mipos_task.c
mipos/mipos_timer.c
mipos/mipos_diskio.c
mipos/arch/simu/mipos_bsp_simu.c
)
set_target_properties(mipos PROPERTIES POSITION_INDEPENDENT_CODE ON)
# FATFS library
add_library(fatfs STATIC
fatfs/diskio.c
fatfs/ff.c
fatfs/ffsystem.c
fatfs/ffunicode.c
)
set_target_properties(fatfs PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Add executables and link libraries
foreach(example IN ITEMS helloworld malloc timers multitask console filesystem fatfs)
add_executable(example-${example} examples/simu/${example}/main.c)
target_link_libraries(example-${example} mipos)
endforeach()
# Link fatfs library to example-fatfs
target_link_libraries(example-fatfs fatfs)
# Custom command for example-fatfs
add_custom_command(
TARGET example-fatfs POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/examples/simu/fatfs/disk.img
${CMAKE_CURRENT_BINARY_DIR}/disk.img
)
# Link against system libraries for macOS
if(APPLE)
target_link_libraries(mipos PUBLIC "-framework CoreFoundation")
target_link_libraries(mipos PUBLIC "-framework IOKit")
target_link_libraries(mipos PUBLIC "-lSystem")
# Apply additional linker flags
set_target_properties(mipos PROPERTIES LINK_FLAGS "${LINKER_FLAGS}")
# Use force_load flag to address duplicate symbols issue if necessary
set_target_properties(mipos PROPERTIES LINK_FLAGS "-Wl,-force_load,libmipos.a")
endif()