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.
KED/CMakeLists.txt

306 lines
12 KiB

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")
####################################################################################################
# Setting the used directory locations
####################################################################################################
# Location of the project : It is defaulted to one Higher than the KED Directory :TODO: Shall we let
# the user define it weherever he wants it ?
set(PROJECT_DIR ${CMAKE_SOURCE_DIR}/..)
# Location of the cmkae core funtionalities / funtions / definitions
set(CMAKE_CORE_DIR ${CMAKE_SOURCE_DIR}/env/cmake_core)
# Location of the used SCL 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})
# Location of the Sources for the selected CSL -> "Specific to each CSL"
set(CSL_SOURCES ${CSL_DIR}/implementation)
set(CSL_INCLUDES
${CSL_DIR}/CMSIS/Include
${CSL_DIR}/HardwareDescription)
set(CSL_STARTUP ${CSL_DIR}/startup)
# Directiry fot the drivers -> "Common to all CSL"
set(DRIVERS_DIR ${CMAKE_SOURCE_DIR}/drivers)
# Directory fot the peripherals -> "Common to all CSL"
set(PERIFERALS_DIR ${CMAKE_SOURCE_DIR}/peripherals)
set(PROJECT_CONFIG_FILE ${PROJECT_DIR}/projectDefinitions.cmake)
####################################################################################################
# INCLUDES
####################################################################################################
# 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)
# Here is the include Where the user sould define his project sources and headers
include(${PROJECT_CONFIG_FILE})
# Here is the include fopr the awailable peripheral headers and standart libraries.
include(${PERIFERALS_DIR}/CMakeLists.txt)
# Here is the include fopr the awailable peripheral headers and standart libraries.
include(${DRIVERS_DIR}/CMakeLists.txt)
####################################################################################################
# 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_CORE_DIR}/compiler.cmake) # TODO : Change location
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})
# do this intead sf declaring languages in the beginning it will prevent loop errors.
project(${CSL_USED} ASM C CXX)
#Create the executable
set(EXECUTABLE ${PROJECT_NAME})
####################################################################################################
# SUBDIRECTORIES Will add the given folders to the porject an check for CmakeLists.txt
####################################################################################################
include(${CSL_DEFS})
add_subdirectory(${CSL_DIR})
####################################################################################################
# Sartupt uCode Definition
####################################################################################################
set(STARTUP_UCODE sub::startup)
####################################################################################################
# Driver definitions
####################################################################################################
message("${BoldBlue}")
message("+-------------------------------+")
message("Cheking Drivers")
message("+-------------------------------+")
foreach(X IN LISTS DRIVERS_LIST)
addDriverHeader("${X}" "NEW_DRIVER_HEADER")
list(APPEND DRIVER_HEADERS_LIST ${NEW_DRIVER_HEADER})
endforeach()
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("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("+-------------------------------+")
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_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 ${Red}!!!This list order also defines the compilation \
order of submodules!!!${ColourReset}${BoldCyan}")
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} ${DRIVER_HEADERS_LIST})
####################################################################################################
# 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 input and output files
set(DOXYGEN_IN ${CMAKE_CORE_DIR}/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
# $<$<COMPILE_LANGUAGE:ASM>:-x assembler-with-cpp ${ASM_FLAGS}>)