You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
6.7 KiB
144 lines
6.7 KiB
####################################################################################################
|
|
# 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 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()
|
|
errorHeaderDirNotFound()
|
|
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 ${MAIN_FLAGS})
|
|
target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS})
|
|
target_include_directories(${alias}_submodule PUBLIC ${PROJECT_HEADERS_DIR} ${PERIPHERALS_HEADERS_DIR} ${CSL_HEADERS_DIR})
|
|
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 ${PERIPHERALS_HEADERS_DIR} ${CSL_HEADERS_DIR} ${DRIVERS_HEADERS_DIR})
|
|
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 ${PERIPHERALS_HEADERS_DIR} ${CSL_HEADERS_DIR} ${DRIVERS_HEADERS_DIR})
|
|
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()
|