You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
297 lines
13 KiB
297 lines
13 KiB
cmake_minimum_required(VERSION 3.18)
|
|
|
|
####################################################################################################
|
|
# CMAKE Features
|
|
####################################################################################################
|
|
# do this instead of declaring languages in the beginning this WILL prevent loop errors.
|
|
project(${CSL_USED} ASM C CXX)
|
|
# Defining the executables name
|
|
set(EXECUTABLE ${PROJECT_NAME})
|
|
|
|
####################################################################################################
|
|
# NON-VITAL OPTION FOR COMPILATION
|
|
####################################################################################################
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE OFF) # Should CMake print everythign ?
|
|
|
|
set(OUTPUT_DOXYGEN TRUE) # Should CMake generate Doxygen output ?
|
|
set(DOXYGEN_OUTPUT_DIR ${CMAKE_SOURCE_DIR}/env/doc)
|
|
# TODO: discuss on where doxygen should place the output
|
|
# -> in env/doc
|
|
# -> in ked_build outside of the ked environment (prefered, as it includes also the users
|
|
# project documentation
|
|
# idea -> creakte an override option in the projectConfig.cmake file to be able to define
|
|
# where and waht.
|
|
set(PL "c") # Used programming language, we could maybe do a check.
|
|
|
|
####################################################################################################
|
|
# PASSED VARIABLE WHEN CALLING run.sh
|
|
####################################################################################################
|
|
# CSL_USED passed by run.sh and is the quivalent of the ic name
|
|
# PROJECT_DIR Passed by run.sh and is the defined place where the project is. run.sh should be in
|
|
# the future capable of definin project paht.
|
|
|
|
####################################################################################################
|
|
# Setting the used directory locations
|
|
####################################################################################################
|
|
# Location of the project : It is defaulted to one Higher than the KED Directory :TODO: Shall we let
|
|
set(PROJECT_CONFIG_FILE ${PROJECT_DIR}/projectDefinitions.cmake)
|
|
|
|
# Location of the cmkae core funtionalities / funtions / definitions
|
|
set(CMAKE_CORE_DIR ${CMAKE_SOURCE_DIR}/env/cmake_core)
|
|
set(COMPILER_DEFS ${CMAKE_CORE_DIR}/compiler.cmake)
|
|
|
|
# Location of CSL, CSL_USED is passed as an argutem to CMake from run.sh
|
|
# -> "Specific to each CSL"
|
|
set(CSL_DIR ${CMAKE_SOURCE_DIR}/csl/${CSL_USED})
|
|
set(CSL_SOURCES_DIR ${CSL_DIR}/implementation)
|
|
set(CSL_HEADERS_DIR ${CSL_DIR}/CMSIS/Include ${CSL_DIR}/HardwareDescription)
|
|
set(CSL_STARTUP_DIR ${CSL_DIR}/startup)
|
|
set(CSL_CONFIG_FILE ${CSL_DIR}/config.cmake)
|
|
|
|
# Directiry fot the drivers -> "Common to all CSL"
|
|
set(DRIVERS_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)
|
|
|
|
# Directory for the libraries -> "Common to all CSL"
|
|
set(LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/libraries)
|
|
set(LIBRARIES_HEADERS_DIR ${CMAKE_SOURCE_DIR}/libraries)
|
|
|
|
|
|
####################################################################################################
|
|
# 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)
|
|
|
|
# For Detailed error messages.
|
|
include(${CMAKE_CORE_DIR}/errorHandler.cmake)
|
|
|
|
# Include the project definition defined by the end user implementiogn KED as a submodule
|
|
include(${PROJECT_CONFIG_FILE})
|
|
|
|
# Here is the include fopr the awailable peripheral headers and standart libraries.
|
|
include(${PERIPHERALS_DIR}/CMakeLists.txt)
|
|
|
|
# Here is the include fopr the awailable peripheral headers and standart libraries.
|
|
include(${DRIVERS_DIR}/CMakeLists.txt)
|
|
|
|
# Include the config fiel where the compilers to use ar defined
|
|
include(${COMPILER_DEFS})
|
|
|
|
# Confugration file of the csl, there you will wind the starup code handling, compiler/linker
|
|
# options, flags and definitions
|
|
include(${CSL_CONFIG_FILE})
|
|
|
|
####################################################################################################
|
|
# 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 Driver Headers")
|
|
message("+-------------------------------+")
|
|
foreach(X IN LISTS DRIVERS_LIST)
|
|
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}")
|
|
|
|
####################################################################################################
|
|
# Peripehral definitions
|
|
####################################################################################################
|
|
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}")
|
|
|
|
####################################################################################################
|
|
# User's project definitions
|
|
####################################################################################################
|
|
message("${BoldMagenta}")
|
|
message("+-------------------------------+")
|
|
message("Cheking User's Project")
|
|
message("+-------------------------------+")
|
|
message("Included Project Headers :")
|
|
checkDirectory("${PROJECT_HEADERS_DIR}")
|
|
message("Included Project Sources :")
|
|
checkDirectory("${PROJECT_SOURCES_DIR}")
|
|
message("Declared sources :")
|
|
printList("|-->" "${PROJECT_SOURCES_DIR_LIST}")
|
|
|
|
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("+-------------------------------+")
|
|
message("${ColourReset}")
|
|
|
|
####################################################################################################
|
|
# 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("${BoldCyan}")
|
|
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_CONFIG_FILE}")
|
|
message(" |--> Compiler Definition file\t\t : ${COMPILER_DEFS}")
|
|
message(" |--> Driver Dir\t\t\t : ${DRIVERS_DIR}")
|
|
message(" |--> Periferal Definition Dir\t\t : ${PERIPHERALS_DIR}")
|
|
message(" |--> Periferal Implementation Dir\t : ${CSL_SOURCES_DIR}")
|
|
message("")
|
|
message(" |--> Startup uCode Submodule:")
|
|
message(" |->${STARTUP_UCODE}")
|
|
|
|
message(" |--> Main Compile Definitions:")
|
|
printList( " | " "${MAIN_DEFS}")
|
|
message(" |--> Main Compile Flags:")
|
|
printList( " | " "${MAIN_FLAGS}")
|
|
message(" |--> Linker Flags:")
|
|
printList( " | " "${LINKER_FLAGS}")
|
|
message(" |--> Periferals which will be implemented:")
|
|
printList( " |-> " "${PERIPHERALS_LIST}")
|
|
message(" |--> Drivers which will be implemented:")
|
|
printList( " |-> " "${DRIVERS_LIST}")
|
|
message(" |--> Project sources to be implemented:")
|
|
printList( " |-> " "${PROJECT_SOURCES_DIR_LIST}")
|
|
message(" |--> Generated Library Submodules ${Red}!!!This list order also defines the compilation \
|
|
order of submodules!!!${ColourReset}${BoldCyan}")
|
|
printList( " |-> " "${GENERATED_LIBRARIES}")
|
|
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 ${COMMON_HEADERS})
|
|
|
|
####################################################################################################
|
|
# LINKING EXECUTEABLE
|
|
####################################################################################################
|
|
message("${BoldGreen}")
|
|
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}")
|
|
|
|
# AS we provide our own linker nad not using the one from the curren OS (system)
|
|
message(" |--> CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
|
|
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(DOXYGEN_IN ${CMAKE_CORE_DIR}/doxyfile.in)
|
|
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxyfile)
|
|
message("${Green}")
|
|
message("+-------------------------------+")
|
|
message("Generating Doxygen output")
|
|
message("+-------------------------------+")
|
|
message("${ColourReset}")
|
|
|
|
# request to configure the file
|
|
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
|
|
# 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 ${DOXYGEN_OUTPUT_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
|
|
# $<$<COMPILE_LANGUAGE:ASM>:-x assembler-with-cpp ${ASM_FLAGS}>)
|