@@ -596,6 +596,106 @@ if(NF_FEATURE_USE_SPIFFS)
596
596
597
597
endif ()
598
598
599
+
600
+ # if support for littlefs is enabled add it to the build
601
+ if (NF_FEATURE_USE_LITTLEFS)
602
+
603
+ # check if LITTLEFS_SOURCE was specified or if it's empty (default is empty)
604
+ set (NO_LITTLEFS_SOURCE TRUE )
605
+
606
+ if (LITTLEFS_SOURCE)
607
+ if (NOT "${LITTLEFS_SOURCE} " STREQUAL "" )
608
+ set (NO_LITTLEFS_SOURCE FALSE )
609
+ endif ()
610
+ endif ()
611
+
612
+ if (NO_LITTLEFS_SOURCE)
613
+ # no littlefs source specified, download it from it's repo
614
+
615
+ # check for Git (needed here for advanced warning to user if it's not installed)
616
+ find_package (Git)
617
+
618
+ # check if Git was found, if not report to user and abort
619
+ if (NOT GIT_EXECUTABLE)
620
+ message (FATAL_ERROR "error: could not find Git, make sure you have it installed." )
621
+ endif ()
622
+
623
+ # need to setup a separate CMake project to download the code from the GitHub repository
624
+ # otherwise it won't be available before the actual build step
625
+ configure_file ("${PROJECT_SOURCE_DIR} /CMake/littlefs.CMakeLists.cmake.in"
626
+ "${CMAKE_BINARY_DIR} /littlefs_Download/CMakeLists.txt" )
627
+
628
+ # setup CMake project for littlefs download
629
+ execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR} " .
630
+ RESULT_VARIABLE result
631
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /littlefs_Download" )
632
+
633
+ # run build on littlefs download CMake project to perform the download
634
+ execute_process (COMMAND ${CMAKE_COMMAND} --build .
635
+ RESULT_VARIABLE result
636
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /littlefs_Download" )
637
+
638
+ # add littlefs as external project
639
+ ExternalProject_Add(
640
+ LITTLEFS
641
+ PREFIX LITTLEFS
642
+ SOURCE_DIR ${CMAKE_BINARY_DIR} /littlefs_Source
643
+ GIT_REPOSITORY https://github.com/ARMmbed/littlefs
644
+ GIT_TAG "v2.2.1" # target latest release
645
+ GIT_SHALLOW 1 # download only the tip of the branch, not the complete history
646
+ TIMEOUT 10
647
+ LOG_DOWNLOAD 1
648
+
649
+ # Disable all other steps
650
+ CONFIGURE_COMMAND ""
651
+ BUILD_COMMAND ""
652
+ INSTALL_COMMAND ""
653
+ )
654
+
655
+ else ()
656
+ # littlefs source was specified
657
+
658
+ # sanity check is source path exists
659
+ if (EXISTS "${LITTLEFS_SOURCE} /" )
660
+
661
+ # check if we already have the sources, no need to copy again
662
+ if (NOT EXISTS "${CMAKE_BINARY_DIR} /littlefs_Source" )
663
+ message (STATUS "littlefs source from: ${LITTLEFS_SOURCE} " )
664
+ file (COPY "${LITTLEFS_SOURCE} /" DESTINATION "${CMAKE_BINARY_DIR} /littlefs_Source" )
665
+ else ()
666
+ message (STATUS "Using local cache of littlefs source from ${LITTLEFS_SOURCE} " )
667
+ endif ()
668
+
669
+ set (LITTLEFS_INCLUDE_DIR ${CMAKE_BINARY_DIR} /littlefs_Source)
670
+ set (LITTLEFS_INCLUDE_DIR ${CMAKE_BINARY_DIR} /littlefs_Source/bd)
671
+ else ()
672
+ message (FATAL_ERROR "Couldn't find littlefs source at ${LITTLEFS_SOURCE} /" )
673
+ endif ()
674
+
675
+ # add littlefs as external project
676
+ ExternalProject_Add(
677
+ LITTLEFS
678
+ PREFIX LITTLEFS
679
+ SOURCE_DIR ${CMAKE_BINARY_DIR} /littlefs_Source
680
+
681
+ # Disable all other steps
682
+ CONFIGURE_COMMAND ""
683
+ BUILD_COMMAND ""
684
+ INSTALL_COMMAND ""
685
+ )
686
+
687
+ endif ()
688
+
689
+ # get source dir for littlefs CMake project
690
+ ExternalProject_Get_Property(LITTLEFS SOURCE_DIR)
691
+
692
+ set (LITTLEFS_LIBRARIES "${CMAKE_SHARED_LIBRARY_PREFIX} LITTLEFS${CMAKE_SHARED_LIBRARY_SUFFIX} " )
693
+ include_directories (${LITTLEFS_INCLUDE_DIRS} )
694
+
695
+ add_subdirectory (littlefs)
696
+
697
+ endif ()
698
+
599
699
# add target ChibiOS dirs
600
700
add_subdirectory (Include )
601
701
add_subdirectory (common)
0 commit comments