#################################################################################################### # 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) if(EXISTS ${DIR}) message("|--> ${DIR} : INCLUDED") else() errorDirNotFound() endif() 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}") 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() endforeach() 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() #################################################################################################### # 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()