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 ? #################################################################################################### # Setting the used directory locations #################################################################################################### set(PROJECT_DIR ${CMAKE_SOURCE_DIR}/..) #Location of the project : It MUST be one Higher than the KED Directory set(CSL_DIR ${CMAKE_SOURCE_DIR}/csl/${CSL_USED}) #Location of the used SCL CSL_USED is passed as an argutem to CMake from run.sh -> "Specific to each CSL" set(CSL_SOURCES ${CMAKE_SOURCE_DIR}/csl/${CSL_USED}/Src)#Location of the Sources for the selected CSL -> "Specific to each CSL" set(DRIVERS_DIR ${CMAKE_SOURCE_DIR}/drivers) #Directiry fot the drivers -> "Common to all CSL" set(PERIFERALS_DIR ${CMAKE_SOURCE_DIR}/periferals) #Directory fot the written -> "Common to all CSL" #################################################################################################### #INCLUDES #################################################################################################### include(config/cmakeProjectConfig.cmake) #For the moment there are only colors include(${PROJECT_DIR}/projectDefinitions.cmake) #Here is the include Where the user sould define his project sources and headers #################################################################################################### # Cheking if the choosen CSL exists, this i redundant because run.sh makes that alredy but makes the # code future proof. Goal would be to not use a run.sh if the user doesn't need help #################################################################################################### if(EXISTS ${CSL_DIR}) # Cheking if the directory exists message("${Green}") message("+-------------------------------+") message("Compiling for ${CSL_USED}") message("+-------------------------------+") message("${ColourReset}") set(COMPILER_DEFS ${CMAKE_SOURCE_DIR}/config/compiler.cmake) set(CSL_DEFS ${CSL_DIR}/config.cmake) else() message("${Red}") message( FATAL_ERROR "\nPlease Select a valid CSL, CMake will exit\n") message("${ColourReset}") endif() include(${COMPILER_DEFS}) project(${CSL_USED} ASM C CXX) #do this intead sf declaring languages in the beginning it will prevent loop errors. set(EXECUTABLE ${PROJECT_NAME}) #Create the executable #################################################################################################### #SUBDIRECTORIES Will add the given folders to the porject an check for CmakeLists.txt #################################################################################################### include(${CSL_DEFS}) add_subdirectory(utils) add_subdirectory(csl) add_subdirectory(drivers) add_subdirectory(periferals) #################################################################################################### #Sartupt uCode Definition #################################################################################################### set(STARTUP_UCODE sub::startup) #################################################################################################### #Peripehral definitions #################################################################################################### set(PERIPHERALS_LIST deviceSetup delay usart timer spi i2c pin) set(NEW_PERIPHERAL null) message("${BoldYellow}") message("+-------------------------------+") message("Cheking Periferals") message("+-------------------------------+") foreach(X IN LISTS PERIPHERALS_LIST) addPeripheral("${X}" "NEW_PERIPHERAL") list(APPEND PERIPHERAL_LIBS ${NEW_PERIPHERAL}) endforeach() message("+-------------------------------+") message("${ColourReset}") #################################################################################################### #Driver definitions #################################################################################################### set(DRIVERS_LIST max7219 max31865) message("${BoldYellow}") message("+-------------------------------+") message("Cheking Drivers") message("+-------------------------------+") foreach(X IN LISTS DRIVERS_LIST) addDriver("${X}" "NEW_DRIVER") list(APPEND DRIVER_LIBS ${NEW_DRIVER}) endforeach() message("+-------------------------------+") message("${ColourReset}") #################################################################################################### #User's project definitions #################################################################################################### message("${BoldYellow}") message("+-------------------------------+") message("Cheking User's Project") message("+-------------------------------+") message("Declared Project Headers :") foreach(X IN LISTS PROJECT_HEADERS_DIR) message("|-->${X}") endforeach() message("Included Project Headers :") projectHeadersCheck() message("Decalred Project Sources :") foreach(X IN LISTS PROJECT_SOURCES_DIR) message("|-->${X}") endforeach() message("Included Project Sources :") projectCheckSourcesCheck() message("Declared sources :") foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) message("|-->${X}") endforeach() message("Creating Libraries for declared sources :") foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) projectAddItem("${X}" "NEW_PROJECT_ITEM") list(APPEND PROJECT_LIBS ${NEW_PROJECT_ITEM}) endforeach() message("+-------------------------------+") #################################################################################################### #Stick All the libraries together, only for code redability futher down. #################################################################################################### foreach(X IN LISTS STARTUP_UCODE PROJECT_LIBS PERIPHERAL_LIBS DRIVER_LIBS ) list(APPEND GENERATED_LIBRARIES ${X}) endforeach() #################################################################################################### #Overview #################################################################################################### message("${BoldBlue}") message("+-------------------------------+") message("Project Info") message("+-------------------------------+") message(" |--> Executable's Name\t\t\t : ${EXECUTABLE}") message(" |--> Project's directory\t\t : ${PROJECT_DIR}") message(" |--> Project Configuration\t\t : ${PROJECT_DIR}/project.conf") message(" |--> Chip Support Layer Dir.\t\t : ${CSL_DIR}") message(" |--> CLS's cmake configuration\t\t : ${CSL_DEFS}") message(" |--> Compiler Definition file\t\t : ${COMPILER_DEFS}") message(" |--> Driver Dir\t\t\t : ${DRIVERS_DIR}") message(" |--> Periferal Definition Dir\t\t : ${PERIFERALS_DIR}") message(" |--> Periferal Implementation Dir\t : ${CSL_SOURCES}") message(" |--> Startup uCode Submodule:") message(" |->${STARTUP_UCODE}") message(" |--> Periferals which will be implemented:") foreach(X IN LISTS PERIPHERALS_LIST) message(" |->${X}") endforeach() message(" |--> Drivers which will be implemented:") foreach(X IN LISTS DRIVERS_LIST) message(" |->${X}") endforeach() message(" |--> Project sources to be implemented:") foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) message(" |->${X}") endforeach() message(" |--> Generated Library Submodules ${Magenta}!!!This list order also defines the compilation order of submodules!!!${ColourReset}${BoldBlue}") foreach(X IN LISTS GENERATED_LIBRARIES) message(" |->${X}") endforeach() message("+-------------------------------+") message("${ColourReset}") #################################################################################################### #EXECUTABLE #################################################################################################### 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}) #################################################################################################### #LINKING EXECUTEABLE #################################################################################################### message("${Cyan}") message("+-------------------------------+") message("Linker & Compiler Info") message("+-------------------------------+") if(IS_NO_SYS) target_link_libraries(${EXECUTABLE} ${GENERATED_LIBRARIES}) target_link_options(${EXECUTABLE} PRIVATE ${LINKER_FLAGS}) else () target_link_libraries(${EXECUTABLE} ${GENERATED_LIBRARIES}) endif() message(" |--> LINKER: ${LINKER}") message(" |--> CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") message(" |--> CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") message(" |--> CMAKE_ASM_COMPILER: ${CMAKE_ASM_COMPILER}") message(" |--> CMAKE_OBJCOPY: ${CMAKE_OBJCOPY}") message(" |--> CMAKE_SIZE: ${CMAKE_SIZE}") message(" |--> CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") #AS we provide our own linker nad not using the one from the curren OS (system) message("+-------------------------------+") message("${ColourReset}") #################################################################################################### #CUSTOM COMMANDS #################################################################################################### if(NEED_OBJCOPY) add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin) endif() add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${CMAKE_SIZE} ${EXECUTABLE}) #################################################################################################### #DOXYGEN #################################################################################################### if(OUTPUT_DOXYGEN) find_package(Doxygen) if (DOXYGEN_FOUND) # set input and output files set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/config/doxyfile.in) set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxyfile) # request to configure the file configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) message("Doxygen build started") # 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} COMMENT "Generating API documentation with Doxygen" VERBATIM ) else (DOXYGEN_FOUND) message("Doxygen need to be installed to generate the doxygen documentation") endif (DOXYGEN_FOUND) endif(OUTPUT_DOXYGEN) #################################################################################################### #CUSTOM Comments from dev. #################################################################################################### # Link For header dependency : https://stackoverflow.com/questions/11216408/cmake-dependencies-headers-between-apps-libraries-in-same-project # This is one possible trick to handle the assenbly compiling. # We can't use arm-non-eabi-as because it can onaly hande macros. # So this bizzare Variable makes shure that whne the asembly compiling is called the -x assembler-with-cpp flag is passed # target_compile_options(${EXECUTABLE} PRIVATE # $<$:-x assembler-with-cpp ${ASM_FLAGS}>)