Skip to content

Commit

Permalink
feat: Moving compiler flags to toolchain.cmake
Browse files Browse the repository at this point in the history
Adding package.json and cmake changes to enable use of cpacman.py
  • Loading branch information
josepablo134 committed Mar 14, 2023
1 parent 63111b2 commit 453b71c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
output/*
**/*build
**/c_modules/
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,39 @@ At the moment the template toolchain only supports linux OS.

- __project/main.c__ : The file where the magic happens. After the startup code from the BSP, the system's entry point is defined here.

- __project/package.json__ : Packages descriptor file meant to be used with [cpacman](https://github.com/josepablo134/SimpleSourcePackageManager) package manager.

# CMake and Ninja

[CMake](https://cmake.org/) is a tool for generation and automation of code. The name is an abbreviation of __cross platform make__. It is a multiplatform, open-source tool that can generate Makefiles (or different build system projects like Ninja) from a simple and more readable configuration file. CMake in a nutshell is a syntax to describe a project and the compiler environment so it can be abstracted from the final build system file (Makefiles, Ninja.build, Eclipse .cproject, etc)

[Ninja](https://ninja-build.org/), in other hand, is a build system tool meant to replace Makefiles. It is focused by design to run as fast as possible. It already knows the number of cores of your machine, so it dynamically decides when and how to parallelize the build process.

# CPacMan (Source Package Manager)

Is a simple package manager (inspired on npm) meant to download source code and integrate it to your project with a simple json descriptor file.

Check it out: [cpacman](https://github.com/josepablo134/SimpleSourcePackageManager)

## Dependencies installation

Just navigate to the `project` folder and invoke the package manager:

```.sh
$ cd project
$ cpacman install
```

This will create a `c_modules` folder containing a CMake file required to add the packages to the project.

For more information about how cpacman works and how to use it, check out: [cpacman](https://github.com/josepablo134/SimpleSourcePackageManager)

## Build Process

The build process is pretty straightforward, just create a build folder, invoke CMake over the `project` folder and then run ninja (I recommend to use Ninja instead of Make).

```.sh
$ #Assuming you are at the root folder of this repo:
$ mkdir build
$ cd build
$ cmake ../project -GNinja
Expand Down
15 changes: 1 addition & 14 deletions project/BSP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ target_include_directories(${COMPONENT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)

include_directories(${COMPONENT_NAME} BEFORE
include_directories(${COMPONENT_NAME}
${CMAKE_CURRENT_LIST_DIR}/cfg
)

Expand All @@ -47,16 +47,3 @@ target_link_libraries( ${COMPONENT_NAME}
TivaWare
)

target_compile_options(${COMPONENT_NAME}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
$<$<COMPILE_LANGUAGE:C>:
-nostdlib -fno-exceptions -nostartfiles -nodefaultlibs -g3 -gdwarf-2 -lgcc -lc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C129_RA1 -DPART_TM4C129XNCZAD
>
$<$<COMPILE_LANGUAGE:ASM>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
)

13 changes: 0 additions & 13 deletions project/BSP/libs/RTOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,3 @@ target_include_directories(${COMPONENT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/FreeRTOS/portable
)

target_compile_options(${COMPONENT_NAME}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
$<$<COMPILE_LANGUAGE:C>:
-nostdlib -fno-exceptions -nostartfiles -nodefaultlibs -g3 -gdwarf-2 -lgcc -lc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C129_RA1 -DPART_TM4C129XNCZAD
>
$<$<COMPILE_LANGUAGE:ASM>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
)

16 changes: 0 additions & 16 deletions project/BSP/libs/TivaWare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,3 @@ target_include_directories(${COMPONENT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/driverlib/inc
)

#target_link_libraries(${COMPONENT_NAME} ${CMAKE_CURRENT_LIST_DIR}/driverlib/gcc/libdriver.a)

target_compile_options(${COMPONENT_NAME}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
$<$<COMPILE_LANGUAGE:C>:
-nostdlib -fno-exceptions -nostartfiles -nodefaultlibs -g3 -gdwarf-2 -lgcc -lc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C129_RA1 -DPART_TM4C129XNCZAD
>
$<$<COMPILE_LANGUAGE:ASM>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
)


Binary file removed project/BSP/libs/TivaWare/driverlib/gcc/libdriver.a
Binary file not shown.
24 changes: 4 additions & 20 deletions project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ add_executable( ${EXEC_NAME} ${WORK_DIR}/main.c )
add_subdirectory( ${WORK_DIR}/BSP )
add_subdirectory( ${WORK_DIR}/Tasks )

# package.json
add_subdirectory( ${WORK_DIR}/c_modules )

target_link_libraries( ${EXEC_NAME}
BSP
Tasks
Expand All @@ -42,28 +45,9 @@ target_include_directories(${EXEC_NAME} PRIVATE
${WORK_DIR}
)

# ===================================================================
# Compile and Link options
# ===================================================================
target_compile_options(${EXEC_NAME}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
$<$<COMPILE_LANGUAGE:C>:
-nostdlib -fno-exceptions -nostartfiles -nodefaultlibs -g3 -gdwarf-2 -lgcc -lc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C129_RA1 -DPART_TM4C129XNCZAD
>
$<$<COMPILE_LANGUAGE:ASM>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
)

target_link_options(${EXEC_NAME}
PUBLIC
# Entry point of the whole system.
#-Wl,-eResetISR
-Wl,-e${BSP_EXEC_ENTRY_POINT}
-fno-exceptions -nostartfiles -lgcc -lc -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wl,-n -Wl,-T ${LINKER_SCRIPT} -Wl,-Map ${OUTPUT_MAP}
-Wl,-e${BSP_EXEC_ENTRY_POINT} -Wl,-T ${LINKER_SCRIPT} -Wl,-Map ${OUTPUT_MAP}
)

# Generate Linker Script from configuration file
Expand Down
15 changes: 2 additions & 13 deletions project/Tasks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@ target_link_libraries( ${COMPONENT_NAME}
BSP
RTOS
TivaWare
)

target_compile_options(${COMPONENT_NAME}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
$<$<COMPILE_LANGUAGE:C>:
-nostdlib -fno-exceptions -nostartfiles -nodefaultlibs -g3 -gdwarf-2 -lgcc -lc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C129_RA1 -DPART_TM4C129XNCZAD
>
$<$<COMPILE_LANGUAGE:ASM>:
-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
>
I2C::TivaCTM4C1294
SPI::TivaCTM4C1294
)

4 changes: 2 additions & 2 deletions project/cmake/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# -fdata-sections Place each data item into its own section in the output file.
# -fomit-frame-pointer Omit the frame pointer in functions that don’t need one.
# -mabi=aapcs Defines enums to be a variable sized type.
set(OBJECT_GEN_FLAGS "-O0 -mthumb -fno-builtin -Wall -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs")
set(OBJECT_GEN_FLAGS "-O0 -mthumb -fno-builtin -Wall -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-exceptions -nostartfiles -g3 -gdwarf-2 -lgcc -lc -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C129_RA1 -DPART_TM4C129XNCZAD")

set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options")
set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options")
Expand All @@ -38,7 +38,7 @@ set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL
# -Wl,--gc-sections Perform the dead code elimination.
# --specs=nano.specs Link with newlib-nano.
# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls.
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -mabi=aapcs -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options")
set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs --specs=nosys.specs -mthumb -mabi=aapcs -fno-exceptions -nostartfiles -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -lgcc -lc -Wl,--gc-sections -Wl,-n" CACHE INTERNAL "Linker options")

#---------------------------------------------------------------------------------------
# Set debug/release build configuration Options
Expand Down
10 changes: 10 additions & 0 deletions project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "TivaCTemplate",
"version": "1.0.0",
"description": "This is a template",
"author": "Josepablo C.",
"license": "ISC",
"dependencies": [
{ "name":"microMiddlewares", "uri":"[email protected]:josepablo134/microMiddlewares.git", "type":"git" }
]
}

0 comments on commit 453b71c

Please sign in to comment.