]> granicus.if.org Git - esp-idf/commitdiff
cmake: Fix psram workaround compiler flag application
authorAngus Gratton <angus@espressif.com>
Fri, 22 Feb 2019 01:20:11 +0000 (12:20 +1100)
committerAngus Gratton <gus@projectgus.com>
Mon, 11 Mar 2019 05:02:36 +0000 (16:02 +1100)
Previously, this compiler flag was not being applied
regardless of CONFIG_SPIRAM_CACHE_WORKAROUND setting.

Explanation: add_compile_options() only applies to
source files added after the function is run, or in
subdirectories added after the function is run. In
this case, no new source files were being added after
this function was run.

components/esp32/CMakeLists.txt
components/esp32/Kconfig
components/esp32/project_include.cmake [new file with mode: 0644]
docs/en/api-guides/build-system-cmake.rst
docs/en/api-guides/build-system.rst
tools/ci/test_build_system_cmake.sh
tools/cmake/idf_functions.cmake
tools/cmake/utilities.cmake

index 5416ad225685f7b4ec9767aa4aede598b9d05290..5255ef038aa7629354b799ec28c36c882dce5e99 100644 (file)
@@ -90,7 +90,10 @@ else()
         )
 
     if(CONFIG_SPIRAM_CACHE_WORKAROUND)
-        add_compile_options(-mfix-esp32-psram-cache-issue)
+        # Note: Adding as a PUBLIC compile option here causes this option to propagate to all components that depend on esp32.
+        #
+        # To handle some corner cases, the same flag is set in project_include.cmake
+        target_compile_options(esp32 PUBLIC -mfix-esp32-psram-cache-issue)
     else()
         target_linker_script(esp32 "ld/esp32.rom.spiram_incompatible_fns.ld")
     endif()
index f68af71070995748ddbe0fb7ea5d61eb68900a6e..3be16efcca01effc47ec8978150525b3a5f39053 100644 (file)
@@ -115,7 +115,8 @@ config SPIRAM_CACHE_WORKAROUND
     help
         Revision 1 of the ESP32 has a bug that can cause a write to PSRAM not to take place in some situations
         when the cache line needs to be fetched from external RAM and an interrupt occurs. This enables a
-        fix in the compiler that makes sure the specific code that is vulnerable to this will not be emitted.
+        fix in the compiler (-mfix-esp32-psram-cache-issue) that makes sure the specific code that is vulnerable
+        to this will not be emitted.
         
         This will also not use any bits of newlib that are located in ROM, opting for a version that is compiled
         with the workaround and located in flash instead.
diff --git a/components/esp32/project_include.cmake b/components/esp32/project_include.cmake
new file mode 100644 (file)
index 0000000..d54d6a9
--- /dev/null
@@ -0,0 +1,8 @@
+if(CONFIG_SPIRAM_CACHE_WORKAROUND)
+    # We do this here as well as in CMakeLists.txt, because targets that
+    # are not part of the ESP-IDF build system (for cases where a generic
+    # non-IDF CMakeLists.txt file is imported into a component) don't depend
+    # on the esp32 component so don't get the extra flag. This handles that case.
+    add_compile_options(-mfix-esp32-psram-cache-issue)
+endif()
+
index 80ed775068e6409610c9675489fea444013535f7..46969b3463818dd186e14b00a7bc00bd8a275ff9 100644 (file)
@@ -702,6 +702,8 @@ the ESP-IDF build system entirely by using a CMake feature called ExternalProjec
 - The second set of commands adds a library target, which points to the "imported" library file built by the external system. Some properties need to be set in order to add include directories and tell CMake where this file is.
 - Finally, the generated library is added to `ADDITIONAL_MAKE_CLEAN_FILES`_. This means ``make clean`` will delete this library. (Note that the other object files from the build won't be deleted.)
 
+.. note:: When using an external build process with PSRAM, remember to add ``-mfix-esp32-psram-cache-issue`` to the C compiler arguments. See :envvar:`CONFIG_SPIRAM_CACHE_WORKAROUND` for details of this flag.
+
 .. _ADDITIONAL_MAKE_CLEAN_FILES_note:
 
 ExternalProject dependencies, clean builds
index e638a36d079934c6c7b11747aa45a5c45ba446cd..d1450dd5381dd28c59e8b5a742ebc5bb6a8bb519 100644 (file)
@@ -585,6 +585,7 @@ $(COMPONENT_LIBRARY) for the project make process to link into the app binary.
 (Actually, even this is not strictly necessary - if the COMPONENT_ADD_LDFLAGS variable
 is overridden then the component can instruct the linker to link other binaries instead.)
 
+.. note:: When using an external build process with PSRAM, remember to add ``-mfix-esp32-psram-cache-issue`` to the C compiler arguments. See :envvar:`CONFIG_SPIRAM_CACHE_WORKAROUND` for details of this flag.
 
 .. _esp-idf-template: https://github.com/espressif/esp-idf-template
 .. _GNU Make Manual: https://www.gnu.org/software/make/manual/make.html
index c5e02fc4d125eb3de38d399a80d23630ec5b59ea..4dda504c4e3bf655e42a2e8d460ad2957e3d7dda 100755 (executable)
@@ -212,6 +212,17 @@ function run_tests()
     mv CMakeLists.bak CMakeLists.txt
     assert_built ${APP_BINS} ${BOOTLOADER_BINS} ${PARTITION_BIN}
 
+    print_status "Building a project with CMake and PSRAM workaround, all files compile with workaround"
+    cp sdkconfig sdkconfig.psram
+    rm -rf build
+    echo "CONFIG_SPIRAM_SUPPORT=y" >> sdkconfig.psram
+    echo "CONFIG_SPIRAM_CACHE_WORKAROUND=y" >> sdkconfig.psram
+    # note: we do 'reconfigure' here, as we just need to run cmake
+    idf.py reconfigure -D SDKCONFIG="`pwd`/sdkconfig.psram"
+    grep -q '"command"' build/compile_commands.json || failure "compile_commands.json missing or has no no 'commands' in it"
+    (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-issue) && failure "All commands in compile_commands.json should use PSRAM cache workaround"
+    rm sdkconfig.psram
+
     print_status "All tests completed"
     if [ -n "${FAILURES}" ]; then
         echo "Some failures were detected:"
index 0d1c1832fd97d034b78d5687f2088c2b4db1d8f8..c976918a72add3b9cc4064f103a2d26151dc493c 100644 (file)
@@ -58,14 +58,16 @@ function(idf_set_global_compiler_options)
         add_compile_options(-Og)
     endif()
 
-    add_c_compile_options(-std=gnu99)
+    # Note: the visual studio generator doesn't support this syntax
+    add_compile_options("$<$<COMPILE_LANGUAGE:C>:-std=gnu99>")
 
-    add_cxx_compile_options(-std=gnu++11 -fno-rtti)
+    add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++11>")
+    add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>")
 
     if(CONFIG_CXX_EXCEPTIONS)
-        add_cxx_compile_options(-fexceptions)
+        add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-fexceptions>")
     else()
-        add_cxx_compile_options(-fno-exceptions)
+        add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>")
     endif()
 
     # Default compiler configuration
@@ -82,9 +84,7 @@ function(idf_set_global_compiler_options)
         -Wextra
         -Wno-unused-parameter
         -Wno-sign-compare)
-    add_c_compile_options(
-        -Wno-old-style-declaration
-        )
+    add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wno-old-style-declaration>")
 
     # Stack protection
     if(NOT BOOTLOADER_BUILD)
index 74d90d317d98cbba02e5744bb6fa839356d17230..b0bf847c2098f19ecb76e1c0003a35f7f539a319 100644 (file)
@@ -74,30 +74,6 @@ function(move_if_different source destination)
 
 endfunction()
 
-
-# add_compile_options variant for C++ code only
-#
-# This adds global options, set target properties for
-# component-specific flags
-function(add_cxx_compile_options)
-    foreach(option ${ARGV})
-        # note: the Visual Studio Generator doesn't support this...
-        add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${option}>)
-    endforeach()
-endfunction()
-
-# add_compile_options variant for C code only
-#
-# This adds global options, set target properties for
-# component-specific flags
-function(add_c_compile_options)
-    foreach(option ${ARGV})
-        # note: the Visual Studio Generator doesn't support this...
-        add_compile_options($<$<COMPILE_LANGUAGE:C>:${option}>)
-    endforeach()
-endfunction()
-
-
 # target_add_binary_data adds binary data into the built target,
 # by converting it to a generated source file which is then compiled
 # to a binary object as part of the build