Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CMake #8

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ image.uf2
*.d

# Exclude build directories and host executables
miosix/_tools/filesystems/build
miosix/_tools/filesystems/buildromfs
miosix/_tools/bin2uf2/build
miosix/_tools/bin2uf2/bin2uf2

# Exclude all build directories
build

# Exclude Mac OS X temporary
._*
.DS_Store
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (C) 2024 by Skyward
#
# This program is free software; you can redistribute it and/or
# it under the terms of the GNU General Public License as published
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# As a special exception, if other files instantiate templates or use
# macros or inline functions from this file, or you compile this file
# and link it with other works to produce a work based on this file,
# this file does not by itself cause the resulting work to be covered
# by the GNU General Public License. However the source code for this
# file must still be made available in accordance with the GNU
# Public License. This exception does not invalidate any other
# why a work based on this file might be covered by the GNU General
# Public License.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>

cmake_minimum_required(VERSION 3.16)

project(Main C CXX ASM)

# Set here your board of choice
set(MIOSIX_OPT_BOARD NOT_SET CACHE STRING "Target board")

add_subdirectory(miosix EXCLUDE_FROM_ALL)
include(LinkTarget)

# List here your source files (.s, .c and .cpp)
add_executable(main main.cpp)
miosix_link_target(main)
miosix_add_program_target(main)

# List here additional include directories
# target_include_directories(main PRIVATE here_your_includes)

# List here additional static libraries
# target_link_libraries(main PRIVATE here_your_libraries)
152 changes: 152 additions & 0 deletions miosix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Copyright (C) 2024 by Skyward
#
# This program is free software; you can redistribute it and/or
# it under the terms of the GNU General Public License as published
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# As a special exception, if other files instantiate templates or use
# macros or inline functions from this file, or you compile this file
# and link it with other works to produce a work based on this file,
# this file does not by itself cause the resulting work to be covered
# by the GNU General Public License. However the source code for this
# file must still be made available in accordance with the GNU
# Public License. This exception does not invalidate any other
# why a work based on this file might be covered by the GNU General
# Public License.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>

cmake_minimum_required(VERSION 3.16)

project(Miosix
VERSION 2.7
DESCRIPTION "OS kernel designed to run on 32bit microcontrollers."
HOMEPAGE_URL "https://miosix.org"
LANGUAGES C CXX
)

set(MIOSIX_KPATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to the miosix kernel")

set(MIOSIX_KERNEL_SRC
${MIOSIX_KPATH}/kernel/kernel.cpp
${MIOSIX_KPATH}/kernel/sync.cpp
${MIOSIX_KPATH}/kernel/error.cpp
${MIOSIX_KPATH}/kernel/pthread.cpp
${MIOSIX_KPATH}/kernel/boot.cpp
${MIOSIX_KPATH}/kernel/elf_program.cpp
${MIOSIX_KPATH}/kernel/process.cpp
${MIOSIX_KPATH}/kernel/process_pool.cpp
${MIOSIX_KPATH}/kernel/timeconversion.cpp
${MIOSIX_KPATH}/kernel/intrusive.cpp
${MIOSIX_KPATH}/kernel/cpu_time_counter.cpp
${MIOSIX_KPATH}/kernel/scheduler/priority/priority_scheduler.cpp
${MIOSIX_KPATH}/kernel/scheduler/control/control_scheduler.cpp
${MIOSIX_KPATH}/kernel/scheduler/edf/edf_scheduler.cpp
${MIOSIX_KPATH}/filesystem/file_access.cpp
${MIOSIX_KPATH}/filesystem/file.cpp
${MIOSIX_KPATH}/filesystem/path.cpp
${MIOSIX_KPATH}/filesystem/stringpart.cpp
${MIOSIX_KPATH}/filesystem/pipe/pipe.cpp
${MIOSIX_KPATH}/filesystem/console/console_device.cpp
${MIOSIX_KPATH}/filesystem/mountpointfs/mountpointfs.cpp
${MIOSIX_KPATH}/filesystem/devfs/devfs.cpp
${MIOSIX_KPATH}/filesystem/fat32/fat32.cpp
${MIOSIX_KPATH}/filesystem/fat32/ff.cpp
${MIOSIX_KPATH}/filesystem/fat32/diskio.cpp
${MIOSIX_KPATH}/filesystem/fat32/wtoupper.cpp
${MIOSIX_KPATH}/filesystem/fat32/ccsbcs.cpp
${MIOSIX_KPATH}/filesystem/littlefs/lfs_miosix.cpp
${MIOSIX_KPATH}/filesystem/littlefs/lfs.c
${MIOSIX_KPATH}/filesystem/littlefs/lfs_util.c
${MIOSIX_KPATH}/filesystem/romfs/romfs.cpp
${MIOSIX_KPATH}/stdlib_integration/libc_integration.cpp
${MIOSIX_KPATH}/stdlib_integration/libstdcpp_integration.cpp
${MIOSIX_KPATH}/e20/e20.cpp
${MIOSIX_KPATH}/e20/unmember.cpp
${MIOSIX_KPATH}/util/util.cpp
${MIOSIX_KPATH}/util/unicode.cpp
${MIOSIX_KPATH}/util/version.cpp
${MIOSIX_KPATH}/util/crc16.cpp
${MIOSIX_KPATH}/util/lcd44780.cpp
)

# Include the architecture options
include(${MIOSIX_KPATH}/arch/CMakeLists.txt)

# Verify that all the required variables have been defined, otherwise abort
set(REQUIRED_VARIABLES
MIOSIX_OPT_BOARD
MIOSIX_ARCH_INC
MIOSIX_BOARD_INC
MIOSIX_BOARD_SETTINGS_INC
MIOSIX_LINKER_SCRIPT
MIOSIX_A_FLAGS
MIOSIX_C_FLAGS
MIOSIX_CXX_FLAGS
MIOSIX_L_FLAGS
MIOSIX_ARCH_SRC
)
foreach(VARIABLE ${REQUIRED_VARIABLES})
if(NOT DEFINED ${VARIABLE})
message(FATAL_ERROR "arch/CMakeLists.txt must define ${VARIABLE}")
endif()
endforeach()

# The user can set a custom path for miosix_settings.h
set(MIOSIX_SETTINGS_PATH ${MIOSIX_KPATH}/default CACHE PATH "Include directory for miosix_settings.h")
mark_as_advanced(MIOSIX_SETTINGS_PATH)
if(NOT MIOSIX_SETTINGS_PATH STREQUAL ${MIOSIX_KPATH}/default)
message(NOTICE "You have set a custom path for miosix_settings.h")
endif()

# Define the miosix library with kernel and architecture sources
add_library(miosix STATIC ${MIOSIX_KERNEL_SRC} ${MIOSIX_ARCH_SRC})

target_include_directories(miosix PUBLIC
${MIOSIX_KPATH}
${MIOSIX_KPATH}/arch/common
${MIOSIX_ARCH_INC}
${MIOSIX_BOARD_INC}
${MIOSIX_BOARD_SETTINGS_INC}
${MIOSIX_SETTINGS_PATH}
)

target_compile_options(miosix PUBLIC
$<$<COMPILE_LANGUAGE:ASM>:${MIOSIX_A_FLAGS}>
$<$<COMPILE_LANGUAGE:C>:${MIOSIX_C_FLAGS}>
$<$<COMPILE_LANGUAGE:CXX>:${MIOSIX_CXX_FLAGS}>
)

# Configure program command as a propery of the miosix library
set_property(TARGET miosix PROPERTY PROGRAM_CMDLINE ${PROGRAM_CMDLINE})

# Add COMPILING_MIOSIX define for private headers
target_compile_definitions(miosix PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:COMPILING_MIOSIX>)

# Configure linker file and options needed to link agains this library
set_property(TARGET miosix PROPERTY LINK_DEPENDS ${MIOSIX_BOARD_INC}/${MIOSIX_LINKER_SCRIPT})
target_link_options(miosix INTERFACE ${MIOSIX_L_FLAGS})

# Run the kernel_global_objects.pl script on all kernel objects
add_custom_command(
TARGET miosix PRE_LINK
COMMAND perl ${MIOSIX_KPATH}/_tools/kernel_global_objects.pl $<TARGET_OBJECTS:miosix>
VERBATIM
COMMAND_EXPAND_LISTS
)

# Optionally print the board list
option(MIOSIX_PRINT_BOARD_LIST "Prints a list of the available boards" OFF)
if(MIOSIX_PRINT_BOARD_LIST)
message(STATUS "Available boards:")
foreach(MIOSIX_OPT_BOARD ${MIOSIX_BOARDS})
message(STATUS "\t${MIOSIX_OPT_BOARD}")
endforeach()
endif()
40 changes: 40 additions & 0 deletions miosix/_examples/blinking_led/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2024 by Skyward
#
# This program is free software; you can redistribute it and/or
# it under the terms of the GNU General Public License as published
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# As a special exception, if other files instantiate templates or use
# macros or inline functions from this file, or you compile this file
# and link it with other works to produce a work based on this file,
# this file does not by itself cause the resulting work to be covered
# by the GNU General Public License. However the source code for this
# file must still be made available in accordance with the GNU
# Public License. This exception does not invalidate any other
# why a work based on this file might be covered by the GNU General
# Public License.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>

cmake_minimum_required(VERSION 3.16)

project(BlinkingLED C CXX ASM)

# Set Miosix definitions and options
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:MIOSIX_SKIP_SETTINGS_EDIT>)
set(MIOSIX_OPT_BOARD stm32f429zi_stm32f4discovery CACHE STRING "Target board")

add_subdirectory(../.. miosix EXCLUDE_FROM_ALL)

include(LinkTarget)

add_executable(blinking_led simple.cpp)
miosix_link_target(blinking_led)
miosix_add_program_target(blinking_led)
32 changes: 15 additions & 17 deletions miosix/_examples/blinking_led/simple.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#include <cstdio>
#include <unistd.h>

#include "interfaces/bsp.h"
#include "miosix.h"

using namespace std;
using namespace miosix;

typedef Gpio<GPIOC_BASE,7> led;

int main()
{

led::mode(Mode::OUTPUT);

for(;;) {
led::high();
sleep(1);
led::low();
sleep(1);
}

return 0;

}
while(true)
{
ledOn();
printf("Led on\n");
sleep(1);

ledOff();
printf("Led off\n");
sleep(1);
}

return 0;
}
58 changes: 58 additions & 0 deletions miosix/_examples/processes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (C) 2024 by Skyward
#
# This program is free software; you can redistribute it and/or
# it under the terms of the GNU General Public License as published
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# As a special exception, if other files instantiate templates or use
# macros or inline functions from this file, or you compile this file
# and link it with other works to produce a work based on this file,
# this file does not by itself cause the resulting work to be covered
# by the GNU General Public License. However the source code for this
# file must still be made available in accordance with the GNU
# Public License. This exception does not invalidate any other
# why a work based on this file might be covered by the GNU General
# Public License.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>

cmake_minimum_required(VERSION 3.16)

project(ProcessesExamples C CXX ASM)

# Set Miosix definitions and options
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:MIOSIX_SKIP_SETTINGS_EDIT>)
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:WITH_PROCESSES>)
set(MIOSIX_OPT_BOARD stm32f429zi_stm32f4discovery CACHE STRING "Target board")
set(MIOSIX_LINKER_SCRIPT stm32_2m+256k_rom_processes.ld CACHE FILEPATH "Linker script")

add_subdirectory(../.. miosix EXCLUDE_FROM_ALL)
add_subdirectory(../../libsyscalls libsyscalls EXCLUDE_FROM_ALL)

include(LinkTarget)
include(AddProcess)
include(AddRomfsImage)

# Kernel level program
add_executable(main main.cpp)
miosix_link_target(main)

# Processes
miosix_add_process(process1 process1.cpp)
miosix_add_process(process2 process2.cpp)

# RomFS image
miosix_add_romfs_image(
IMAGE_NAME image
DIR_NAME bin
KERNEL main
PROCESSES process1 process2
)
miosix_add_program_target(image DEPENDS image)
36 changes: 36 additions & 0 deletions miosix/_examples/processes/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <spawn.h>
#include <sys/wait.h>

#include <cstdio>

void start_process(pid_t* pid, char* const argv[], char* const envp[])
{
int error_code = posix_spawn(pid, argv[0], NULL, NULL, argv, envp);

if(error_code != 0)
{
printf("spawn returned %d\n", error_code);
}
}

int main()
{
pid_t pid1, pid2;

// Arguments and environment variables
const char* arg1[] = {"/bin/process1", nullptr};
const char* arg2[] = {"/bin/process2", nullptr};
const char* env[] = {nullptr};

// Start the processes
start_process(&pid1, (char* const*)arg1, (char* const*)env);
start_process(&pid2, (char* const*)arg2, (char* const*)env);

// Wait for them to end
wait(NULL);
wait(NULL);

printf("All processes ended\n");

return 0;
}
Loading