#################################################################################################### # DIRECTORY CHECKS #################################################################################################### function(checkDirectory _directory) if(EXISTS ${_directory}) else() errorDirNotFound("${_directory}") endif() endfunction() #################################################################################################### # HEADER MANAGEMENT #################################################################################################### # This function goes an searches for directories containing header files and return the corresponding directory. function(createHeaderDirList _directory _list _headersList) set(_newheaderDirList) foreach(DIR IN LISTS _list) checkDirectory("${_directory}/${DIR}") list(APPEND _newheaderDirList ${_directory}/${DIR}) message("${BoldMagenta} |-> Added : ${_directory}/${DIR}") endforeach() message("${ColourReset}") set(${_headersList} ${_newheaderDirList} PARENT_SCOPE) endfunction() # This function searches for the given header file name (_alias) if it has benn included # If it finds it it retursn the directory where the header is Located # If it doesn't find a header it generates a fatal error function(checkIfHeaderFileIncluded _alias _retDir) set(_headerFound FALSE) set(_headerDirFound) foreach(_headerDir IN LISTS COMMON_HEADERS) if(EXISTS ${_headerDir}/${alias}.h) set(_headerFound TRUE) set(_headerDirFound ${_headerDir}) endif() endforeach() if(_headerFound) set(${_retDir} ${_headerDirFound}/${alias}.h PARENT_SCOPE) else() errorHFileNotFound(${_headerDirFound} ${_alias}) endif() endfunction() # This function searches for the given header file name (_alias) if it has benn included # If it finds it it retursn the directory where the header is Located # If it doesn't find a header it returns a Non Found Message function(searchHeaderFile _alias _retDir) set(_headerFound FALSE) set(_headerDirFound) foreach(_headerDir IN LISTS COMMON_HEADERS) if(EXISTS ${_headerDir}/${_alias}.h) set(_headerFound TRUE) set(_headerDirFound ${_headerDir}) endif() endforeach() if(_headerFound) set(${_retDir} ${_headerDirFound}/${_alias}.h PARENT_SCOPE) else() set(${_retDir} "No corresponding header << ${_alias}.h >> found " PARENT_SCOPE) endif() endfunction() #################################################################################################### # SUBMODULE MANAGEMENT #################################################################################################### function(makeSubmodules _directory _aliasList _submoduleList) set(_newSubmoduleList) set(_headerLoc) #For each alias of element present on the list that has been given as argument foreach(alias IN LISTS _aliasList) checkDirectory("${_directory}/${alias}") # Does the directory exists (If not fatal error) #Does the given element has an implmenetation for a CSL if(EXISTS ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) #If yes message("${BoldCyan} |-> Target Found : ${alias} ${BoldYellow} ") checkIfHeaderFileIncluded("${alias}" "_headerLoc") #Every Implementation has to have a header (if not Fatal Error) #Does the given element has an predefined standart usage library if(EXISTS ${_directory}/${alias}/${alias}.${PL}) # If yes then add this to the compiling list message(" |-> Def Header : ${_headerLoc}") message(" |-> Lib Source : ${_directory}/${alias}/${alias}.${PL} ") message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL} ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) else() # If No than just compile the implmentation source message(" |-> Def Header : ${_headerLoc}") message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") add_library(${alias}_submodule ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) endif() message(" |-> Name : sub::${alias}") target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) add_library(sub::${alias} ALIAS ${alias}_submodule) #Append the internal submodule list with the newly compiled element list(APPEND _newSubmoduleList sub::${alias}) else() # Else, when the element has no implmentation for a CSL #If the element has an source file if(EXISTS ${_directory}/${alias}/${alias}.${PL}) searchHeaderFile("${alias}" "_headerLoc") #Searches if there is an Header (if not it will not generate any error) message("${BoldCyan} |-> Target Found : ${alias} ${BoldYellow} ") message(" |-> Header : ${_headerLoc}") message(" |-> Source : ${_directory}/${alias}/${alias}.${PL}") message(" |-> Name : sub::${alias}") add_library(${alias}_submodule ${_directory}/${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 ${COMMON_HEADERS}) add_library(sub::${alias} ALIAS ${alias}_submodule) #Append the internal submodule list with the newly compiled element list(APPEND _newSubmoduleList sub::${alias}) else() # When the element has no source file and is only a header. message("${BoldMagenta} |-> No Source file for target : ${alias}") message(" |-> Only headers will be added") endif() endif() endforeach() message("${ColourReset}") #New submodule list with the names of the compiled elements set(${_submoduleList} ${_newSubmoduleList} PARENT_SCOPE) endfunction() #################################################################################################### # PRINT FUNCTIONS #################################################################################################### function(printList _txt _list) foreach(X IN LISTS _list) message("${_txt}${X}") endforeach() endfunction()