Просмотр исходного кода

Merge pull request #226 from spacefisch/garjones/allow_settings_paths_through_env

allow settings paths through env
Hish15 4 лет назад
Родитель
Сommit
a78357156d
5 измененных файлов с 64 добавлено и 5 удалено
  1. 48 5
      README.md
  2. 4 0
      cmake/FindBSP.cmake
  3. 4 0
      cmake/FindCMSIS.cmake
  4. 4 0
      cmake/FindFreeRTOS.cmake
  5. 4 0
      cmake/FindHAL.cmake

+ 48 - 5
README.md

@@ -36,14 +36,52 @@ 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. 
-You can do this by passing values through command line during cmake run or by setting variables inside your `CMakeLists.txt`
+First of all you need to configure toolchain and library paths using CMake variables. There are
+generally three ways to do this:
+
+1. Pass the variables through command line during cmake run with passed to CMake with 
+   `-D<VAR_NAME>=...`
+2. Set the variables inside your `CMakeLists.txt`
+3. Pass these variables to CMake by setting them as environmental variables. 
+
+The most important set of variables which needs to be set can be found in the following section.
 
 ## Configuration
 
+These configuration options need to be set for the build process to work properly:
+
 * `STM32_TOOLCHAIN_PATH` - where toolchain is located, **default**: `/usr`
+* `STM32_CUBE_<FAMILY>_PATH` - path to STM32Cube directory, where `<FAMILY>` is one
+   of `F0 G0 L0 F1 L1 F2 F3 F4 G4 L4 F7 H7` **default**: `/opt/STM32Cube<FAMILY>`
+
+These configuration variables are optional:
+
 * `TARGET_TRIPLET` - toolchain target triplet, **default**: `arm-none-eabi`
-* `STM32_CUBE_<FAMILY>_PATH` - path to STM32Cube directory, where `<FAMILY>` is one of `F0 G0 L0 F1 L1 F2 F3 F4 G4 L4 F7 H7` **default**: `/opt/STM32Cube<FAMILY>`
+* `FREERTOS_PATH` - Path to the FreeRTOS kernel when compiling with a RTOS. Does not need to be
+   specified when using CMSIS
+
+### Helper script on Unix shells
+
+If you have access to a Unix shell, which is the default terminal on Linux, or tools like
+`MinGW64` or `git bash` on Windows, you can write a small `path_helper.sh` script like this:
+
+```sh
+export STM32_TOOLCHAIN_PATH="<ToolchainPath>"
+export TARGET_TRIPLET=arm-none-eabi
+export STM32_CUBE_<FAMILY>_PATH="<PathToCubeRoot>"
+```
+
+and then use `. path_helper.sh` to set up the environment for the local terminal instance in one go.
+
+### Helper script in Powershell
+
+On Windows, you can use a Powershell script `path_helper.ps1`to set up the environment:
+
+```sh
+$env:STM32_TOOLCHAIN_PATH = "<ToolchainPath>"
+$env:TARGET_TRIPLET = arm-none-eabi
+$env:STM32_CUBE_<FAMILY>_PATH="<PathToCubeRoot>"
+```
 
 ## Common usage
 
@@ -155,9 +193,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:
 

+ 4 - 0
cmake/FindBSP.cmake

@@ -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}")

+ 4 - 0
cmake/FindCMSIS.cmake

@@ -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}")

+ 4 - 0
cmake/FindFreeRTOS.cmake

@@ -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}")

+ 4 - 0
cmake/FindHAL.cmake

@@ -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}")