diff --git a/CMakeLists.txt b/CMakeLists.txt index bc5a2b8..b4f14dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,8 @@ set(DRIVERS_HEADERS_DIR) #Declared empty because it will be filled automaticaly # Directory fot the peripherals -> "Common to all CSL" set(PERIPHERALS_DIR ${CMAKE_SOURCE_DIR}/peripherals) -set(PERIPHERALS_HEADERS_DIR ${CMAKE_SOURCE_DIR}/peripherals) +set(PERIPHERALS_HEADERS_DIR)#Declared empty because it will be filled automaticaly afterwards +set(PERIPHERAL_LIBS)#Declared empty because it will be filled automaticaly afterwards # Directory for the libraries -> "Common to all CSL" set(LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/libraries) @@ -63,8 +64,7 @@ set(LIBRARIES_HEADERS_DIR ${CMAKE_SOURCE_DIR}/libraries) #################################################################################################### -# INCLUDES -#################################################################################################### +# INCLUDES #################################################################################################### # Adding human readable color references for cmake include(${CMAKE_CORE_DIR}/colors.cmake) @@ -96,12 +96,12 @@ include(${CSL_CONFIG_FILE}) #################################################################################################### message("${BoldBlue}") message("+-------------------------------+") -message("Cheking Driver Headers") +message("Adding Header Directories") message("+-------------------------------+") -foreach(X IN LISTS DRIVERS_LIST) - addHeaderDir("${DRIVERS_DIR}" "${X}" "NEW_DRIVER_HEADER") - list(APPEND DRIVERS_HEADERS_DIR ${NEW_DRIVER_HEADER}) -endforeach() +message("-->For Drivers") +createHeaderDirList("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVERS_HEADERS_DIR") +message("-->For Peripherals") +createHeaderDirList("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERALS_HEADERS_DIR") message("+-------------------------------+") set (COMMON_HEADERS ${CSL_HEADERS_DIR} @@ -130,10 +130,7 @@ message("+-------------------------------+") message("Cheking Periferals") message("+-------------------------------+") -foreach(X IN LISTS PERIPHERALS_LIST) - addPeripheral("${X}" "NEW_PERIPHERAL") - list(APPEND PERIPHERAL_LIBS ${NEW_PERIPHERAL}) -endforeach() +makeSubmodules("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERAL_LIBS") message("+-------------------------------+") message("${ColourReset}") @@ -146,9 +143,9 @@ message("+-------------------------------+") message("Cheking User's Project") message("+-------------------------------+") message("Included Project Headers :") -checkDirectory("${PROJECT_HEADERS_DIR}") +checkDirectories("${PROJECT_HEADERS_DIR}") message("Included Project Sources :") -checkDirectory("${PROJECT_SOURCES_DIR}") +checkDirectories("${PROJECT_SOURCES_DIR}") message("Declared sources :") printList("|-->" "${PROJECT_SOURCES_DIR_LIST}") diff --git a/env/cmake_core/cmakeCore.cmake b/env/cmake_core/cmakeCore.cmake index e878634..f14eaf9 100755 --- a/env/cmake_core/cmakeCore.cmake +++ b/env/cmake_core/cmakeCore.cmake @@ -3,8 +3,8 @@ # Project function for cheking header files source files and generating libraries from them. #################################################################################################### #Searching if the given header and/or sources directory exists if not we brake the compilation -function(checkDirectory _directory) - foreach(DIR IN LISTS _directory) +function(checkDirectories _directoryList) + foreach(DIR IN LISTS _directoryList) if(EXISTS ${DIR}) message("|--> ${DIR} : INCLUDED") else() @@ -13,40 +13,22 @@ function(checkDirectory _directory) endforeach() endfunction() -# This function goes an searches for directories containing header files and return the corresponding directory. -function(addHeaderDir _directory _alias _currentDriverHeader) - if(EXISTS ${_directory}/${_alias} ) # Checks if the given directory exitsts - if(EXISTS ${_directory}/${_alias}/${_alias}.h) - message(" --> Header File : ${_directory}/${_alias}/${_alias}.h = FOUND") - message(" |-> Driver directory : ${_directory}/${_alias} = ADDED TO HEADERS") - set(${_currentDriverHeader} ${_directory}/${_alias} PARENT_SCOPE) - - else () - errorHFileNotFound("${_directory}" "${_alias}") - endif() - else () - errorHDirNotFound("${_directory}" "${_alias}") +function(checkDirectory _directory) + if(EXISTS ${_directory}) + else() + errorDirNotFound() endif() endfunction() -#Searching each sources directory to find the desired source file and generate a libaray submodule for the linker -function(projectAddItem alias _currentItem) - foreach(DIR IN LISTS PROJECT_SOURCES_DIR) - if(EXISTS ${DIR}) - if(EXISTS ${DIR}/${alias}.${PL}) #For each directory we chanek if the given source file exitst - message("|-->${alias}.${PL} FOUND in : ${DIR}") - message(" |-> Creating sub::${alias}.${PL} library submodule") - add_library(${alias}_submodule ${DIR}/${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(${_currentItem} sub::${alias} PARENT_SCOPE) - endif() - else() - message(FATAL_ERROR "Source directory <<${DIR}>> : NOT FOUND") - endif() +# 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") endforeach() + set(${_headersList} ${_newheaderDirList} PARENT_SCOPE) endfunction() #################################################################################################### @@ -120,3 +102,40 @@ function(printList _txt _list) 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}") + if(EXISTS ${_directory}/${alias}/${alias}.${PL}) + message(" |->Submodule Source File : ${alias}.c : FOUND") + message(" |-> DIR: ${_directory}/${alias}/${alias}.${PL}") + add_library(${alias}_submodule ${_directory}/${alias}/${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) + 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}") + add_library(${alias}_submodule ${_directory}/${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) + list(APPEND _newSubmoduleList sub::${alias}) + else() + message(" |->No Source File Found : Only headers will be added") + endif() + endif() + endforeach() + printList("_newSubmoduleList = " ${_newSubmoduleList}) + set(${_submoduleList} ${_newSubmoduleList} PARENT_SCOPE) +endfunction() diff --git a/peripherals/delay.h b/peripherals/delay/delay.h similarity index 100% rename from peripherals/delay.h rename to peripherals/delay/delay.h diff --git a/peripherals/deviceSetup.h b/peripherals/deviceSetup/deviceSetup.h similarity index 100% rename from peripherals/deviceSetup.h rename to peripherals/deviceSetup/deviceSetup.h diff --git a/peripherals/i2c.c b/peripherals/i2c/i2c.c similarity index 100% rename from peripherals/i2c.c rename to peripherals/i2c/i2c.c diff --git a/peripherals/i2c.h b/peripherals/i2c/i2c.h similarity index 100% rename from peripherals/i2c.h rename to peripherals/i2c/i2c.h diff --git a/peripherals/interrupt.c b/peripherals/interrupt/interrupt.c similarity index 100% rename from peripherals/interrupt.c rename to peripherals/interrupt/interrupt.c diff --git a/peripherals/interrupt.h b/peripherals/interrupt/interrupt.h similarity index 100% rename from peripherals/interrupt.h rename to peripherals/interrupt/interrupt.h diff --git a/peripherals/pin.h b/peripherals/pin/pin.h similarity index 100% rename from peripherals/pin.h rename to peripherals/pin/pin.h diff --git a/peripherals/spi.c b/peripherals/spi/spi.c similarity index 100% rename from peripherals/spi.c rename to peripherals/spi/spi.c diff --git a/peripherals/spi.h b/peripherals/spi/spi.h similarity index 100% rename from peripherals/spi.h rename to peripherals/spi/spi.h diff --git a/peripherals/timer.h b/peripherals/timer/timer.h similarity index 100% rename from peripherals/timer.h rename to peripherals/timer/timer.h diff --git a/peripherals/usart.h b/peripherals/usart/usart.h similarity index 100% rename from peripherals/usart.h rename to peripherals/usart/usart.h