#################################################################################################### # CMAKE Colors #################################################################################################### if(NOT WIN32) string(ASCII 27 Esc) set(ColourReset "${Esc}[m") set(ColourBold "${Esc}[1m") set(Red "${Esc}[31m") set(Green "${Esc}[32m") set(Yellow "${Esc}[33m") set(Blue "${Esc}[34m") set(Magenta "${Esc}[35m") set(Cyan "${Esc}[36m") set(White "${Esc}[37m") set(BoldRed "${Esc}[1;31m") set(BoldGreen "${Esc}[1;32m") set(BoldYellow "${Esc}[1;33m") set(BoldBlue "${Esc}[1;34m") set(BoldMagenta "${Esc}[1;35m") set(BoldCyan "${Esc}[1;36m") set(BoldWhite "${Esc}[1;37m") endif() #################################################################################################### # Project function for cheking header files source files and generating libraries from them. #################################################################################################### #Searching if the given header directory exists if not we brake the compilation function(projectHeadersCheck) foreach(DIR IN LISTS PROJECT_HEADERS_DIR) if(EXISTS ${DIR}) message("|--> ${DIR} : INCLUDED") else() errorHeaderDirNotFound() endif() endforeach() endfunction() #Searching if the given Source exists if not we brake the compilation function(projectCheckSourcesCheck) foreach(DIR IN LISTS PROJECT_SOURCES_DIR) if(EXISTS ${DIR}) message("|--> ${DIR} : INCLUDED") else() errorSourceDirNotFound() endif() endforeach() 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 ${C_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${C_DEFS}) target_include_directories(${alias}_submodule PUBLIC ${PROJECT_HEADERS_DIR} ${PERIFERALS_DIR} ${CSL_INCLUDES}) 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}/imp_${alias}.${PL}) # Checks if the desired peripheral is implemented for the desired CSL. message(" --> Peripheral: ${alias} = FOUND") message(" |-> Drirectory: ${CSL_SOURCES}/imp_${alias}.${PL}") if(EXISTS ${PERIFERALS_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: ${PERIFERALS_DIR}/${alias}.${PL}") add_library(${alias}_submodule ${PERIFERALS_DIR}/${alias}.${PL} ${CSL_SOURCES}/imp_${alias}.${PL}) else() add_library(${alias}_submodule ${CSL_SOURCES}/imp_${alias}.${PL}) endif() target_compile_options(${alias}_submodule PRIVATE ${C_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${C_DEFS}) target_include_directories(${alias}_submodule PUBLIC ${PERIFERALS_DIR} ${CSL_INCLUDES} ${DRIVER_HEADERS_LIST}) 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 ${C_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${C_DEFS}) target_include_directories(${alias}_submodule PUBLIC ${PERIFERALS_DIR} ${CSL_INCLUDES} ${DRIVER_HEADERS_LIST}) 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() function(addDriverHeader alias _currentDriverHeader) 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") set(${_currentDriverHeader} ${DRIVERS_DIR}/${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()