bond/CMakeLists.txt

147 lines
3.5 KiB
CMake
Raw Permalink Normal View History

2019-06-26 05:47:18 +00:00
cmake_minimum_required(VERSION 3.10)
2019-06-26 05:47:18 +00:00
# disable in-source build
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
2020-02-24 07:16:26 +00:00
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
2019-11-28 18:02:52 +00:00
project(bond)
2019-11-28 18:02:52 +00:00
set(proj bond)
2019-06-26 05:47:18 +00:00
set(INC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
set(MK ${CMAKE_CURRENT_SOURCE_DIR}/mk)
set(arch amd64)
include(${MK}/${arch}.cmake)
# sanity check
set(TOOLCHAINS
AS
CC
GRUB
LD
DMP)
2020-06-23 08:20:23 +00:00
FOREACH (f IN LISTS TOOLCHAINS)
if (NOT ${f})
2019-06-26 05:47:18 +00:00
message(FATAL_ERROR "Toolchain ${f} cannot be found.")
2020-06-23 08:20:23 +00:00
endif ()
endforeach (f)
2019-06-26 05:47:18 +00:00
2019-11-28 18:02:52 +00:00
set(CC_WARN_IGNORE
-Wno-gnu-statement-expression # this means we can assign the return val of the last statment in a block, useful in MAX, MIN, etc.
-Wno-gnu-zero-variadic-macro-arguments # this enables us to use __VA_ARGS__ in macros
)
2019-06-26 05:47:18 +00:00
set(CC_FLAGS
-std=c17
-c
-g
2019-12-07 08:54:18 +00:00
-O0
2019-06-26 05:47:18 +00:00
-Wall
-Wextra
-Wpedantic
-Werror
2019-11-28 18:02:52 +00:00
${CC_WARN_IGNORE}
2019-06-26 05:47:18 +00:00
-ffreestanding
2019-11-28 18:02:52 +00:00
-I${INC}
2019-06-26 05:47:18 +00:00
-fno-pic
-fno-stack-protector
${CC_FLAGS_${ARCH}})
set(AS_FLAGS
${AS_FLAGS_${ARCH}})
set(LD_FLAGS
-fuse-ld=${LD}
-nostdlib
-Wl,--fatal-warnings
2019-12-07 08:54:18 +00:00
-Wl,--build-id=none
2019-06-26 05:47:18 +00:00
${LD_FLAGS_${ARCH}})
set(PP_FLAGS
-E
-xc
-P
-I${INC}
${PP_FLAGS_${ARCH}})
set(DMP_FLAGS
${DMP_FLAGS_${ARCH}})
set(SUBMODULES
2020-02-24 07:16:26 +00:00
common
ke
2019-06-26 05:47:18 +00:00
arch
2020-02-24 07:16:26 +00:00
mm
2019-11-28 18:02:52 +00:00
scripts
test)
2019-06-26 05:47:18 +00:00
# process submodules
2020-06-23 08:20:23 +00:00
FOREACH (f IN LISTS SUBMODULES)
2019-06-26 05:47:18 +00:00
add_subdirectory(${f})
2020-06-23 08:20:23 +00:00
endforeach (f)
2019-06-26 05:47:18 +00:00
# process dependencies
2020-06-23 08:20:23 +00:00
FOREACH (f IN LISTS SUBMODULES)
2019-06-26 05:47:18 +00:00
set(OBJS ${OBJS} ${OBJS_${f}})
set(TARGETS ${TARGETS} ${TARGET_${f}})
2020-06-23 08:20:23 +00:00
endforeach (f)
2019-06-26 05:47:18 +00:00
# set target names
# Rules for generating the image
set(TARGET ${proj}_elf)
set(OBJ_${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${proj}.elf)
add_custom_command(
OUTPUT ${OBJ_${TARGET}}
2019-12-07 08:54:18 +00:00
DEPENDS ${TARGETS} ${OBJS}
2019-06-26 05:47:18 +00:00
COMMAND ${CC} ${LD_FLAGS} -Wl,-T, ${SCRIPT_LD} -o ${OBJ_${TARGET}} ${OBJS})
add_custom_target(${TARGET} ALL
DEPENDS ${OBJ_${TARGET}})
# Rules for generating the dump
set(TARGET ${proj}_dmp)
set(OBJ_${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${proj}.dmp)
add_custom_command(
OUTPUT ${OBJ_${TARGET}}
2019-12-07 08:54:18 +00:00
DEPENDS ${proj}.elf
2019-06-26 05:47:18 +00:00
COMMAND ${DMP} ${DMP_FLAGS} ${OBJ_${proj}_elf} > ${OBJ_${TARGET}}
)
add_custom_target(${proj}_dmp ALL
DEPENDS ${OBJ_${TARGET}})
# Rules for generating the iso
set(TARGET ${proj}_iso)
set(OBJ_${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${proj}.iso)
add_custom_command(
OUTPUT ${OBJ_${TARGET}}
2019-12-07 08:54:18 +00:00
DEPENDS ${proj}.elf
2019-06-26 05:47:18 +00:00
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_iso
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_iso/boot
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/tmp_iso/boot/grub
COMMAND ${CMAKE_COMMAND} -E copy ${OBJ_${proj}_elf} ${CMAKE_CURRENT_BINARY_DIR}/tmp_iso/
COMMAND ${CMAKE_COMMAND} -E copy ${SCRIPT_GRUB} ${CMAKE_CURRENT_BINARY_DIR}/tmp_iso/boot/grub/
COMMAND ${GRUB} -d /usr/lib/grub/i386-pc -o ${OBJ_${TARGET}} ${CMAKE_CURRENT_BINARY_DIR}/tmp_iso
)
add_custom_target(${proj}_iso ALL
DEPENDS ${OBJ_${TARGET}})
# hack for clion not parsing custom targets
if ($ENV{CLION_IDE})
2020-06-23 08:20:23 +00:00
SET(CMAKE_C_COMPILER ${CC})
2019-11-28 18:02:52 +00:00
include_directories(${INC})
2019-06-26 05:47:18 +00:00
add_executable(kernel ${G_CC_SRC})
2020-06-23 08:20:23 +00:00
add_definitions(-DKOPT_DBG)
2019-11-28 18:02:52 +00:00
target_compile_options(kernel PRIVATE ${CC_FLAGS})
2020-06-23 08:20:23 +00:00
endif ()
2018-12-16 23:52:33 +00:00