Skip to content

Commit 0de2a77

Browse files
committed
Cmake: Decouple how user & kernel flags are included
Building applications should should be orthogonal of how kernel is build. But previously flags for both kernel and user applications were set and dealt with together in 'mosflags.cmake' file. Now 'userflags.cmake' & 'kernelflags.cmake' are separate files are included individually corresponding to what is being build. Common things are in 'commonflags.cmake.
1 parent ffe42b7 commit 0de2a77

File tree

11 files changed

+91
-85
lines changed

11 files changed

+91
-85
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ endif()
5757
#---------------------------------------------------------------------------
5858

5959
include(cmake/compile_assemble_link.cmake)
60-
include(cmake/mosflags.cmake)
6160

6261
set(MOS_BIN_DIR ${CMAKE_BINARY_DIR}/bin)
6362
set(MOS_OBJ_DIR ${CMAKE_BINARY_DIR}/obj)
@@ -191,6 +190,8 @@ if(CMAKE_CROSSCOMPILING)
191190
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
192191
)
193192
else()
193+
include(cmake/x86/unittestflags.cmake)
194+
194195
#---------------------------------------------------------------------------
195196
# Validate compiler features required for compiling unittests
196197
#---------------------------------------------------------------------------

cmake/mosflags.cmake

Lines changed: 0 additions & 36 deletions
This file was deleted.

cmake/x86/commonflags.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
set(MOS_GCC_WARN_FLAGS
2+
-Wpedantic
3+
-Wall
4+
-Wextra
5+
-Wconversion
6+
-Wdangling-else
7+
-Werror
8+
)
9+
10+
set(MOS_GCC_FLAGS
11+
-std=c99
12+
-nostartfiles
13+
-ffreestanding
14+
-fno-pie
15+
-fno-stack-protector
16+
-fno-asynchronous-unwind-tables
17+
-m32
18+
-march=i686
19+
-masm=intel
20+
-mno-red-zone
21+
-mno-sse
22+
-malign-data=abi
23+
-Os
24+
-fno-unit-at-a-time
25+
-fno-omit-frame-pointer
26+
-fno-inline-functions-called-once
27+
)
28+
29+
set(MOS_LINKER_OPTIONS
30+
-ffreestanding
31+
-nostdlib
32+
)

cmake/x86/kernelflags.cmake

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
1-
set(MOS_KERNEL_GCC_WARN_FLAGS
2-
-Wpedantic
3-
-Wall
4-
-Wextra
5-
-Wconversion
6-
-Wdangling-else
7-
-Werror
8-
)
1+
include(${PROJECT_SOURCE_DIR}/cmake/${ARCH}/commonflags.cmake)
92

3+
# ----------------------------------------------------
4+
# GCC
5+
# ----------------------------------------------------
106
set(MOS_KERNEL_GCC_FLAGS
11-
${MOS_KERNEL_GCC_WARN_FLAGS}
12-
-std=c99
13-
-nostartfiles
14-
-ffreestanding
15-
-fno-pie
16-
-fno-stack-protector
17-
-fno-asynchronous-unwind-tables
18-
-m32
19-
-march=i686
20-
-masm=intel
21-
-mno-red-zone
22-
-mno-sse
23-
-malign-data=abi
24-
-Os
25-
-fno-unit-at-a-time
26-
-fno-omit-frame-pointer
27-
-fno-inline-functions-called-once
28-
)
7+
${MOS_GCC_WARN_FLAGS}
8+
${MOS_GCC_FLAGS}
9+
)
2910

3011
set(MOS_KERNEL_GCC_DEFINITIONS
3112
${MOS_BUILD_MODE}
@@ -38,6 +19,13 @@ if (MOS_PORT_E9_ENABLED)
3819
list(APPEND MOS_KERNEL_GCC_DEFINITIONS PORT_E9_ENABLED)
3920
endif()
4021

22+
set(MOS_KERNEL_GCC_INCLUDE_DIRS
23+
${PROJECT_SOURCE_DIR}/include
24+
)
25+
26+
# ----------------------------------------------------
27+
# NASM
28+
# ----------------------------------------------------
4129
set(MOS_KERNEL_NASM_DEFINITIONS
4230
KERNEL
4331
)
@@ -57,8 +45,28 @@ set(MOS_KERNEL_ASM_INCLUDE_DIRS
5745
${PROJECT_SOURCE_DIR}/include/x86/asm
5846
)
5947

60-
set(MOS_KERNEL_GCC_INCLUDE_DIRS
61-
${PROJECT_SOURCE_DIR}/include
62-
)
48+
# ----------------------------------------------------
49+
# Both GCC & NASM
50+
# ----------------------------------------------------
51+
if (MOS_BUILD_MODE STREQUAL "DEBUG")
52+
list(APPEND MOS_KERNEL_GCC_FLAGS -g)
53+
list(APPEND MOS_KERNEL_NASM_ELF_MODE_FLAGS -g)
54+
endif()
55+
56+
If (MOS_GRAPHICS_ENABLED)
57+
list(APPEND MOS_KERNEL_GCC_DEFINITIONS
58+
GRAPHICS_MODE_ENABLED
59+
GRAPHICS_BPP=${MOS_GRAPHICS_BPP}
60+
)
61+
62+
list(APPEND MOS_KERNEL_NASM_DEFINITIONS
63+
GRAPHICS_MODE_ENABLED
64+
GRAPHICS_BPP=${MOS_GRAPHICS_BPP}
65+
)
66+
endif()
67+
6368

69+
# ----------------------------------------------------
70+
# LINKER
71+
# ----------------------------------------------------
6472
set(MOS_KERNEL_LINKER_SCRIPT_FILE ${PROJECT_SOURCE_DIR}/src/kernel/x86/kernel.ld)

cmake/x86/userflags.cmake

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1+
include(${PROJECT_SOURCE_DIR}/cmake/${ARCH}/commonflags.cmake)
2+
13
set(MOS_USER_GCC_FLAGS
2-
${MOS_KERNEL_GCC_WARN_FLAGS}
3-
-std=c99
4-
-nostartfiles
5-
-ffreestanding
6-
-fno-pie
7-
-fno-stack-protector
8-
-fno-asynchronous-unwind-tables
9-
-m32
10-
-march=i686
11-
-masm=intel
12-
-mno-red-zone
13-
-mno-sse
14-
-malign-data=abi
15-
-Os
16-
-fno-unit-at-a-time
17-
-fno-omit-frame-pointer
18-
-fno-inline-functions-called-once
4+
${MOS_GCC_WARN_FLAGS}
5+
${MOS_GCC_FLAGS}
196
-fno-inline-small-functions
20-
)
7+
)
218

229
set(MOS_USER_GCC_DEFINITIONS
2310
${MOS_BUILD_MODE}
@@ -29,5 +16,4 @@ set(MOS_USER_GCC_INCLUDE_DIRS
2916
${PROJECT_SOURCE_DIR}/include/applib
3017
)
3118

32-
3319
set(MOS_USER_LINKER_SCRIPT_FILE ${PROJECT_SOURCE_DIR}/src/kernel/x86/process.ld)

src/apps/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(${PROJECT_SOURCE_DIR}/cmake/${ARCH}/userflags.cmake)
2+
13
# ---------------------------------------------------------------------------
24
# Program - Proc1
35
# ---------------------------------------------------------------------------

src/apps/applib/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(${PROJECT_SOURCE_DIR}/cmake/${ARCH}/kernelflags.cmake)
2+
13
# ------------------------------------------------------------------------
24
# CRTA
35
# Application C Runtime is analogous to the CRT in Linux, it provides prologue & epilogue code for

src/bootloader/x86/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(${PROJECT_SOURCE_DIR}/cmake/${ARCH}/kernelflags.cmake)
2+
13
assemble_and_copy_bin(
24
NAME boot0.flt
35
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boot0/boot.s

src/kernel/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
include(${PROJECT_SOURCE_DIR}/cmake/${ARCH}/kernelflags.cmake)
2+
3+
#---------------------------------------------------------------------------
4+
# Build Arch independent kernel
5+
#---------------------------------------------------------------------------
16
set(KERNEL_SOURCES
27
${CMAKE_CURRENT_SOURCE_DIR}/kpanic.c
38
${CMAKE_CURRENT_SOURCE_DIR}/kmalloc.c

src/kernel/drivers/x86/pc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(${PROJECT_SOURCE_DIR}/cmake/${ARCH}/kernelflags.cmake)
2+
13
set(DRIVER_SOUCES
24
${CMAKE_CURRENT_SOURCE_DIR}/8259_pic.c
35
${CMAKE_CURRENT_SOURCE_DIR}/8254_pit.c

0 commit comments

Comments
 (0)