diff --git a/.gitignore b/.gitignore index 254d236..67bc1f3 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,6 @@ build/ # python stuff __pycache__/ + +# Doxygen +env/doc/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 182ca22..31b79d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,7 @@ cmake_minimum_required(VERSION 3.15) # CMAKE Features #################################################################################################### set(CMAKE_VERBOSE_MAKEFILE ON) # Should CMake print everythign ? -set(OUTPUT_DOXYGEN FALSE) # Should CMake generate Doxygen output ? -set(PL "c") +set(PL "c") # Used programming language, we could maybe do a check. #################################################################################################### # Setting the used directory locations @@ -26,17 +25,25 @@ set(CSL_STARTUP_DIR ${CSL_DIR}/startup) # Directiry fot the drivers -> "Common to all CSL" set(DRIVERS_DIR ${CMAKE_SOURCE_DIR}/drivers) -set(DRIVERS_HEADERS_DIR ${CMAKE_SOURCE_DIR}/drivers) +set(DRIVERS_HEADERS_DIR) #Declared empty because it will be filled automaticaly afterwards # Directory fot the peripherals -> "Common to all CSL" set(PERIPHERALS_DIR ${CMAKE_SOURCE_DIR}/peripherals) set(PERIPHERALS_HEADERS_DIR ${CMAKE_SOURCE_DIR}/peripherals) +set(LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/libraries) set(LIBRARIES_HEADERS_DIR ${CMAKE_SOURCE_DIR}/libraries) +# Variable for Doxygen generation +set(OUTPUT_DOXYGEN TRUE) # Should CMake generate Doxygen output ? +set(DOXYGEN_WORKING_DIR ${CMAKE_SOURCE_DIR}/env/doc) + #################################################################################################### # INCLUDES #################################################################################################### +# Adding human readable color references for cmake +include(${CMAKE_CORE_DIR}/colors.cmake) + # All the library and submodule funtions and definitions are written here include(${CMAKE_CORE_DIR}/cmakeCore.cmake) @@ -52,10 +59,6 @@ include(${PERIPHERALS_DIR}/CMakeLists.txt) # Here is the include fopr the awailable peripheral headers and standart libraries. include(${DRIVERS_DIR}/CMakeLists.txt) -#################################################################################################### -# HEADERS -#################################################################################################### -set (COMMON_HEADERS ${PERIPHERALS_HEADERS_DIR} ${CSL_HEADERS_DIR} ${LIBRARIES_HEADERS_DIR}) #################################################################################################### # Cheking if the choosen CSL exists, this i redundant because run.sh makes that alredy but makes the @@ -66,6 +69,8 @@ if(EXISTS ${CSL_DIR}) # Cheking if the directory exists message("+-------------------------------+") message("Compiling for ${CSL_USED}") message("+-------------------------------+") + message("Project dir : ${PROJECT_DIR}") + message("+-------------------------------+") message("${ColourReset}") set(COMPILER_DEFS ${CMAKE_CORE_DIR}/compiler.cmake) # TODO : Change location set(CSL_DEFS ${CSL_DIR}/config.cmake) @@ -78,7 +83,7 @@ endif() include(${COMPILER_DEFS}) -# do this intead sf declaring languages in the beginning it will prevent loop errors. +# do this instead of declaring languages in the beginning this WILL prevent loop errors. project(${CSL_USED} ASM C CXX) #Create the executable @@ -91,28 +96,40 @@ include(${CSL_DEFS}) add_subdirectory(${CSL_DIR}) #################################################################################################### -# Sartupt uCode Definition +# Sartupt uCode Definition this part Is left alone on purpose ! #################################################################################################### set(STARTUP_UCODE sub::startup) #################################################################################################### -# Driver definitions +# HEADERS +# ALL Header Definitions and calls MSUT be made here to be able to propagate them through all the modules #################################################################################################### + message("${BoldBlue}") message("+-------------------------------+") -message("Cheking Drivers") +message("Cheking Driver Headers") message("+-------------------------------+") - foreach(X IN LISTS DRIVERS_LIST) - addDriverHeader("${X}" "NEW_DRIVER_HEADER") + addHeaderDir("${DRIVERS_DIR}" "${X}" "NEW_DRIVER_HEADER") list(APPEND DRIVERS_HEADERS_DIR ${NEW_DRIVER_HEADER}) endforeach() +message("+-------------------------------+") +set (COMMON_HEADERS ${CSL_HEADERS_DIR} + ${PERIPHERALS_HEADERS_DIR} + ${DRIVERS_HEADERS_DIR} + ${LIBRARIES_HEADERS_DIR} + ${PROJECT_HEADERS_DIR}) + +#################################################################################################### +# Driver definitions +#################################################################################################### +message("Cheking Drivers ") +message("+-------------------------------+") foreach(X IN LISTS DRIVERS_LIST) addDriver("${X}" "NEW_DRIVER") list(APPEND DRIVER_LIBS ${NEW_DRIVER}) endforeach() - message("+-------------------------------+") message("${ColourReset}") @@ -229,8 +246,7 @@ message("${ColourReset}") add_executable(${EXECUTABLE} ${PROJECT_DIR}/main.c) target_compile_options(${EXECUTABLE} PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${EXECUTABLE} PRIVATE ${MAIN_DEFS}) -target_include_directories(${EXECUTABLE} PUBLIC ${PROJECT_HEADERS_DIR} ${PROJECT_SOURCES_DIR} - ${MAIN_INCLUDES} ${DRIVERS_HEADERS_DIR}) +target_include_directories(${EXECUTABLE} PUBLIC ${COMMON_HEADERS}) #################################################################################################### # LINKING EXECUTEABLE @@ -280,9 +296,13 @@ add_custom_command(TARGET ${EXECUTABLE} if(OUTPUT_DOXYGEN) find_package(Doxygen) if (DOXYGEN_FOUND) - # set input and output files set(DOXYGEN_IN ${CMAKE_CORE_DIR}/doxyfile.in) set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxyfile) + message("${Green}") + message("+-------------------------------+") + message("Generation DOxygen output") + message("+-------------------------------+") + message("${ColourReset}") # request to configure the file configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) @@ -291,9 +311,14 @@ if(OUTPUT_DOXYGEN) # note the option ALL which allows to build the docs together with the application add_custom_target( doc_doxygen ALL COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${DOXYGEN_WORKING_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM ) + message("${Green}") + message("+-------------------------------+") + message("Generating Doxygen Done") + message("+-------------------------------+") + message("${ColourReset}") else (DOXYGEN_FOUND) message("Doxygen need to be installed to generate the doxygen documentation") endif (DOXYGEN_FOUND) diff --git a/env/cmake_core/cmakeCore.cmake b/env/cmake_core/cmakeCore.cmake old mode 100644 new mode 100755 index 3a2d7a7..f680b49 --- a/env/cmake_core/cmakeCore.cmake +++ b/env/cmake_core/cmakeCore.cmake @@ -1,25 +1,3 @@ -#################################################################################################### -# 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. @@ -30,11 +8,27 @@ function(checkDirectory _directory) if(EXISTS ${DIR}) message("|--> ${DIR} : INCLUDED") else() - errorHeaderDirNotFound() + errorDirNotFound() endif() endforeach() endfunction() +# This function goes an searches for directories containing header files and return the corresponding directory. +function(addHeaderDir _directory _alias _currentDriverHeader) + if(EXISTS ${_directory}/${_alias} ) # Checks if the given directory exitsts + if(EXISTS ${_directory}/${_alias}/${_alias}.h) + message(" --> Header File : ${_directory}/${_alias}/${_alias}.h = FOUND") + message(" |-> Driver directory : ${_directory}/${_alias} = ADDED TO HEADERS") + set(${_currentDriverHeader} ${_directory}/${_alias} PARENT_SCOPE) + + else () + errorHFileNotFound("${_directory}" "${_alias}") + endif() + else () + errorHDirNotFound("${_directory}" "${_alias}") + endif() +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) @@ -45,7 +39,7 @@ function(projectAddItem alias _currentItem) 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 ${COMMON_HEADERS} ${PROJECT_HEADERS_DIR}) + target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) add_library(sub::${alias} ALIAS ${alias}_submodule) set(${_currentItem} sub::${alias} PARENT_SCOPE) endif() @@ -72,7 +66,7 @@ function(addPeripheral alias _currentPripheral) target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) - target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS} ${DRIVERS_HEADERS_DIR}) + target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) add_library(sub::${alias} ALIAS ${alias}_submodule) set(${_currentPripheral} sub::${alias} PARENT_SCOPE) @@ -96,7 +90,7 @@ function(addDriver alias _currentDriver) 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 ${COMMON_HEADERS} ${DRIVERS_HEADERS_DIR}) + target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) add_library(sub::${alias} ALIAS ${alias}_submodule) set(${_currentDriver} sub::${alias} PARENT_SCOPE) else () @@ -116,28 +110,4 @@ function(addDriver alias _currentDriver) 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() diff --git a/env/cmake_core/colors.cmake b/env/cmake_core/colors.cmake new file mode 100755 index 0000000..31abc25 --- /dev/null +++ b/env/cmake_core/colors.cmake @@ -0,0 +1,22 @@ +#################################################################################################### +# 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() diff --git a/env/cmake_core/compiler.cmake b/env/cmake_core/compiler.cmake old mode 100644 new mode 100755 diff --git a/env/cmake_core/doxyfile.in b/env/cmake_core/doxyfile.in old mode 100644 new mode 100755 diff --git a/env/cmake_core/errorHandler.cmake b/env/cmake_core/errorHandler.cmake old mode 100644 new mode 100755 index 1f890fe..8a1340e --- a/env/cmake_core/errorHandler.cmake +++ b/env/cmake_core/errorHandler.cmake @@ -15,33 +15,53 @@ function(errorOut) message("#########################################\n\n") endfunction() -function(errorHeaderDirNotFound) +function(errorDirNotFound) errorDetected() - message(" |-->PROJECT HEADER DIRECTORY NOT FOUND") + message(" |-->GIVEN DIRECTORY NOT FOUND") message(" |-> Given dir : ${DIR}") message("!!! Possible Reasons !!!") message(" |--> Did you give corect path in ${PROJECT_CONFIG_FILE} ??") - message(" |-> The declarion should look like :") - message(" |-> list(APPEND PROJECT_HEADERS_DIR ${DIR})") - message(" |-> you can also use the \$\{PROJECT_DIR\} variable") - message(" |-> \$\{PROJECT_DIR\} = ${PROJECT_DIR}") - message(" |-> list(APPEND PROJECT_HEADERS_DIR \$\{PROJECT_DIR\}/path_to_your_directory") + message(" |-> The declaration for HEADERS should look like :") + message(" |-> list(APPEND PROJECT_HEADERS_DIR \$\{PROJECT_DIR\}/path_to_header_directory") + message(" |-> \$\{PROJECT_DIR\} = ${PROJECT_DIR}") + message(" |-> The declaration for SOURCES should look like :") + message(" |-> list(APPEND PROJECT_SOURCES_DIR \$\{PROJECT_DIR\}/path_to_source_directory") + message(" |-> \$\{PROJECT_DIR\} = ${PROJECT_DIR}") + message("If A Directory has source and header files, it should be declared 2 times accordingly") + message(" |--> Once as HEADER location") + message(" |--> Once as SOURCES location") + message("\nFor more information please refer to : ${CMAKE_SOURCE_DIR}/README.md\n") errorOut() - message(FATAL_ERROR "Header directory ${DIR} : NOT FOUND") + message(FATAL_ERROR "Directory ${DIR} : NOT FOUND") endfunction() -function(errorSourceDirNotFound) +function(errorHFileNotFound _directory _alias) errorDetected() - message(" |--> PROJECT SOURCE DIRECTORY NOT FOUND") - message(" |-> Given dir : ${DIR}") + message("The header file <<${_alias}.h>> was not found") + message(" |--> Given directory is : ${_directory}/${_alias}") + message(" |--> Given Header file path : ${_directory}/${_alias}/${_alias}.h") message("!!! Possible Reasons !!!") - message(" |--> Did you give corect path in ${PROJECT_CONFIG_FILE} ??") - message(" |-> The declarion should look like :") - message(" |-> list(APPEND PROJECT_SOURCES_DIR ${DIR})") - message(" |-> you can also use the \$\{PROJECT_DIR\} variable") - message(" |-> \$\{PROJECT_DIR\} = ${PROJECT_DIR}") - message(" |-> list(APPEND PROJECT_SOURCES_DIR \$\{PROJECT_DIR\}/path_to_your_directory") + message(" |--> Did you name the module correctly in ${_directory}/CMakeLists.txt ??") + message(" |-> The module name should be : ") + message(" |-> The same as the the folder name") + message(" |-> The same as the the source name") + message(" |-> The same as the the header name") + message("\nFor more information please refer to : ${_directory}/README.md\n") errorOut() - message(FATAL_ERROR "Source directory ${DIR} : NOT FOUND") + message(FATAL_ERROR "\n NO Header file : <<${_alias}.h>> was found ### COMPILATION ABORTED ###\n") endfunction() +function(errorHDirNotFound _dir _alias) + errorDetected() + message("The file <<${_alias}>> was not found") + message(" |--> Given directory is : ${_directory}/${_alias}") + message("!!! Possible Reasons !!!") + message(" |--> Did you name the module correctly in ${_directory}/CMakeLists.txt ??") + message(" |-> The module name should be : ") + message(" |-> The same as the the folder name") + message(" |-> The same as the the source name") + message(" |-> The same as the the header name") + message("\nFor more information please refer to : ${_directory}/README.md\n") + errorOut() + message(FATAL_ERROR "\nNO Directory : <<${_directory}/${_alias}>> was found ### COMPILATION ABORTED ###\n") +endfunction()