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.
289 lines
13 KiB
289 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)
|
|
|
|
# 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")
|
|
checkDirectories("${PROJECT_HEADERS_DIR}")
|
|
message("${BoldBlue}+-------------------------------+${ColourReset}")
|
|
|
|
set (COMMON_HEADERS ${CSL_HEADERS_DIR}
|
|
${PERIPHERALS_HEADERS_DIR}
|
|
${DRIVERS_HEADERS_DIR}
|
|
${LIBRARIES_HEADERS_DIR}
|
|
${PROJECT_HEADERS_DIR}
|
|
${SYSTEM_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")
|
|
makeSubmodules("${PROJECT_DIR}" "${PROJECT_SOURCES_DIR_LIST}" "PROJECT_LIBS")
|
|
message("${BoldBlue}+-------------------------------+${ColourReset}")
|
|
|
|
|
|
####################################################################################################
|
|
# Stick All the libraries together, only for code redability futher down.
|
|
####################################################################################################
|
|
foreach(X IN LISTS STARTUP_UCODE
|
|
PROJECT_LIBS
|
|
PERIPHERAL_LIBS
|
|
DRIVER_LIBS
|
|
LIBRARIES_LIBS
|
|
SYSTEM_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.${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(" |--> 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}>)
|