|
| 1 | +# Copyright (C) 2024 by Skyward |
| 2 | +# |
| 3 | +# This program is free software; you can redistribute it and/or |
| 4 | +# it under the terms of the GNU General Public License as published |
| 5 | +# the Free Software Foundation; either version 2 of the License, or |
| 6 | +# (at your option) any later version. |
| 7 | +# |
| 8 | +# This program is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +# GNU General Public License for more details. |
| 12 | +# |
| 13 | +# As a special exception, if other files instantiate templates or use |
| 14 | +# macros or inline functions from this file, or you compile this file |
| 15 | +# and link it with other works to produce a work based on this file, |
| 16 | +# this file does not by itself cause the resulting work to be covered |
| 17 | +# by the GNU General Public License. However the source code for this |
| 18 | +# file must still be made available in accordance with the GNU |
| 19 | +# Public License. This exception does not invalidate any other |
| 20 | +# why a work based on this file might be covered by the GNU General |
| 21 | +# Public License. |
| 22 | +# |
| 23 | +# You should have received a copy of the GNU General Public License |
| 24 | +# along with this program; if not, see <http://www.gnu.org/licenses/> |
| 25 | + |
| 26 | +cmake_minimum_required(VERSION 3.16) |
| 27 | + |
| 28 | +project(Miosix |
| 29 | + VERSION 2.7 |
| 30 | + DESCRIPTION "OS kernel designed to run on 32bit microcontrollers." |
| 31 | + HOMEPAGE_URL "https://miosix.org" |
| 32 | + LANGUAGES C CXX |
| 33 | +) |
| 34 | + |
| 35 | +set(MIOSIX_KPATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to the miosix kernel") |
| 36 | + |
| 37 | +set(MIOSIX_KERNEL_SRC |
| 38 | + ${MIOSIX_KPATH}/kernel/kernel.cpp |
| 39 | + ${MIOSIX_KPATH}/kernel/sync.cpp |
| 40 | + ${MIOSIX_KPATH}/kernel/error.cpp |
| 41 | + ${MIOSIX_KPATH}/kernel/pthread.cpp |
| 42 | + ${MIOSIX_KPATH}/kernel/boot.cpp |
| 43 | + ${MIOSIX_KPATH}/kernel/elf_program.cpp |
| 44 | + ${MIOSIX_KPATH}/kernel/process.cpp |
| 45 | + ${MIOSIX_KPATH}/kernel/process_pool.cpp |
| 46 | + ${MIOSIX_KPATH}/kernel/timeconversion.cpp |
| 47 | + ${MIOSIX_KPATH}/kernel/intrusive.cpp |
| 48 | + ${MIOSIX_KPATH}/kernel/cpu_time_counter.cpp |
| 49 | + ${MIOSIX_KPATH}/kernel/scheduler/priority/priority_scheduler.cpp |
| 50 | + ${MIOSIX_KPATH}/kernel/scheduler/control/control_scheduler.cpp |
| 51 | + ${MIOSIX_KPATH}/kernel/scheduler/edf/edf_scheduler.cpp |
| 52 | + ${MIOSIX_KPATH}/filesystem/file_access.cpp |
| 53 | + ${MIOSIX_KPATH}/filesystem/file.cpp |
| 54 | + ${MIOSIX_KPATH}/filesystem/path.cpp |
| 55 | + ${MIOSIX_KPATH}/filesystem/stringpart.cpp |
| 56 | + ${MIOSIX_KPATH}/filesystem/pipe/pipe.cpp |
| 57 | + ${MIOSIX_KPATH}/filesystem/console/console_device.cpp |
| 58 | + ${MIOSIX_KPATH}/filesystem/mountpointfs/mountpointfs.cpp |
| 59 | + ${MIOSIX_KPATH}/filesystem/devfs/devfs.cpp |
| 60 | + ${MIOSIX_KPATH}/filesystem/fat32/fat32.cpp |
| 61 | + ${MIOSIX_KPATH}/filesystem/fat32/ff.cpp |
| 62 | + ${MIOSIX_KPATH}/filesystem/fat32/diskio.cpp |
| 63 | + ${MIOSIX_KPATH}/filesystem/fat32/wtoupper.cpp |
| 64 | + ${MIOSIX_KPATH}/filesystem/fat32/ccsbcs.cpp |
| 65 | + ${MIOSIX_KPATH}/filesystem/littlefs/lfs_miosix.cpp |
| 66 | + ${MIOSIX_KPATH}/filesystem/littlefs/lfs.c |
| 67 | + ${MIOSIX_KPATH}/filesystem/littlefs/lfs_util.c |
| 68 | + ${MIOSIX_KPATH}/filesystem/romfs/romfs.cpp |
| 69 | + ${MIOSIX_KPATH}/stdlib_integration/libc_integration.cpp |
| 70 | + ${MIOSIX_KPATH}/stdlib_integration/libstdcpp_integration.cpp |
| 71 | + ${MIOSIX_KPATH}/e20/e20.cpp |
| 72 | + ${MIOSIX_KPATH}/e20/unmember.cpp |
| 73 | + ${MIOSIX_KPATH}/util/util.cpp |
| 74 | + ${MIOSIX_KPATH}/util/unicode.cpp |
| 75 | + ${MIOSIX_KPATH}/util/version.cpp |
| 76 | + ${MIOSIX_KPATH}/util/crc16.cpp |
| 77 | + ${MIOSIX_KPATH}/util/lcd44780.cpp |
| 78 | +) |
| 79 | + |
| 80 | +# Include the architecture options |
| 81 | +include(${MIOSIX_KPATH}/arch/CMakeLists.txt) |
| 82 | + |
| 83 | +# Verify that all the required variables have been defined, otherwise abort |
| 84 | +set(REQUIRED_VARIABLES |
| 85 | + MIOSIX_OPT_BOARD |
| 86 | + MIOSIX_ARCH_INC |
| 87 | + MIOSIX_BOARD_INC |
| 88 | + MIOSIX_BOARD_SETTINGS_INC |
| 89 | + MIOSIX_LINKER_SCRIPT |
| 90 | + MIOSIX_A_FLAGS |
| 91 | + MIOSIX_C_FLAGS |
| 92 | + MIOSIX_CXX_FLAGS |
| 93 | + MIOSIX_L_FLAGS |
| 94 | + MIOSIX_ARCH_SRC |
| 95 | +) |
| 96 | +foreach(VARIABLE ${REQUIRED_VARIABLES}) |
| 97 | + if(NOT DEFINED ${VARIABLE}) |
| 98 | + message(FATAL_ERROR "arch/CMakeLists.txt must define ${VARIABLE}") |
| 99 | + endif() |
| 100 | +endforeach() |
| 101 | + |
| 102 | +# The user can set a custom path for miosix_settings.h |
| 103 | +set(MIOSIX_SETTINGS_PATH ${MIOSIX_KPATH}/default CACHE PATH "Include directory for miosix_settings.h") |
| 104 | +mark_as_advanced(MIOSIX_SETTINGS_PATH) |
| 105 | +if(NOT MIOSIX_SETTINGS_PATH STREQUAL ${MIOSIX_KPATH}/default) |
| 106 | + message(NOTICE "You have set a custom path for miosix_settings.h") |
| 107 | +endif() |
| 108 | + |
| 109 | +# Define the miosix library with kernel and architecture sources |
| 110 | +add_library(miosix STATIC ${MIOSIX_KERNEL_SRC} ${MIOSIX_ARCH_SRC}) |
| 111 | + |
| 112 | +target_include_directories(miosix PUBLIC |
| 113 | + ${MIOSIX_KPATH} |
| 114 | + ${MIOSIX_KPATH}/arch/common |
| 115 | + ${MIOSIX_ARCH_INC} |
| 116 | + ${MIOSIX_BOARD_INC} |
| 117 | + ${MIOSIX_BOARD_SETTINGS_INC} |
| 118 | + ${MIOSIX_SETTINGS_PATH} |
| 119 | +) |
| 120 | + |
| 121 | +target_compile_options(miosix PUBLIC |
| 122 | + $<$<COMPILE_LANGUAGE:ASM>:${MIOSIX_A_FLAGS}> |
| 123 | + $<$<COMPILE_LANGUAGE:C>:${MIOSIX_C_FLAGS}> |
| 124 | + $<$<COMPILE_LANGUAGE:CXX>:${MIOSIX_CXX_FLAGS}> |
| 125 | +) |
| 126 | + |
| 127 | +# Configure program command as a propery of the miosix library |
| 128 | +set_property(TARGET miosix PROPERTY PROGRAM_CMDLINE ${PROGRAM_CMDLINE}) |
| 129 | + |
| 130 | +# Add COMPILING_MIOSIX define for private headers |
| 131 | +target_compile_definitions(miosix PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:COMPILING_MIOSIX>) |
| 132 | + |
| 133 | +# Configure linker file and options needed to link agains this library |
| 134 | +set_property(TARGET miosix PROPERTY LINK_DEPENDS ${MIOSIX_BOARD_INC}/${MIOSIX_LINKER_SCRIPT}) |
| 135 | +target_link_options(miosix INTERFACE ${MIOSIX_L_FLAGS}) |
| 136 | + |
| 137 | +# Run the kernel_global_objects.pl script on all kernel objects |
| 138 | +add_custom_command( |
| 139 | + TARGET miosix PRE_LINK |
| 140 | + COMMAND perl ${MIOSIX_KPATH}/_tools/kernel_global_objects.pl $<TARGET_OBJECTS:miosix> |
| 141 | + VERBATIM |
| 142 | + COMMAND_EXPAND_LISTS |
| 143 | +) |
| 144 | + |
| 145 | +# Optionally print the board list |
| 146 | +option(MIOSIX_PRINT_BOARD_LIST "Prints a list of the available boards" OFF) |
| 147 | +if(MIOSIX_PRINT_BOARD_LIST) |
| 148 | + message(STATUS "Available boards:") |
| 149 | + foreach(MIOSIX_OPT_BOARD ${MIOSIX_BOARDS}) |
| 150 | + message(STATUS "\t${MIOSIX_OPT_BOARD}") |
| 151 | + endforeach() |
| 152 | +endif() |
0 commit comments