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.
271 lines
13 KiB
271 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)#Declared empty because it will be filled automaticaly afterwards
|
|
set(PERIPHERAL_LIBS)#Declared empty because it will be filled automaticaly afterwards
|
|
|
|
# Directory for the libraries -> "Common to all CSL"
|
|
set(LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/libraries)
|
|
set(LIBRARIES_HEADERS_DIR)#Declared empty because it will be filled automaticaly afterwards
|
|
set(LIBRARIES_LIBS)#Declared empty because it will be filled automaticaly afterwards
|
|
|
|
# Directory for the SYSTEM -> "Common to all CSL"
|
|
set(SYSTEM_DIR ${CMAKE_SOURCE_DIR}/system)
|
|
set(SYSTEM_HEADERS_DIR)#Declared empty because it will be filled automaticaly afterwards
|
|
set(SYSTEM_LIBS)#Declared empty because it will be filled automaticaly afterwards
|
|
|
|
####################################################################################################
|
|
# 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)
|
|
|
|
# For Doxygen document generatio
|
|
include(${CMAKE_CORE_DIR}/doxygen.cmake)
|
|
|
|
# All the library and submodule funtions and definitions are written here
|
|
include(${CMAKE_CORE_DIR}/cmakeProject.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 drivers headers and standart libraries.
|
|
include(${DRIVERS_DIR}/CMakeLists.txt)
|
|
|
|
# Here is the include fopr the awailable libraries headers and standart libraries.
|
|
include(${LIBRARIES_DIR}/CMakeLists.txt)
|
|
|
|
# Here is the include fopr the awailable system headers and standart libraries.
|
|
include(${SYSTEM_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 MUST be made here to be able to propagate them through
|
|
# all the modules
|
|
####################################################################################################
|
|
message("${BoldBlue}")
|
|
message("+-------------------------------+")
|
|
message("Adding Header Directories")
|
|
message("+-------------------------------+")
|
|
message("|-->For System")
|
|
createHeaderDirList("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_HEADERS_DIR")
|
|
message("${BoldBlue}|-->For Peripherals")
|
|
createHeaderDirList("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERALS_HEADERS_DIR")
|
|
message("${BoldBlue}|-->For Drivers")
|
|
createHeaderDirList("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVERS_HEADERS_DIR")
|
|
message("${BoldBlue}|-->For Libraries")
|
|
createHeaderDirList("${LIBRARIES_DIR}" "${LIBRARIES_LIST}" "LIBRARIES_HEADERS_DIR")
|
|
message("${BoldBlue}|-->For Project")
|
|
createHeaderDirListProject("${PROJECT_ADDITIONAL_DIRS}" "PROJECT_HEADERS_DIR")
|
|
message("${BoldBlue}+-------------------------------+${ColourReset}")
|
|
|
|
#Stick all the herade direcotries together for ease of use further down
|
|
set (COMMON_HEADERS ${CSL_HEADERS_DIR}
|
|
${SYSTEM_HEADERS_DIR}
|
|
${PERIPHERALS_HEADERS_DIR}
|
|
${DRIVERS_HEADERS_DIR}
|
|
${LIBRARIES_HEADERS_DIR}
|
|
${PROJECT_HEADERS_DIR})
|
|
|
|
####################################################################################################
|
|
# Making Modules
|
|
####################################################################################################
|
|
message("${BoldBlue}")
|
|
message("+-------------------------------+")
|
|
message("Making Submolues")
|
|
message("+-------------------------------+")
|
|
message("|-->For System")
|
|
makeSubmodules("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_LIBS")
|
|
message("${BoldBlue}|-->For Peripherals")
|
|
makeSubmodules("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERAL_LIBS")
|
|
message("${BoldBlue}|-->For Drivers")
|
|
makeSubmodules("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVER_LIBS")
|
|
message("${BoldBlue}|-->For Libraries")
|
|
makeSubmodules("${LIBRARIES_DIR}" "${LIBRARIES_LIST}" "LIBRARIES_LIBS")
|
|
message("${BoldBlue}|-->For Project")
|
|
makeSubmodulesProject("${PROJECT_ADDITIONAL_DIRS}" "${PROJECT_TO_COMPILE_LIST}" "PROJECT_LIBS")
|
|
message("${BoldBlue}+-------------------------------+${ColourReset}")
|
|
|
|
# Stick All the libraries together, only for code redability futher down.
|
|
foreach(X IN LISTS STARTUP_UCODE
|
|
SYSTEM_LIBS
|
|
PERIPHERAL_LIBS
|
|
DRIVER_LIBS
|
|
LIBRARIES_LIBS
|
|
PROJECT_LIBS )
|
|
list(APPEND GENERATED_LIBRARIES ${X})
|
|
endforeach()
|
|
|
|
####################################################################################################
|
|
# Overview
|
|
####################################################################################################
|
|
message("${BoldBlue}")
|
|
message("+-------------------------------+")
|
|
message("Project Info")
|
|
message("+-------------------------------+")
|
|
message(" |--> Executable Name:${BoldCyan} ${EXECUTABLE} ${BoldBlue}")
|
|
message(" |--> Startup uCode :${BoldCyan} ${STARTUP_CODE} ${BoldBlue}")
|
|
message(" |--> Linker :${BoldCyan} ${LINKER} ${BoldBlue}")
|
|
message(" |--> Project Dir :${BoldCyan} ${PROJECT_DIR} ${BoldBlue}")
|
|
message(" |--> Project Config :${BoldCyan} ${PROJECT_CONFIG_FILE} ${BoldBlue}")
|
|
message(" |--> CSL Dir :${BoldCyan} ${CSL_DIR} ${BoldBlue}")
|
|
message(" |--> CSL Config :${BoldCyan} ${CSL_CONFIG_FILE} ${BoldBlue}")
|
|
message(" |--> Compiler Config:${BoldCyan} ${COMPILER_DEFS} ${BoldBlue}")
|
|
|
|
message("${BoldBlue}")
|
|
message("+-------------------------------+")
|
|
message("Compiling Info")
|
|
message("+-------------------------------+")
|
|
message("|--> Main Compile Definitions:")
|
|
printList("${BoldCyan} | " "${MAIN_DEFS}")
|
|
message("${BoldBlue}|--> Main Compile Flags:")
|
|
printList("${BoldCyan} | " "${MAIN_FLAGS}")
|
|
message("${BoldBlue}|--> Linker Flags:")
|
|
printList("${BoldCyan} | " "${LINKER_FLAGS}")
|
|
message("${BoldBlue}|--> Periferals which will be implemented:")
|
|
printList("${BoldCyan} |-> " "${PERIPHERALS_LIST}")
|
|
message("${BoldBlue}|--> Drivers which will be implemented:")
|
|
printList("${BoldCyan} |-> " "${DRIVERS_LIST}")
|
|
message("${BoldBlue}|--> Project sources to be implemented:")
|
|
printList("${BoldCyan} |-> " "${PROJECT_SOURCES_DIR_LIST}")
|
|
message("${BoldBlue}|--> Generated Library Submodules ${Red}!!!This list order also defines the compilation \
|
|
order of submodules!!!${ColourReset}${BoldCyan}")
|
|
printList("${BoldCyan} |-> " "${GENERATED_LIBRARIES}")
|
|
message("${BoldBlue}+-------------------------------+${ColourReset}")
|
|
|
|
####################################################################################################
|
|
# EXECUTABLE
|
|
####################################################################################################
|
|
add_executable(${EXECUTABLE} ${PROJECT_DIR}/main.${PL})
|
|
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(" |-> C_COMPILER : ${CMAKE_C_COMPILER}")
|
|
message(" |-> CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
|
|
message(" |-> ASM_COMPILER: ${CMAKE_ASM_COMPILER}")
|
|
message(" |-> OBJCOPY : ${CMAKE_OBJCOPY}")
|
|
message(" |-> SIZE : ${CMAKE_SIZE}")
|
|
|
|
# AS we provide our own linker nad not using the one from the curren OS (system)
|
|
message(" |-> 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})
|
|
|
|
|
|
####################################################################################################
|
|
# Documentation generation
|
|
####################################################################################################
|
|
generateDoxygen()
|
|
|
|
####################################################################################################
|
|
#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}>)
|