Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow settings paths through env #226

Merged
merged 10 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ It will compile a project for the `F4` family by default, but you can also compi
# Usage

First of all you need to configure toolchain and library paths using CMake variables.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add the variables names (or an example of variable name) here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea. maybe even a concrete example for a file which can be sourced to load all necessary env variables at once (I find this really convenient compared to very large CMake commands, and the path stays clean if it is not used)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of commit 08ceb4b it seems already excellent to me. It's better than what I expected. I will review When you remove WIP.

Please note also there are also Windows users like me, so keep generic (even if we can consider Linux as default choice)

Copy link
Contributor Author

@robamu robamu Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually used .sh scripts on Windows with git bash or MinGW64. I am not totally sure whether this belongs in the README, but a regular CMake workflow generally involves more scripting and I found scripts like that to set up environments quickly extremely useful. I added this for the powershell on Windows as well, but I need to test this. I read somewhere that it would not be possible with powershell like that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .sh only is OK don't worry. I just wanted to heads up. Your work is great.

You can do this by passing values through command line during cmake run or by setting variables inside your `CMakeLists.txt`
You can do this by passing values through command line during cmake run or by setting variables
inside your `CMakeLists.txt`. You can also set pass these variables to CMake by setting them
robamu marked this conversation as resolved.
Show resolved Hide resolved
as environmental variables.

## Configuration

Expand Down Expand Up @@ -146,9 +148,14 @@ CMSIS package will generate linker script for your device automatically (target

stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in the embedded world.

## FreeRTOS
## <a id="freertos"></a> FreeRTOS

[cmake/FindFreeRTOS](cmake/FindFreeRTOS) - finds FreeRTOS sources in location specified by `FREERTOS_PATH` (*default*: `/opt/FreeRTOS`) variable and format them as `IMPORTED` targets. `FREERTOS_PATH` can be either the path to the whole [FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS) github repo, or the path to FreeRTOS-Kernel (usually located in the subfolder `FreeRTOS` on a downloaded release)
[cmake/FindFreeRTOS](cmake/FindFreeRTOS.cmake) - finds FreeRTOS sources in location specified by
`FREERTOS_PATH` (*default*: `/opt/FreeRTOS`) variable and format them as `IMPORTED` targets.
`FREERTOS_PATH` can be either the path to the whole
[FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS) github repo, or the path to
FreeRTOS-Kernel (usually located in the subfolder `FreeRTOS` on a downloaded release).
You can supply `FREERTOS_PATH` as an environmental variable as well.

Typical usage:

Expand All @@ -166,4 +173,3 @@ Other FreeRTOS libraries:
* `FreeRTOS::StreamBuffer` - stream buffer (`stream_buffer.c`)
* `FreeRTOS::Timers` - timers (`timers.c`)
* `FreeRTOS::Heap::<N>` - heap implementation (`heap_<N>.c`), `<N>`: [1-5]

4 changes: 4 additions & 0 deletions cmake/FindBSP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ foreach(COMP ${BSP_FIND_COMPONENTS})
set(FAMILY ${CMAKE_MATCH_1})
string(TOLOWER ${FAMILY} FAMILY_L)

if(NOT STM32_CUBE_${FAMILY}_PATH)
set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}")
endif()

if(NOT STM32_CUBE_${FAMILY}_PATH)
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "No STM32_CUBE_${FAMILY}_PATH specified using default: ${STM32_CUBE_${FAMILY}_PATH}")
Expand Down
4 changes: 4 additions & 0 deletions cmake/FindCMSIS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})

string(TOLOWER ${FAMILY} FAMILY_L)

if((NOT STM32_CMSIS_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH))
set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}")
endif()

if((NOT STM32_CMSIS_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH))
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_CMSIS_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
Expand Down
4 changes: 4 additions & 0 deletions cmake/FindFreeRTOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ list(REMOVE_DUPLICATES FreeRTOS_FIND_COMPONENTS)

set(FreeRTOS_HEAPS 1 2 3 4 5)

if(NOT FREERTOS_PATH)
set(FREERTOS_PATH $ENV{FREERTOS_PATH} CACHE PATH "Path to FreeRTOS")
endif()

if(NOT FREERTOS_PATH)
set(FREERTOS_PATH /opt/FreeRTOS CACHE PATH "Path to FreeRTOS")
message(STATUS "No FREERTOS_PATH specified using default: ${FREERTOS_PATH}")
Expand Down
4 changes: 4 additions & 0 deletions cmake/FindHAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES})
set(FAMILY ${CMAKE_MATCH_1})
string(TOLOWER ${FAMILY} FAMILY_L)

if((NOT STM32_HAL_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH))
set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}")
endif()

if((NOT STM32_HAL_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH))
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_HAL_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
Expand Down