Skip to content

Commit

Permalink
Move cmake compile options to the example project (#872)
Browse files Browse the repository at this point in the history
* Move GCC compile option to GCC folder with toolchain option

* Add CI flow to build cmake example

* Fix CI

* formatting && enable Werror

* Add useless variable to test CI

* revert useless variable

* Add comments as examples.

* Remove default compile options.

* Formatting

* Remove compile option in kernel cmake and put the sample in examples/cmake_example

---------

Co-authored-by: Joseph Julicher <[email protected]>
  • Loading branch information
ActoryOu and n9wxu authored Oct 30, 2023
1 parent 1c465a0 commit ef0104e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 42 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/kernel-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ jobs:
working-directory: FreeRTOS/Demo/Posix_GCC
run: make -j COVERAGE_TEST=1

CMake-Example:
name: CMake Example with Native GCC
runs-on: ubuntu-latest
steps:
# Checkout user pull request changes
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install GCC
shell: bash
run: |
sudo apt-get -y update
sudo apt-get -y install build-essential
- name: Build CMake Example Demo
shell: bash
working-directory: examples/cmake_example
run: |
cmake -S . -B build
cmake --build build
MSP430-GCC:
name: GNU MSP430 Toolchain
runs-on: ubuntu-latest
Expand Down
42 changes: 0 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,50 +230,8 @@ elseif((FREERTOS_PORT STREQUAL "A_CUSTOM_PORT") AND (NOT TARGET freertos_kernel_
" freertos_kernel_include)")
endif()


add_library(freertos_kernel STATIC)

########################################################################
# Overall Compile Options
# Note the compile option strategy is to error on everything and then
# Per library opt-out of things that are warnings/errors.
# This ensures that no matter what strategy for compilation you take, the
# builds will still occur.
#
# Only tested with GNU and Clang.
# Other options are https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
# Naming of compilers translation map:
#
# FreeRTOS | CMake
# -------------------
# CCS | ?TBD?
# GCC | GNU, Clang, *Clang Others?
# IAR | IAR
# Keil | ARMCC
# MSVC | MSVC # Note only for MinGW?
# Renesas | ?TBD?

target_compile_options(freertos_kernel PRIVATE
### Gnu/Clang C Options
$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>

$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wconversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>

# Suppressions required to build clean with clang.
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>
)


########################################################################
add_subdirectory(include)
add_subdirectory(portable)
Expand Down
39 changes: 39 additions & 0 deletions examples/cmake_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,45 @@ set(FREERTOS_PORT "TEMPLATE" CACHE STRING "" FORCE)
# Adding the FreeRTOS-Kernel subdirectory
add_subdirectory(${FREERTOS_KERNEL_PATH} FreeRTOS-Kernel)

########################################################################
# Overall Compile Options
# Note the compile option strategy is to error on everything and then
# Per library opt-out of things that are warnings/errors.
# This ensures that no matter what strategy for compilation you take, the
# builds will still occur.
#
# Only tested with GNU and Clang.
# Other options are https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
# Naming of compilers translation map:
#
# FreeRTOS | CMake
# -------------------
# CCS | ?TBD?
# GCC | GNU, Clang, *Clang Others?
# IAR | IAR
# Keil | ARMCC
# MSVC | MSVC # Note only for MinGW?
# Renesas | ?TBD?

target_compile_options(freertos_kernel PRIVATE
### Gnu/Clang C Options
$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>

$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wconversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>

# Suppressions required to build clean with clang.
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align> )

add_executable(${PROJECT_NAME}
main.c
)
Expand Down

0 comments on commit ef0104e

Please sign in to comment.