Skip to content

Commit 0cc43fb

Browse files
committed
add cmake
Signed-off-by: Zone.NiuZH <[email protected]>
1 parent cc25883 commit 0cc43fb

File tree

4 files changed

+279
-0
lines changed

4 files changed

+279
-0
lines changed

CMakePresets.json

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 27,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "host",
11+
"description": "Linux Only",
12+
"hidden": true,
13+
"condition": {
14+
"type": "equals",
15+
"lhs": "${hostSystemName}",
16+
"rhs": "Linux"
17+
}
18+
},
19+
{
20+
"name": "std",
21+
"description": "This preset makes sure the project actually builds with at least the specified standard",
22+
"hidden": true,
23+
"cacheVariables": {
24+
"CMAKE_C_EXTENSIONS": "OFF",
25+
"CMAKE_C_STANDARD": "23",
26+
"CMAKE_C_STANDARD_REQUIRED": "ON",
27+
"CMAKE_CXX_EXTENSIONS": "OFF",
28+
"CMAKE_CXX_STANDARD": "23",
29+
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
30+
}
31+
},
32+
{
33+
"name": "configurePresets_base",
34+
"hidden": true,
35+
"inherits": [
36+
"host",
37+
"std"
38+
],
39+
"displayName": "configurePresets_base",
40+
"description": "base configurePresets",
41+
"generator": "Unix Makefiles",
42+
"toolchainFile": "",
43+
"binaryDir": "",
44+
"installDir": "",
45+
"cacheVariables": {
46+
"CMAKE_VERBOSE_MAKEFILE": {
47+
"type": "BOOL",
48+
"value": "TRUE"
49+
},
50+
"CMAKE_EXPORT_COMPILE_COMMANDS": {
51+
"type": "BOOL",
52+
"value": "ON"
53+
},
54+
"CMAKE_BUILD_TYPE": {
55+
"type": "STRING",
56+
"value": "Debug"
57+
},
58+
"CMAKE_SYSTEM_NAME": {
59+
"type": "STRING",
60+
"value": "Generic"
61+
},
62+
"COVERAGE_OUTPUT_DIR": {
63+
"type": "STRING",
64+
"value": "coverage"
65+
}
66+
}
67+
},
68+
{
69+
"name": "build_x86_64",
70+
"hidden": false,
71+
"inherits": [
72+
"configurePresets_base"
73+
],
74+
"displayName": "build x86_64",
75+
"description": "build x86_64",
76+
"toolchainFile": "${sourceDir}/cmake/x86_64-gcc.cmake",
77+
"binaryDir": "${sourceDir}/build_x86_64",
78+
"cacheVariables": {
79+
"CMAKE_SYSTEM_PROCESSOR": {
80+
"type": "STRING",
81+
"value": "x86_64"
82+
},
83+
"EXECUTABLE_OUTPUT_PATH": {
84+
"type": "STRING",
85+
"value": "${sourceDir}/build_x86_64/bin"
86+
},
87+
"LIBRARY_OUTPUT_PATH": {
88+
"type": "STRING",
89+
"value": "${sourceDir}/build_x86_64/lib"
90+
}
91+
}
92+
},
93+
{
94+
"name": "build_riscv64",
95+
"hidden": false,
96+
"inherits": [
97+
"configurePresets_base"
98+
],
99+
"displayName": "build riscv64",
100+
"description": "build riscv64",
101+
"toolchainFile": "${sourceDir}/cmake/riscv64-gcc.cmake",
102+
"binaryDir": "${sourceDir}/build_riscv64",
103+
"cacheVariables": {
104+
"CMAKE_SYSTEM_PROCESSOR": {
105+
"type": "STRING",
106+
"value": "riscv64"
107+
},
108+
"EXECUTABLE_OUTPUT_PATH": {
109+
"type": "STRING",
110+
"value": "${sourceDir}/build_riscv64/bin"
111+
},
112+
"LIBRARY_OUTPUT_PATH": {
113+
"type": "STRING",
114+
"value": "${sourceDir}/build_riscv64/lib"
115+
}
116+
}
117+
},
118+
{
119+
"name": "build_aarch64",
120+
"hidden": false,
121+
"inherits": [
122+
"configurePresets_base"
123+
],
124+
"displayName": "build aarch64",
125+
"description": "build aarch64",
126+
"toolchainFile": "${sourceDir}/cmake/aarch64-gcc.cmake",
127+
"binaryDir": "${sourceDir}/build_aarch64",
128+
"cacheVariables": {
129+
"CMAKE_SYSTEM_PROCESSOR": {
130+
"type": "STRING",
131+
"value": "aarch64"
132+
},
133+
"EXECUTABLE_OUTPUT_PATH": {
134+
"type": "STRING",
135+
"value": "${sourceDir}/build_aarch64/bin"
136+
},
137+
"LIBRARY_OUTPUT_PATH": {
138+
"type": "STRING",
139+
"value": "${sourceDir}/build_aarch64/lib"
140+
}
141+
}
142+
}
143+
]
144+
}

cmake/aarch64-gcc.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# This file is a part of Simple-XX/SimpleKernel
3+
# (https://github.com/Simple-XX/SimpleKernel).
4+
#
5+
# aarch64-gcc.cmake for Simple-XX/SimpleKernel.
6+
7+
if (NOT UNIX)
8+
message(FATAL_ERROR "Only support Linux.")
9+
endif ()
10+
11+
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
12+
find_program(Compiler_gcc g++)
13+
if (NOT Compiler_gcc)
14+
message(FATAL_ERROR "g++ not found.\n"
15+
"Run `sudo apt-get install -y gcc g++` to install.")
16+
else ()
17+
message(STATUS "Found g++ ${Compiler_gcc}")
18+
endif ()
19+
elseif (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
20+
find_program(Compiler_gcc aarch64-linux-gnu-g++)
21+
if (NOT Compiler_gcc)
22+
message(FATAL_ERROR "aarch64-linux-gnu-g++ not found.\n"
23+
"Run `sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu` to install.")
24+
else ()
25+
message(STATUS "Found aarch64-linux-gnu-g++ ${Compiler_gcc}")
26+
endif ()
27+
28+
set(TOOLCHAIN_PREFIX aarch64-linux-gnu-)
29+
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
30+
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
31+
set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf)
32+
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
33+
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
34+
set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm)
35+
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump)
36+
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
37+
else ()
38+
message(FATAL_ERROR "NOT support ${CMAKE_HOST_SYSTEM_PROCESSOR}")
39+
endif ()

cmake/riscv64-gcc.cmake

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
# This file is a part of Simple-XX/SimpleKernel
3+
# (https://github.com/Simple-XX/SimpleKernel).
4+
#
5+
# riscv64-gcc.cmake for Simple-XX/SimpleKernel.
6+
7+
if (NOT UNIX)
8+
message(FATAL_ERROR "Only support Linux.")
9+
endif ()
10+
11+
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "riscv64")
12+
# GCC
13+
find_program(Compiler_gcc g++)
14+
if (NOT Compiler_gcc)
15+
message(FATAL_ERROR "g++ not found.\n"
16+
"Run `sudo apt-get install -y gcc g++` to install.")
17+
else ()
18+
message(STATUS "Found g++ ${Compiler_gcc}")
19+
endif ()
20+
elseif (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
21+
find_program(Compiler_gcc riscv64-linux-gnu-g++)
22+
if (NOT Compiler_gcc)
23+
message(FATAL_ERROR "riscv64-linux-gnu-g++ not found.\n"
24+
"Run `sudo apt install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu` to install.")
25+
endif ()
26+
27+
set(TOOLCHAIN_PREFIX riscv64-linux-gnu-)
28+
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
29+
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
30+
set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf)
31+
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
32+
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
33+
set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm)
34+
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump)
35+
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
36+
elseif (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
37+
find_program(Compiler_gcc_cr riscv64-linux-gnu-g++)
38+
if (NOT Compiler_gcc_cr)
39+
message(FATAL_ERROR "riscv64-linux-gnu-g++ not found.\n"
40+
"Run `sudo apt install -y g++-riscv64-linux-gnu` to install.")
41+
else ()
42+
message(STATUS "Found riscv64-linux-gnu-g++ ${Compiler_gcc_cr}")
43+
endif ()
44+
45+
set(TOOLCHAIN_PREFIX riscv64-linux-gnu-)
46+
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
47+
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
48+
set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf)
49+
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
50+
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
51+
set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm)
52+
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump)
53+
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
54+
else ()
55+
message(FATAL_ERROR "NOT support ${CMAKE_HOST_SYSTEM_PROCESSOR}")
56+
endif ()

cmake/x86_64-gcc.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# This file is a part of Simple-XX/SimpleKernel
3+
# (https://github.com/Simple-XX/SimpleKernel).
4+
#
5+
# x86_64-gcc.cmake for Simple-XX/SimpleKernel.
6+
7+
if (NOT UNIX)
8+
message(FATAL_ERROR "Only support Linux.")
9+
endif ()
10+
11+
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
12+
# GCC
13+
find_program(Compiler_gcc g++)
14+
if (NOT Compiler_gcc)
15+
message(FATAL_ERROR "g++ not found.\n"
16+
"Run `sudo apt-get install -y gcc g++` to install.")
17+
else ()
18+
message(STATUS "Found g++ ${Compiler_gcc}")
19+
endif ()
20+
elseif (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
21+
find_program(Compiler_gcc_cr x86_64-linux-gnu-g++)
22+
if (NOT Compiler_gcc_cr)
23+
message(FATAL_ERROR "aarch64-linux-gnu-g++ not found.\n"
24+
"Run `sudo apt install -y g++-multilib-x86-64-linux-gnu` to install.")
25+
else ()
26+
message(STATUS "Found x86_64-linux-gnu-g++ ${Compiler_gcc_cr}")
27+
endif ()
28+
29+
set(TOOLCHAIN_PREFIX x86_64-linux-gnu-)
30+
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
31+
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
32+
set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf)
33+
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
34+
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
35+
set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm)
36+
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump)
37+
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
38+
else ()
39+
message(FATAL_ERROR "NOT support ${CMAKE_HOST_SYSTEM_PROCESSOR}")
40+
endif ()

0 commit comments

Comments
 (0)