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

Support for CMake builds. Added Linux stub port for now to allow cross compilation #35

Merged
merged 8 commits into from
Oct 28, 2022
173 changes: 173 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0048 NEW) # project version
cmake_policy(SET CMP0076 NEW) # full paths

########################################################################
# Project Details
project(FreeRTOS-Plus-TCP
VERSION 0.0.1
DESCRIPTION "FreeRTOS DOS Compatible Embedded FAT File System"
HOMEPAGE_URL https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/index.html
LANGUAGES C)

# Do not allow in-source build.
if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
endif()

# Options

# Optional: FREERTOS_PLUS_FAT_DEV_SUPPORT
# - when OFF - device support is disabled and not used.
# - When ON - device support is enabled and the ff_devices.h API is used.
# Optional: FREERTOS_PLUS_FAT_PORT
# - When not defined - identifies native platform Linxu or MinGW and uses that port.
# - When defined as A_CUSTOM_PORT - the port library must be defined in advance.
# - When any of the other supported ports - the port library is defined by portable source files.
option(FREERTOS_PLUS_FAT_DEV_SUPPORT "FreeRTOS Plus FAT Device selection support" OFF)

# Select the appropriate FAT Port
# This will fail the CMake preparation step if not set to one of those values.
set(FREERTOS_PLUS_FAT_PORT "" CACHE STRING "FreeRTOS Plus FAT Port selection")
set(FREERTOS_PLUS_FAT_PORT_LIST
A_CUSTOM_PORT
ATSAM4E
AVR32_UC3
LPC18XX
POSIX
STM32FXX
STM32HXX
ZYNQ
ZYNQ_2019_3
)
if(NOT FREERTOS_PLUS_FAT_PORT)
# Attempt to detect the system.
if(UNIX)
message(STATUS "Detected UNIX/Posix system setting FREERTOS_PLUS_FAT_PORT = POSIX")
set(FREERTOS_PLUS_FAT_PORT POSIX)
elseif(MINGW)
message(STATUS "Detected Windows MinGW system setting FREERTOS_PLUS_FAT_PORT = WIN_MGW")
set(FREERTOS_PLUS_FAT_PORT WIN_PCAP)
endif()
endif()

if(NOT FREERTOS_PLUS_FAT_PORT IN_LIST FREERTOS_PLUS_FAT_PORT_LIST )
message(FATAL_ERROR " FREERTOS_PLUS_FAT_PORT is '${FREERTOS_PLUS_FAT_PORT}'.\n"
" Please specify it from top-level CMake file (example):\n"
" set(FREERTOS_PLUS_FAT_PORT POSIX CACHE STRING \"\")\n"
" or from CMake command line option:\n"
" -DFREERTOS_PLUS_FAT_PORT=POSIX\n"
" \n"
" Available port options: (Tested means compiled with that variant)\n"
" A_CUSTOM_PORT Target: User Defined\n"
" ATSAM4E Target: ATSAM4E Tested: TODO\n"
" AVR32_UC3 Target: avr32_uc3 Tested: TODO\n"
" LPC18XX Target: lpc18xx Tested: TODO\n"
" POSIX Target: linux/Posix\n"
" STM32F4XX Target: STM32F4xx Tested: TODO\n"
" STM32F7XX Target: STM32F7xx Tested: TODO\n"
" ZYNQ Target: Xilinx Zynq Tested: TODO\n"
" ZYNQ_2019_3 Target: Xilinx Zynq 2019.3")
elseif((FREERTOS_PLUS_FAT_PORT STREQUAL "A_CUSTOM_PORT") AND (NOT TARGET freertos_plus_fat_port) )
message(FATAL_ERROR " FREERTOS_PLUS_FAT_PORT is set to A_CUSTOM_PORT.\n"
" Please specify the custom port target with all necessary files.\n"
" For example, assuming a directory of:\n"
" FreeRTOSPlusFatPort/\n"
" CMakeLists.txt\n"
" ff_sddisk.c\n"
" Where FreeRTOSPlusFatPort/CMakeLists.txt is a modified version of:\n"
" add_library(freertos_plus_fat_port STATIC)\n"
" target_sources(freertos_plus_fat_port\n"
" PRIVATE\n"
" ff_sddisk.c)\n"
" target_link_libraries(freertos_plus_fat_port\n"
" PUBLIC\n"
" freertos_plus_fat_port_common\n"
" PRIVATE\n"
" freertos_kernel\n"
" freertos_plus_fat)")
endif()

add_library( freertos_plus_fat STATIC )

target_sources( freertos_plus_fat
PRIVATE
include/ff_crc.h
include/ff_devices.h
include/ff_dir.h
include/ff_error.h
include/ff_fat.h
include/ff_fatdef.h
include/ff_file.h
include/ff_format.h
include/ff_headers.h
include/ff_ioman.h
include/ff_locking.h
include/ff_memory.h
include/ff_old_config_defines.h
include/ff_stdio.h
include/ff_string.h
include/ff_sys.h
include/ff_time.h
include/FreeRTOS_errno_FAT.h
include/FreeRTOSFATConfigDefaults.h

ff_crc.c
$<$<BOOL:${FREERTOS_PLUS_FAT_DEV_SUPPORT}>:ff_dev_support.c>
ff_dir.c
ff_error.c
ff_fat.c
ff_file.c
ff_format.c
ff_ioman.c
ff_locking.c
ff_memory.c
ff_stdio.c
ff_string.c
ff_sys.c
ff_time.c
)

target_include_directories( freertos_plus_fat SYSTEM
PUBLIC
include
)

target_compile_definitions( freertos_plus_fat
PUBLIC
ffconfigDEV_SUPPORT=$<BOOL:${FREERTOS_PLUS_FAT_DEV_SUPPORT}>
)

target_compile_options( freertos_plus_fat
PRIVATE
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-qual>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-constant-conversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-documentation-unknown-command>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-documentation>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-extra-semi-stmt>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wno-format>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-implicit-int-conversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-overflow>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-pedantic>

$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-reserved-macro-identifier>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-shorten-64-to-32>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sign-conversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-tautological-constant-out-of-range-compare>
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-type-limits>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-undef>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
)

target_link_libraries( freertos_plus_fat
PUBLIC
freertos_config
PRIVATE
freertos_plus_fat_port
freertos_kernel
)

add_subdirectory(portable)
104 changes: 104 additions & 0 deletions portable/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
add_library( freertos_plus_fat_port_common STATIC )

target_sources( freertos_plus_fat_port_common
PRIVATE
common/ff_ramdisk.c
common/ff_ramdisk.h
common/ff_sddisk.h
)

target_include_directories( freertos_plus_fat_port_common SYSTEM
PUBLIC
common
)

target_compile_options( freertos_plus_fat_port_common
PRIVATE
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-prototypes>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-reserved-macro-identifier>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-shorten-64-to-32>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sign-conversion>
)

target_link_libraries( freertos_plus_fat_port_common
PRIVATE
freertos_kernel
freertos_plus_fat
)

# -------------------------------------------------------------------

if (FREERTOS_PLUS_FAT_PORT STREQUAL "A_CUSTOM_PORT")
message(STATUS "Using a custom FREERTOS_PLUS_FAT_PORT.")
return()
endif()

add_library( freertos_plus_fat_port STATIC )

target_sources( freertos_plus_fat_port
PRIVATE
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},ATSAM4E>:
ATSAM4E/ff_sddisk_r.c
ATSAM4E/ff_sddisk.c>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},AVR32_UC3>:
avr32_uc3/ff_flush.c
avr32_uc3/ff_flush.h
avr32_uc3/ff_locking.c>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},LPC18XX>:
lpc18xx/ff_sddisk.c>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},POSIX>:
linux/ff_sddisk.c>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},STM32F4XX>:
STM32F4xx/ff_sddisk.c
STM32F4xx/stm32f4xx_hal_sd.c
STM32F4xx/stm32f4xx_hal_sd.h
STM32F4xx/stm32f4xx_ll_sdmmc.c
STM32F4xx/stm32f4xx_ll_sdmmc.h>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},STM3F7XX>:
STM32F7xx/ff_sddisk.c
STM32F7xx/stm32f7xx_hal_sd.c
STM32F7xx/stm32f7xx_hal_sd.h>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},ZYNQ>:
Zynq/ff_sddisk.c
Zynq/xsdps_g.c
Zynq/xsdps_hw.h
Zynq/xsdps_info.c
Zynq/xsdps_info.h
Zynq/xsdps_options.c
Zynq/xsdps_sinit.c
Zynq/xsdps.c
Zynq/xsdps.h>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},ZYNQ_2019_3>:
Zynq.2019.3/ff_sddisk.c
Zynq.2019.3/xsdps_g.c
Zynq.2019.3/xsdps_hw.h
Zynq.2019.3/xsdps_info.c
Zynq.2019.3/xsdps_info.h
Zynq.2019.3/xsdps_options.c
Zynq.2019.3/xsdps_sinit.c
Zynq.2019.3/xsdps.c
Zynq.2019.3/xsdps.h>
)

target_include_directories( freertos_plus_fat_port
PRIVATE
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},AVR32_UC3>:${CMAKE_CURRENT_SOURCE_DIR}/avr32_uc3>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},STM32F4XX>:${CMAKE_CURRENT_SOURCE_DIR}/STM32F4xx>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},STM32F7XX>:${CMAKE_CURRENT_SOURCE_DIR}/STM32F7xx>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},ZYNQ>:${CMAKE_CURRENT_SOURCE_DIR}/Zynq>
$<$<STREQUAL:${FREERTOS_PLUS_FAT_PORT},ZYNQ_2019_3>:${CMAKE_CURRENT_SOURCE_DIR}/Zynq.2019.3>
)

target_compile_options( freertos_plus_fat_port
PRIVATE
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-gnu-statement-expression>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-parameter>
)

target_link_libraries( freertos_plus_fat_port
PUBLIC
freertos_plus_fat_port_common
PRIVATE
freertos_plus_fat
freertos_kernel
)
8 changes: 4 additions & 4 deletions portable/common/ff_ramdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ BaseType_t FF_RAMDiskShowPartition( FF_Disk_t * pxDisk )
FF_PRINTF( "Partition Nr %8u\n", pxDisk->xStatus.bPartitionNumber );
FF_PRINTF( "Type %8u (%s)\n", pxIOManager->xPartition.ucType, pcTypeName );
FF_PRINTF( "VolLabel '%8s' \n", pxIOManager->xPartition.pcVolumeLabel );
FF_PRINTF( "TotalSectors %8lu\n", pxIOManager->xPartition.ulTotalSectors );
FF_PRINTF( "SecsPerCluster %8lu\n", pxIOManager->xPartition.ulSectorsPerCluster );
FF_PRINTF( "Size %8lu KB\n", ulTotalSizeKB );
FF_PRINTF( "FreeSize %8lu KB ( %d perc free )\n", ulFreeSizeKB, iPercentageFree );
FF_PRINTF( "TotalSectors %8lu\n", (unsigned long) pxIOManager->xPartition.ulTotalSectors );
FF_PRINTF( "SecsPerCluster %8lu\n", (unsigned long) pxIOManager->xPartition.ulSectorsPerCluster );
FF_PRINTF( "Size %8lu KB\n", (unsigned long) ulTotalSizeKB );
FF_PRINTF( "FreeSize %8lu KB ( %d perc free )\n", (unsigned long) ulFreeSizeKB, iPercentageFree );
Copy link
Contributor

Choose a reason for hiding this comment

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

In stead of casting to unsigned long, the +FAT library normally uses unsigned in combination with %u:

-    FF_PRINTF( "TotalSectors   %8lu\n", (unsigned long) pxIOManager->xPartition.ulTotalSectors );
+    FF_PRINTF( "TotalSectors   %8u\n", (unsigned) pxIOManager->xPartition.ulTotalSectors );

It also removes the warning and it works well on 64-bit platforms as well.
Thank you

Copy link
Contributor

Choose a reason for hiding this comment

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

Until now, I didn't comment on this PR ( except about FF_PRINTF() ) because I am totally inexperienced with cmake ( I only use GNU make ).

I checked out your branch and typed "cmake", which doesn't work obviously.
Would you mind to give a short description of how I can compile the project for dummies?

Also, if you open this PR, you will see that "This branch is out-of-date with the base branch", with a button "Update branch". Could you update it with the master branch?

I will talk to the team and see who can further review this PR. Sorry for the long delay.

Copy link
Contributor Author

@phelter phelter Oct 24, 2022

Choose a reason for hiding this comment

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

@htibosch -

  • Short description on how to compile the project:

I've added a build check in ci/cd environment similar to the FreeRTOS-Plus-TCP repo (the .github directory is a copy and modify from that).

I've also updated the main README.md as to how to integrate with CMake in a higher level project.

Copy link
Contributor

Choose a reason for hiding this comment

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

As for the FF_PRINTF - all but one of the ff_ramdisk.c files are using %8lu rather than what you requested

That is possibly true, but we would like to get rid of all %ld and %lu formats, both in FreeRTOS+TCP and in FreeRTOS+TCP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@htibosch - My goal was to add the necessary code to have a linux port build similar to other FreeRTOS git repos (Kernel and Plus-TCP) and follow the same coding style and usage of the existing ports inside this Plus-FAT repo. Changing some code to reflect an arbitrary request to get rid of a particular format in this and other repos is out of scope (from my perspective) of this particular PR.

Since this is an unrelated issue to any of the CMake build support (a different feature/clean-up task), I'll add it to a follow on PR associated with fixing compile warnings of this repo instead (and I'll change all of the various portable code instead of just this new Linux port).

See similar ones for:

I intend to update the above ones and provide them, but have been blocked in continuing with this effort due to the outstanding pull requests.

}

return xReturn;
Expand Down
Loading