]> granicus.if.org Git - esp-idf/commitdiff
cmake: Account for missing partition CSV file at cmake runtime
authorAngus Gratton <angus@espressif.com>
Mon, 27 Aug 2018 03:55:04 +0000 (11:55 +0800)
committerAngus Gratton <gus@projectgus.com>
Wed, 29 Aug 2018 12:22:55 +0000 (20:22 +0800)
Avoid either breaking menuconfig (if cmake fails), or producing bad build output (if cmake succeeds
but no flashing offsets, etc. were generated.)

components/partition_table/CMakeLists.txt
components/partition_table/project_include.cmake
tools/cmake/scripts/fail.cmake [new file with mode: 0644]

index a97080c4cd1d34876a8a635a01c9a0c8e20c9bca..443a5ad6e339aaa0c400583c8423155f5c19a2f7 100644 (file)
@@ -42,7 +42,24 @@ if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
 
 endif()
 
-add_custom_target(partition_table ALL DEPENDS "${final_partition_bin}")
+if(EXISTS ${partition_csv})
+    add_custom_target(partition_table ALL DEPENDS "${final_partition_bin}")
+else()
+    # This is a bit of a hack: If the partition input CSV is not found, create a phony partition_table target that
+    # fails the build. Have it also touch CMakeCache.txt to cause a cmake run next time
+    # (to pick up a new CSV if one exists, etc.)
+    #
+    # This is because partition CSV is required at CMake runtime (to generate metadata files with flashing data, etc) but we can't
+    # fail the build if it is not found, because the "menuconfig" target may be required to fix the problem. CMAKE_CONFIGURE_DEPENDS
+    # only works for files which exist at CMake runtime.
+    add_custom_target(partition_table ALL
+        COMMAND ${CMAKE_COMMAND} -E echo "Partition table CSV ${partition_csv} does not exist. Either change partition table in menuconfig or create this input file."
+        COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_BINARY_DIR}/CMakeCache.txt"
+        COMMAND ${CMAKE_COMMAND} -P ${IDF_PATH}/tools/cmake/scripts/fail.cmake)
+endif()
+
+add_dependencies(bootloader partition_table)
+add_dependencies(app partition_table)
 
 # Use global properties ESPTOOL_WRITE_FLASH_ARGS to pass this info to build
 # the list of esptool write arguments for flashing
index 8af1e0ee923175fb0b5db6c9a52099216875ef4d..07ba2cce02b0e5acca6c7625d74c32e2f0b219fd 100644 (file)
@@ -11,6 +11,8 @@ if(CONFIG_PARTITION_TABLE_CUSTOM)
     if(NOT EXISTS "${PARTITION_CSV_PATH}")
         message(WARNING "Partition table CSV file ${PARTITION_CSV_PATH} not found. "
             "Change custom partition CSV path in menuconfig.")
+        # Note: partition_table CMakeLists.txt contains some logic to create a dummy
+        # partition_table target in this case, see comments in that file.
     endif()
 else()
     # Other .csv files are always in the component directory
diff --git a/tools/cmake/scripts/fail.cmake b/tools/cmake/scripts/fail.cmake
new file mode 100644 (file)
index 0000000..5ceddb3
--- /dev/null
@@ -0,0 +1,4 @@
+# 'cmake -E' doesn't have a way to fail outright, so run this script
+# with 'cmake -P' to fail a build.
+message(FATAL_ERROR "Failing the build (see errors on lines above)")
+