Channged .c extention on library generation function with a PL varibale for future proofing the code

master
Kerem Yollu 3 years ago
parent 6a4ec9adcf
commit c762a4abbd

@ -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

@ -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()

@ -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})

@ -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()

@ -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})

Loading…
Cancel
Save