From 00a6e0c8e77538fc88fc1ba312792e0b680430fb Mon Sep 17 00:00:00 2001 From: kerem Date: Sat, 21 Jan 2023 16:51:41 +0100 Subject: [PATCH] Automated the driver library creation and inclusion process for the main Cmake --- CMakeLists.txt | 5 +++-- drivers/CMakeLists.txt | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c1ab98..d1bd545 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ message("${ColourReset}") #################################################################################################### #Driver definitions #################################################################################################### -set(DRIVERS_LIST max7219) +set(DRIVERS_LIST max7219 max31865) message("${BoldYellow}") message("+-------------------------------+") @@ -94,7 +94,8 @@ message("Cheking Drivers") message("+-------------------------------+") foreach(X IN LISTS DRIVERS_LIST) - list(APPEND DRIVER_LIBS sub::${X}) + addDriver("${X}" "NEW_DRIVER") + list(APPEND DRIVER_LIBS ${NEW_DRIVER}) endforeach() message("+-------------------------------+") diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 3dd9142..21dda28 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -1,2 +1,36 @@ -add_subdirectory(max7219) add_subdirectory(max31865) + +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}.c) + message(" |-> Source File : ${DRIVERS_DIR}/${alias}/${alias}.c = FOUND") + if(EXISTS ${DRIVERS_DIR}/${alias}/${alias}.h) + + message(" |-> Header File : ${DRIVERS_DIR}/${alias}/${alias}.h = FOUND") + + #add_subdirectory(${DRIVERS_DIR}/${alias}) + + add_library(${alias}_submodule ${DRIVERS_DIR}/${alias}/${alias}.c) + 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}) + add_library(sub::${alias} ALIAS ${alias}_submodule) + set(${_currentPripheral} 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()