Cmake's main functionalities are fully implmeneted now the error handler should be optimized

master
kerem yollu 2 years ago
parent c893a9584e
commit 36be0a0f9e

@ -60,8 +60,13 @@ set(PERIPHERAL_LIBS)#Declared empty because it will be filled automaticaly after
# Directory for the libraries -> "Common to all CSL" # Directory for the libraries -> "Common to all CSL"
set(LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/libraries) 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 #################################################################################################### # INCLUDES ####################################################################################################
@ -80,9 +85,15 @@ include(${PROJECT_CONFIG_FILE})
# Here is the include fopr the awailable peripheral headers and standart libraries. # Here is the include fopr the awailable peripheral headers and standart libraries.
include(${PERIPHERALS_DIR}/CMakeLists.txt) 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) 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 the config fiel where the compilers to use ar defined
include(${COMPILER_DEFS}) include(${COMPILER_DEFS})
@ -91,77 +102,56 @@ include(${COMPILER_DEFS})
include(${CSL_CONFIG_FILE}) 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 # all the modules
#################################################################################################### ####################################################################################################
message("${BoldBlue}") message("${BoldBlue}")
message("+-------------------------------+") message("+-------------------------------+")
message("Adding Header Directories") message("Adding Header Directories")
message("+-------------------------------+") message("+-------------------------------+")
message("-->For Drivers") message("|-->For Drivers")
createHeaderDirList("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVERS_HEADERS_DIR") createHeaderDirList("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVERS_HEADERS_DIR")
message("-->For Peripherals") message("${BoldBlue}|-->For Peripherals")
createHeaderDirList("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERALS_HEADERS_DIR") 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} set (COMMON_HEADERS ${CSL_HEADERS_DIR}
${PERIPHERALS_HEADERS_DIR} ${PERIPHERALS_HEADERS_DIR}
${DRIVERS_HEADERS_DIR} ${DRIVERS_HEADERS_DIR}
${LIBRARIES_HEADERS_DIR} ${LIBRARIES_HEADERS_DIR}
${PROJECT_HEADERS_DIR}) ${PROJECT_HEADERS_DIR}
${SYSTEM_HEADERS_DIR})
#################################################################################################### ####################################################################################################
# Driver definitions # Making Modules
#################################################################################################### ####################################################################################################
message("Cheking Drivers ") message("${BoldBlue}")
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("+-------------------------------+") message("+-------------------------------+")
message("Cheking Periferals") message("Making Submolues")
message("+-------------------------------+") message("+-------------------------------+")
message("|-->For Drivers")
makeSubmodules("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVER_LIBS")
message("${BoldBlue}|-->For Peripherals")
makeSubmodules("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERAL_LIBS") 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. # 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}) list(APPEND GENERATED_LIBRARIES ${X})
endforeach() endforeach()
@ -206,7 +196,7 @@ message("${ColourReset}")
#################################################################################################### ####################################################################################################
# EXECUTABLE # EXECUTABLE
#################################################################################################### ####################################################################################################
add_executable(${EXECUTABLE} ${PROJECT_DIR}/main.c) add_executable(${EXECUTABLE} ${PROJECT_DIR}/main.${PL})
target_compile_options(${EXECUTABLE} PRIVATE ${MAIN_FLAGS}) target_compile_options(${EXECUTABLE} PRIVATE ${MAIN_FLAGS})
target_compile_definitions(${EXECUTABLE} PRIVATE ${MAIN_DEFS}) target_compile_definitions(${EXECUTABLE} PRIVATE ${MAIN_DEFS})
target_include_directories(${EXECUTABLE} PUBLIC ${COMMON_HEADERS}) target_include_directories(${EXECUTABLE} PUBLIC ${COMMON_HEADERS})

@ -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 #Searching if the given header and/or sources directory exists if not we brake the compilation
function(checkDirectories _directoryList) function(checkDirectories _directoryList)
foreach(DIR IN LISTS _directoryList) foreach(DIR IN LISTS _directoryList)
if(EXISTS ${DIR}) if(EXISTS ${DIR})
message("|--> ${DIR} : INCLUDED") message("${BoldMagenta} |-> Added : ${DIR}")
else() else()
errorDirNotFound() errorDirNotFound()
endif() endif()
endforeach() endforeach()
message("${ColourReset}")
endfunction() endfunction()
function(checkDirectory _directory) function(checkDirectory _directory)
@ -20,102 +20,39 @@ function(checkDirectory _directory)
endif() endif()
endfunction() endfunction()
####################################################################################################
# HEADER MANAGEMENT
####################################################################################################
# This function goes an searches for directories containing header files and return the corresponding directory. # This function goes an searches for directories containing header files and return the corresponding directory.
function(createHeaderDirList _directory _list _headersList) function(createHeaderDirList _directory _list _headersList)
set(_newheaderDirList) set(_newheaderDirList)
foreach(DIR IN LISTS _list) foreach(DIR IN LISTS _list)
checkDirectory("${_directory}/${DIR}") checkDirectory("${_directory}/${DIR}")
list(APPEND _newheaderDirList ${_directory}/${DIR}) list(APPEND _newheaderDirList ${_directory}/${DIR})
message(" |-> Header Directory : ${_directory}/${DIR} = ADDED") message("${BoldMagenta} |-> Added : ${_directory}/${DIR}")
endforeach() endforeach()
message("${ColourReset}")
set(${_headersList} ${_newheaderDirList} PARENT_SCOPE) set(${_headersList} ${_newheaderDirList} PARENT_SCOPE)
endfunction() endfunction()
#################################################################################################### ####################################################################################################
# Peripheral function for generating libraries from them. # SUBMODULE MANAGEMENT
####################################################################################################
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()
#################################################################################################### ####################################################################################################
# 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) function(makeSubmodules _directory _aliasList _submoduleList)
set(_newSubmoduleList) set(_newSubmoduleList)
foreach(alias IN LISTS _aliasList) foreach(alias IN LISTS _aliasList)
checkDirectory("${_directory}/${alias}") checkDirectory("${_directory}/${alias}")
if(EXISTS ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) if(EXISTS ${CSL_SOURCES_DIR}/imp_${alias}.${PL})
message(" |->Submodule CSL Implementation for : ${alias} : FOUND") message("${BoldYellow} |-> Target Found : ${alias} ")
message(" |-> DIR: ${CSL_SOURCES_DIR}/imp_${alias}.${PL}")
if(EXISTS ${_directory}/${alias}/${alias}.${PL}) if(EXISTS ${_directory}/${alias}/${alias}.${PL})
message(" |->Submodule Source File : ${alias}.c : FOUND") message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}")
message(" |-> DIR: ${_directory}/${alias}/${alias}.${PL}") message(" |-> Lib Source : ${_directory}/${alias}/${alias}.${PL} ")
add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL} ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL} ${CSL_SOURCES_DIR}/imp_${alias}.${PL})
else() else()
message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}")
add_library(${alias}_submodule ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) add_library(${alias}_submodule ${CSL_SOURCES_DIR}/imp_${alias}.${PL})
endif() endif()
message(" |-> Name : sub::${alias}")
target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS})
target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS})
target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS})
@ -123,8 +60,9 @@ function(makeSubmodules _directory _aliasList _submoduleList)
list(APPEND _newSubmoduleList sub::${alias}) list(APPEND _newSubmoduleList sub::${alias})
else() else()
if(EXISTS ${_directory}/${alias}/${alias}.${PL}) if(EXISTS ${_directory}/${alias}/${alias}.${PL})
message(" |->Submodule Source File : ${alias}.c : FOUND") message("${BoldYellow} |-> Target Found : ${alias} ")
message(" |-> DIR: ${_directory}/${alias}/${alias}.${PL}") message(" |-> Source : ${_directory}/${alias}/${alias}.${PL}")
message(" |-> Name : sub::${alias}")
add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL}) add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL})
target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS})
target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS})
@ -132,10 +70,21 @@ function(makeSubmodules _directory _aliasList _submoduleList)
add_library(sub::${alias} ALIAS ${alias}_submodule) add_library(sub::${alias} ALIAS ${alias}_submodule)
list(APPEND _newSubmoduleList sub::${alias}) list(APPEND _newSubmoduleList sub::${alias})
else() 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()
endif() endif()
endforeach() endforeach()
printList("_newSubmoduleList = " ${_newSubmoduleList}) message("${ColourReset}")
set(${_submoduleList} ${_newSubmoduleList} PARENT_SCOPE) set(${_submoduleList} ${_newSubmoduleList} PARENT_SCOPE)
endfunction() endfunction()
####################################################################################################
# PRINT FUNCTIONS
####################################################################################################
function(printList _txt _list)
foreach(X IN LISTS _list)
message("${_txt}${X}")
endforeach()
endfunction()

@ -1 +1 @@
set(LIBRARIES_LIST) set(LIBRARIES_LIST uart font)

@ -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)

@ -0,0 +1,2 @@
set(SYSTEM_LIST interrupt)
Loading…
Cancel
Save