This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
CMakeLists.txt
97 lines (79 loc) · 3.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
97
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
PROJECT(duckOS C CXX ASM)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_SYSROOT ${CMAKE_BINARY_DIR}/root)
set(CMAKE_STAGING_PREFIX ${CMAKE_BINARY_DIR}/root)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/root)
set(CMAKE_INSTALL_DATAROOTDIR ${CMAKE_BINARY_DIR}/root/res)
set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_CXX_STANDARD 17)
SET_PROPERTY(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "root")
# Options
SET(ADD_KERNEL_DEBUG_SYMBOLS OFF CACHE BOOL "Add symbols to the kernel -g and -ggdb for debugging")
IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
SET(KERNEL_EXECUTABLE_NAME duckk32)
ELSEIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
SET(KERNEL_EXECUTABLE_NAME duckk64)
ENDIF()
function(MAKE_LIBRARY LIBNAME)
# Install dynamic library
ADD_LIBRARY(${LIBNAME} SHARED ${SOURCES})
INSTALL(TARGETS ${LIBNAME} LIBRARY DESTINATION lib)
SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
ADD_DEPENDENCIES(${LIBNAME} libc)
# Install static library
ADD_LIBRARY(${LIBNAME}_static STATIC ${SOURCES})
INSTALL(TARGETS ${LIBNAME}_static DESTINATION lib)
SET_TARGET_PROPERTIES(${LIBNAME}_static PROPERTIES PREFIX "")
ADD_DEPENDENCIES(${LIBNAME}_static libc)
# Install headers
FILE(GLOB_RECURSE LIBHEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
foreach(HEADER ${LIBHEADERS})
GET_FILENAME_COMPONENT(SUBDIRECTORY ${HEADER} DIRECTORY)
install(FILES ${HEADER} DESTINATION usr/include/${LIBNAME}/${SUBDIRECTORY})
endforeach()
FILE(GLOB_RECURSE LIBHEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.hpp")
foreach(HEADER ${LIBHEADERS})
GET_FILENAME_COMPONENT(SUBDIRECTORY ${HEADER} DIRECTORY)
install(FILES ${HEADER} DESTINATION usr/include/${LIBNAME}/${SUBDIRECTORY})
endforeach()
endfunction()
function(MAKE_PROGRAM PROGNAME)
ADD_EXECUTABLE(${PROGNAME} ${SOURCES})
INSTALL(TARGETS ${PROGNAME} RUNTIME DESTINATION bin)
ADD_DEPENDENCIES(${PROGNAME} libc)
endfunction()
function(MAKE_APP APPNAME)
ADD_EXECUTABLE(${APPNAME} ${SOURCES})
INSTALL(TARGETS ${APPNAME} RUNTIME DESTINATION apps/${APPNAME}.app)
INSTALL(DIRECTORY resources/ DESTINATION apps/${APPNAME}.app)
ADD_DEPENDENCIES(${APPNAME} libc)
endfunction()
INCLUDE_DIRECTORIES(libraries/)
INCLUDE_DIRECTORIES(libraries/libc)
INCLUDE_DIRECTORIES(.)
include_directories(${TOOLCHAIN_ROOT_DIR}/${TOOLCHAIN_PLATFORM}/include/c++/${GCC_VER}/)
include_directories(${TOOLCHAIN_ROOT_DIR}/${TOOLCHAIN_PLATFORM}/include/c++/${GCC_VER}/${TOOLCHAIN_PLATFORM}/)
LINK_DIRECTORIES(${TOOLCHAIN_ROOT_DIR}/lib/gcc/${TOOLCHAIN_PLATFORM}/${GCC_VER}/)
LINK_DIRECTORIES(${TOOLCHAIN_ROOT_DIR}/${TOOLCHAIN_PLATFORM}/lib/)
ADD_SUBDIRECTORY(kernel/)
ADD_SUBDIRECTORY(libraries/)
ADD_SUBDIRECTORY(services/)
ADD_SUBDIRECTORY(programs/)
ADD_CUSTOM_TARGET(image
COMMAND ${CMAKE_COMMAND} -E env "SOURCE_DIR=${CMAKE_SOURCE_DIR}" "ARCH=${CMAKE_SYSTEM_PROCESSOR}" ${CMAKE_SOURCE_DIR}/scripts/image.sh $(IMAGE_DEV)
BYPRODUCTS ${CMAKE_BINARY_DIR}/duckOS.img
USES_TERMINAL
)
ADD_CUSTOM_TARGET(base-system
COMMAND ${CMAKE_COMMAND} -E env "SOURCE_DIR=${CMAKE_SOURCE_DIR}" ${CMAKE_SOURCE_DIR}/scripts/base-system.sh $(ROOT_DIR)
USES_TERMINAL
)
ADD_CUSTOM_TARGET(qemu
COMMAND ${CMAKE_COMMAND} -E env "KERNEL_NAME=${KERNEL_EXECUTABLE_NAME}" "ARCH=${CMAKE_SYSTEM_PROCESSOR}" ${CMAKE_SOURCE_DIR}/scripts/qemu.sh
USES_TERMINAL
)
ADD_CUSTOM_TARGET(tests
COMMAND ${CMAKE_COMMAND} -E env "KERNEL_NAME=${KERNEL_EXECUTABLE_NAME}" "ARCH=${CMAKE_SYSTEM_PROCESSOR}" ${CMAKE_SOURCE_DIR}/scripts/qemu.sh kernel-tests=true
USES_TERMINAL
)