From c762a4abbd97fc66f58fef4bad7de19107d4d4d4 Mon Sep 17 00:00:00 2001 From: kerem Date: Sun, 22 Jan 2023 17:03:24 +0100 Subject: [PATCH] Channged .c extention on library generation function with a PL varibale for future proofing the code --- CMakeLists.txt | 2 +- config/cmakeProjectConfig.cmake | 49 +++++++++++++++++++++- drivers/CMakeLists.txt | 6 +-- examples/autoInit/projectDefinitions.cmake | 43 +------------------ periferals/CMakeLists.txt | 14 +++---- 5 files changed, 60 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fa2a36..c631399 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.15) #################################################################################################### set(CMAKE_VERBOSE_MAKEFILE ON) #Should CMake print everythign ? set(OUTPUT_DOXYGEN FALSE) #Should CMake generate Doxygen output ? - +set(PL "c") #################################################################################################### # Setting the used directory locations diff --git a/config/cmakeProjectConfig.cmake b/config/cmakeProjectConfig.cmake index b0c99ef..8bb8e6b 100644 --- a/config/cmakeProjectConfig.cmake +++ b/config/cmakeProjectConfig.cmake @@ -1,4 +1,6 @@ - +#################################################################################################### +# CMAKE Colors +#################################################################################################### if(NOT WIN32) string(ASCII 27 Esc) set(ColourReset "${Esc}[m") @@ -18,3 +20,48 @@ if(NOT WIN32) 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() + message(FATAL_ERROR "Header directory ${DIR} : NOT FOUND") + 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() + message(FATAL_ERROR "Source directory ${DIR} : NOT FOUND") + 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() diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index c13501d..c72c2a2 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -1,15 +1,15 @@ 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}.${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_subdirectory(${DRIVERS_DIR}/${alias}) - add_library(${alias}_submodule ${DRIVERS_DIR}/${alias}/${alias}.c) + 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}) diff --git a/examples/autoInit/projectDefinitions.cmake b/examples/autoInit/projectDefinitions.cmake index e28c559..5dadf91 100644 --- a/examples/autoInit/projectDefinitions.cmake +++ b/examples/autoInit/projectDefinitions.cmake @@ -17,46 +17,5 @@ list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/sensors) #Declaring sources to be compiled for the project. #CMake will look in each previsouly declarec sources directory until to find this files. -set(PROJECT_SOURCES_DIR_LIST uartComm.c sensor.c) +set(PROJECT_SOURCES_DIR_LIST uartComm sensor) -#Searching if the given header directory exists if not we brake the compilation -function(projectHeadersCheck) - foreach(X IN LISTS PROJECT_HEADERS_DIR) - if(EXISTS ${X}) - message("|--> ${X} : INCLUDED") - else() - message(FATAL_ERROR "Header directory ${X} : NOT FOUND") - endif() - endforeach() -endfunction() - -#Searching if the given Source exists if not we brake the compilation -function(projectCheckSourcesCheck) - foreach(X IN LISTS PROJECT_SOURCES_DIR) - if(EXISTS ${X}) - message("|--> ${X} : INCLUDED") - else() - message(FATAL_ERROR "Source directory ${X} : NOT FOUND") - 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(X IN LISTS PROJECT_SOURCES_DIR) - if(EXISTS ${X}) - if(EXISTS ${X}/${alias}) #For each directory we chanek if the given source file exitst - message("|-->${alias} FOUND in : ${X}") - message(" |-> Creating sub::${alias} library submodule") - add_library(${alias}_submodule ${X}/${alias}) - 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 ${X} : NOT FOUND") - endif() - endforeach() -endfunction() diff --git a/periferals/CMakeLists.txt b/periferals/CMakeLists.txt index 1dac4b0..12ffb94 100644 --- a/periferals/CMakeLists.txt +++ b/periferals/CMakeLists.txt @@ -1,13 +1,13 @@ function(addPeripheral alias _currentPripheral) - if(EXISTS ${CSL_SOURCES}/imp_${alias}.c) # Checks if the desired peripheral is implemented for the desired CSL. + 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}.c") - if(EXISTS ${PERIFERALS_DIR}/${alias}.c) # Cheks if generic funtions are awailable. this is useful for standars as SPI i2c etc... - message(" --> Generic Library ${alias}.c for imp_${alias}.c = FOUND") - message(" |-> DIRECTORY: ${PERIFERALS_DIR}/${alias}.c") - add_library(${alias}_submodule ${PERIFERALS_DIR}/${alias}.c ${CSL_SOURCES}/imp_${alias}.c) + 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}.c) + add_library(${alias}_submodule ${CSL_SOURCES}/imp_${alias}.${PL}) endif() target_compile_options(${alias}_submodule PRIVATE ${C_FLAGS})