From 36be0a0f9ea64c574b012dcf82e28afa5331c4d8 Mon Sep 17 00:00:00 2001 From: kerem yollu Date: Mon, 6 Mar 2023 16:42:20 +0100 Subject: [PATCH] Cmake's main functionalities are fully implmeneted now the error handler should be optimized --- CMakeLists.txt | 90 +++++++------- env/cmake_core/cmakeCore.cmake | 111 +++++------------- libraries/CMakeLists.txt | 2 +- libraries/{ => font}/oled_fonts.h | 0 libraries/{ => uart}/ascii.h | 0 peripherals/CMakeLists.txt | 2 +- system/CMakeLists.txt | 2 + system/bus.c | 0 system/bus.h | 0 system/dma.c | 0 system/dma.h | 0 system/interrupt.c | 0 system/interrupt.h | 0 {peripherals => system}/interrupt/interrupt.c | 0 {peripherals => system}/interrupt/interrupt.h | 0 system/ked.c | 0 system/ked.h | 0 17 files changed, 74 insertions(+), 133 deletions(-) rename libraries/{ => font}/oled_fonts.h (100%) rename libraries/{ => uart}/ascii.h (100%) create mode 100644 system/CMakeLists.txt delete mode 100644 system/bus.c delete mode 100644 system/bus.h delete mode 100644 system/dma.c delete mode 100644 system/dma.h delete mode 100644 system/interrupt.c delete mode 100644 system/interrupt.h rename {peripherals => system}/interrupt/interrupt.c (100%) rename {peripherals => system}/interrupt/interrupt.h (100%) delete mode 100644 system/ked.c delete mode 100644 system/ked.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b4f14dc..a7cd95e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,8 +60,13 @@ set(PERIPHERAL_LIBS)#Declared empty because it will be filled automaticaly after # Directory for the libraries -> "Common to all CSL" set(LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/libraries) -set(LIBRARIES_HEADERS_DIR ${CMAKE_SOURCE_DIR}/libraries) +set(LIBRARIES_HEADERS_DIR)#Declared empty because it will be filled automaticaly afterwards +set(LIBRARIES_LIBS)#Declared empty because it will be filled automaticaly afterwards +# Directory for the SYSTEM -> "Common to all CSL" +set(SYSTEM_DIR ${CMAKE_SOURCE_DIR}/system) +set(SYSTEM_HEADERS_DIR)#Declared empty because it will be filled automaticaly afterwards +set(SYSTEM_LIBS)#Declared empty because it will be filled automaticaly afterwards #################################################################################################### # INCLUDES #################################################################################################### @@ -80,9 +85,15 @@ include(${PROJECT_CONFIG_FILE}) # Here is the include fopr the awailable peripheral headers and standart libraries. include(${PERIPHERALS_DIR}/CMakeLists.txt) -# Here is the include fopr the awailable peripheral headers and standart libraries. +# Here is the include fopr the awailable drivers headers and standart libraries. include(${DRIVERS_DIR}/CMakeLists.txt) +# Here is the include fopr the awailable libraries headers and standart libraries. +include(${LIBRARIES_DIR}/CMakeLists.txt) + +# Here is the include fopr the awailable system headers and standart libraries. +include(${SYSTEM_DIR}/CMakeLists.txt) + # Include the config fiel where the compilers to use ar defined include(${COMPILER_DEFS}) @@ -91,77 +102,56 @@ include(${COMPILER_DEFS}) include(${CSL_CONFIG_FILE}) #################################################################################################### -# HEADERS : ALL Header Definitions and calls MSUT be made here to be able to propagate them through +# HEADERS : ALL Header Definitions and calls MUST be made here to be able to propagate them through # all the modules #################################################################################################### message("${BoldBlue}") message("+-------------------------------+") message("Adding Header Directories") message("+-------------------------------+") -message("-->For Drivers") +message("|-->For Drivers") createHeaderDirList("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVERS_HEADERS_DIR") -message("-->For Peripherals") +message("${BoldBlue}|-->For Peripherals") createHeaderDirList("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERALS_HEADERS_DIR") -message("+-------------------------------+") +message("${BoldBlue}|-->For Libraries") +createHeaderDirList("${LIBRARIES_DIR}" "${LIBRARIES_LIST}" "LIBRARIES_HEADERS_DIR") +message("${BoldBlue}|-->For Project") +checkDirectories("${PROJECT_HEADERS_DIR}") +message("${BoldBlue}|-->For System") +createHeaderDirList("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_HEADERS_DIR") +message("${BoldBlue}+-------------------------------+${ColourReset}") set (COMMON_HEADERS ${CSL_HEADERS_DIR} ${PERIPHERALS_HEADERS_DIR} ${DRIVERS_HEADERS_DIR} ${LIBRARIES_HEADERS_DIR} - ${PROJECT_HEADERS_DIR}) + ${PROJECT_HEADERS_DIR} + ${SYSTEM_HEADERS_DIR}) #################################################################################################### -# Driver definitions +# Making Modules #################################################################################################### -message("Cheking Drivers ") -message("+-------------------------------+") -foreach(X IN LISTS DRIVERS_LIST) - addDriver("${X}" "NEW_DRIVER") - list(APPEND DRIVER_LIBS ${NEW_DRIVER}) -endforeach() -message("+-------------------------------+") -message("${ColourReset}") - -#################################################################################################### -# Peripehral definitions -#################################################################################################### -message("${BoldYellow}") +message("${BoldBlue}") message("+-------------------------------+") -message("Cheking Periferals") +message("Making Submolues") message("+-------------------------------+") - +message("|-->For Drivers") +makeSubmodules("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVER_LIBS") +message("${BoldBlue}|-->For Peripherals") makeSubmodules("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERAL_LIBS") +message("${BoldBlue}|-->For Libraries") +makeSubmodules("${LIBRARIES_DIR}" "${LIBRARIES_LIST}" "LIBRARIES_LIBS") +message("${BoldBlue}|-->For Project") +makeSubmodules("${PROJECT_DIR}" "${PROJECT_SOURCES_DIR_LIST}" "PROJECT_LIBS") +message("${BoldBlue}|-->For System") +makeSubmodules("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_LIBS") +message("${BoldBlue}+-------------------------------+${ColourReset}") -message("+-------------------------------+") -message("${ColourReset}") - -#################################################################################################### -# User's project definitions -#################################################################################################### -message("${BoldMagenta}") -message("+-------------------------------+") -message("Cheking User's Project") -message("+-------------------------------+") -message("Included Project Headers :") -checkDirectories("${PROJECT_HEADERS_DIR}") -message("Included Project Sources :") -checkDirectories("${PROJECT_SOURCES_DIR}") -message("Declared sources :") -printList("|-->" "${PROJECT_SOURCES_DIR_LIST}") - -message("Creating Libraries for declared sources :") -foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) - projectAddItem("${X}" "NEW_PROJECT_ITEM") - list(APPEND PROJECT_LIBS ${NEW_PROJECT_ITEM}) -endforeach() - -message("+-------------------------------+") -message("${ColourReset}") #################################################################################################### # Stick All the libraries together, only for code redability futher down. #################################################################################################### -foreach(X IN LISTS STARTUP_UCODE PROJECT_LIBS PERIPHERAL_LIBS DRIVER_LIBS) +foreach(X IN LISTS STARTUP_UCODE PROJECT_LIBS PERIPHERAL_LIBS DRIVER_LIBS LIBRARIES_LIBS SYSTEM_LIBS) list(APPEND GENERATED_LIBRARIES ${X}) endforeach() @@ -206,7 +196,7 @@ message("${ColourReset}") #################################################################################################### # EXECUTABLE #################################################################################################### -add_executable(${EXECUTABLE} ${PROJECT_DIR}/main.c) +add_executable(${EXECUTABLE} ${PROJECT_DIR}/main.${PL}) target_compile_options(${EXECUTABLE} PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${EXECUTABLE} PRIVATE ${MAIN_DEFS}) target_include_directories(${EXECUTABLE} PUBLIC ${COMMON_HEADERS}) diff --git a/env/cmake_core/cmakeCore.cmake b/env/cmake_core/cmakeCore.cmake index f14eaf9..7509b6f 100755 --- a/env/cmake_core/cmakeCore.cmake +++ b/env/cmake_core/cmakeCore.cmake @@ -1,16 +1,16 @@ - #################################################################################################### -# Project function for cheking header files source files and generating libraries from them. +# DIRECTORY CHECKS #################################################################################################### #Searching if the given header and/or sources directory exists if not we brake the compilation function(checkDirectories _directoryList) foreach(DIR IN LISTS _directoryList) if(EXISTS ${DIR}) - message("|--> ${DIR} : INCLUDED") + message("${BoldMagenta} |-> Added : ${DIR}") else() errorDirNotFound() endif() endforeach() + message("${ColourReset}") endfunction() function(checkDirectory _directory) @@ -20,102 +20,39 @@ function(checkDirectory _directory) endif() endfunction() +#################################################################################################### +# HEADER MANAGEMENT +#################################################################################################### # This function goes an searches for directories containing header files and return the corresponding directory. function(createHeaderDirList _directory _list _headersList) set(_newheaderDirList) foreach(DIR IN LISTS _list) checkDirectory("${_directory}/${DIR}") list(APPEND _newheaderDirList ${_directory}/${DIR}) - message(" |-> Header Directory : ${_directory}/${DIR} = ADDED") + message("${BoldMagenta} |-> Added : ${_directory}/${DIR}") endforeach() + message("${ColourReset}") set(${_headersList} ${_newheaderDirList} PARENT_SCOPE) endfunction() #################################################################################################### -# Peripheral function for generating libraries from them. -#################################################################################################### -function(addPeripheral alias _currentPripheral) - if(EXISTS ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) # Checks if the desired peripheral is implemented for the desired CSL. - message(" --> Peripheral: ${alias} = FOUND") - message(" |-> Drirectory: ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") - if(EXISTS ${PERIPHERALS_HEADERS_DIR}/${alias}.${PL}) # Cheks if generic funtions are awailable. this is useful for standars as SPI i2c etc... - message(" --> Generic Library ${alias}.${PL} for imp_${alias}.${PL} = FOUND") - message(" |-> DIRECTORY: ${PERIPHERALS_HEADERS_DIR}/${alias}.${PL}") - add_library(${alias}_submodule ${PERIPHERALS_HEADERS_DIR}/${alias}.${PL} ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) - else() - add_library(${alias}_submodule ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) - endif() - - target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) - target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) - target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) - add_library(sub::${alias} ALIAS ${alias}_submodule) - set(${_currentPripheral} sub::${alias} PARENT_SCOPE) - - else () - message("${BoldRed}") - message(FATAL_ERROR "\nThe Included <<${alias}>> peripheral was NOT found ### COMPILATION ABORTED ###\n") - message("${ColourReset}") - endif() -endfunction() - +# SUBMODULE MANAGEMENT #################################################################################################### -# Driver function for generating libraries from them. -#################################################################################################### -function(addDriver alias _currentDriver) - if(EXISTS ${DRIVERS_DIR}/${alias} ) # Checks if the desired peripheral is implemented for the desired CSL. - message(" --> Driver directory : ${DRIVERS_DIR}/${alias} = FOUND") - if(EXISTS ${DRIVERS_DIR}/${alias}/${alias}.${PL}) - message(" |-> Source File : ${DRIVERS_DIR}/${alias}/${alias}.${PL} = FOUND") - if(EXISTS ${DRIVERS_DIR}/${alias}/${alias}.h) - message(" |-> Header File : ${DRIVERS_DIR}/${alias}/${alias}.h = FOUND") - add_library(${alias}_submodule ${DRIVERS_DIR}/${alias}/${alias}.${PL}) - target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) - target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) - target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) - add_library(sub::${alias} ALIAS ${alias}_submodule) - set(${_currentDriver} sub::${alias} PARENT_SCOPE) - else () - message("${BoldRed}") - message(FATAL_ERROR "\nThe Included <<${alias}>> Driver's Header file was NOT found ### COMPILATION ABORTED ###\n") - message("${ColourReset}") - endif() - else () - message("${BoldRed}") - message(FATAL_ERROR "\nThe Included <<${alias}>> Driver's Source file was NOT found ### COMPILATION ABORTED ###\n") - message("${ColourReset}") - endif() - else () - message("${BoldRed}") - message(FATAL_ERROR "\nThe Included <<${alias}>> Driver was NOT found ### COMPILATION ABORTED ###\n") - message("${ColourReset}") - endif() -endfunction() - - -#################################################################################################### -# PRINT FUNCTIONS -#################################################################################################### -function(printList _txt _list) - foreach(X IN LISTS _list) - message("${_txt}${X}") - endforeach() -endfunction() - function(makeSubmodules _directory _aliasList _submoduleList) set(_newSubmoduleList) foreach(alias IN LISTS _aliasList) checkDirectory("${_directory}/${alias}") if(EXISTS ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) - message(" |->Submodule CSL Implementation for : ${alias} : FOUND") - message(" |-> DIR: ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") + message("${BoldYellow} |-> Target Found : ${alias} ") if(EXISTS ${_directory}/${alias}/${alias}.${PL}) - message(" |->Submodule Source File : ${alias}.c : FOUND") - message(" |-> DIR: ${_directory}/${alias}/${alias}.${PL}") + message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") + message(" |-> Lib Source : ${_directory}/${alias}/${alias}.${PL} ") add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL} ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) else() + message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") add_library(${alias}_submodule ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) endif() + message(" |-> Name : sub::${alias}") target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) @@ -123,8 +60,9 @@ function(makeSubmodules _directory _aliasList _submoduleList) list(APPEND _newSubmoduleList sub::${alias}) else() if(EXISTS ${_directory}/${alias}/${alias}.${PL}) - message(" |->Submodule Source File : ${alias}.c : FOUND") - message(" |-> DIR: ${_directory}/${alias}/${alias}.${PL}") + message("${BoldYellow} |-> Target Found : ${alias} ") + message(" |-> Source : ${_directory}/${alias}/${alias}.${PL}") + message(" |-> Name : sub::${alias}") add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL}) target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) @@ -132,10 +70,21 @@ function(makeSubmodules _directory _aliasList _submoduleList) add_library(sub::${alias} ALIAS ${alias}_submodule) list(APPEND _newSubmoduleList sub::${alias}) else() - message(" |->No Source File Found : Only headers will be added") + message("${BoldMagenta} |-> No Source file for target : ${alias}") + message(" |-> Only headers will be added") endif() endif() endforeach() - printList("_newSubmoduleList = " ${_newSubmoduleList}) + message("${ColourReset}") set(${_submoduleList} ${_newSubmoduleList} PARENT_SCOPE) endfunction() + +#################################################################################################### +# PRINT FUNCTIONS +#################################################################################################### +function(printList _txt _list) + foreach(X IN LISTS _list) + message("${_txt}${X}") + endforeach() +endfunction() + diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 0228e68..02d697c 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -1 +1 @@ -set(LIBRARIES_LIST) +set(LIBRARIES_LIST uart font) diff --git a/libraries/oled_fonts.h b/libraries/font/oled_fonts.h similarity index 100% rename from libraries/oled_fonts.h rename to libraries/font/oled_fonts.h diff --git a/libraries/ascii.h b/libraries/uart/ascii.h similarity index 100% rename from libraries/ascii.h rename to libraries/uart/ascii.h diff --git a/peripherals/CMakeLists.txt b/peripherals/CMakeLists.txt index 286b946..7fa5500 100644 --- a/peripherals/CMakeLists.txt +++ b/peripherals/CMakeLists.txt @@ -1,2 +1,2 @@ -set(PERIPHERALS_LIST deviceSetup delay usart timer spi i2c pin interrupt) +set(PERIPHERALS_LIST deviceSetup delay usart timer spi i2c pin) diff --git a/system/CMakeLists.txt b/system/CMakeLists.txt new file mode 100644 index 0000000..014b64d --- /dev/null +++ b/system/CMakeLists.txt @@ -0,0 +1,2 @@ +set(SYSTEM_LIST interrupt) + diff --git a/system/bus.c b/system/bus.c deleted file mode 100644 index e69de29..0000000 diff --git a/system/bus.h b/system/bus.h deleted file mode 100644 index e69de29..0000000 diff --git a/system/dma.c b/system/dma.c deleted file mode 100644 index e69de29..0000000 diff --git a/system/dma.h b/system/dma.h deleted file mode 100644 index e69de29..0000000 diff --git a/system/interrupt.c b/system/interrupt.c deleted file mode 100644 index e69de29..0000000 diff --git a/system/interrupt.h b/system/interrupt.h deleted file mode 100644 index e69de29..0000000 diff --git a/peripherals/interrupt/interrupt.c b/system/interrupt/interrupt.c similarity index 100% rename from peripherals/interrupt/interrupt.c rename to system/interrupt/interrupt.c diff --git a/peripherals/interrupt/interrupt.h b/system/interrupt/interrupt.h similarity index 100% rename from peripherals/interrupt/interrupt.h rename to system/interrupt/interrupt.h diff --git a/system/ked.c b/system/ked.c deleted file mode 100644 index e69de29..0000000 diff --git a/system/ked.h b/system/ked.h deleted file mode 100644 index e69de29..0000000