@@ -27,57 +27,43 @@ else()
2727endif ()
2828set (MBED_INTERNAL_LAST_MBED_TARGET "${MBED_TARGET} " CACHE INTERNAL "Previous mbed target this dir was configured with" FORCE)
2929
30- # Convert all relative paths to absolute paths, rooted at CMAKE_SOURCE_DIR.
31- # This makes sure that they are interpreted the same way everywhere.
32- get_filename_component (MBED_APP_JSON_PATH "${MBED_APP_JSON_PATH} " ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR} )
33- get_filename_component (CUSTOM_TARGETS_JSON_PATH "${CUSTOM_TARGETS_JSON_PATH} " ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR} )
34-
35- # Make it so that if mbed_app.json or custom_targets.json are modified, CMake is rerun.
36- set_property (DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${MBED_APP_JSON_PATH} )
37- if (EXISTS "${CUSTOM_TARGETS_JSON_PATH} " AND (NOT IS_DIRECTORY "${CUSTOM_TARGETS_JSON_PATH} " ))
38- set_property (DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CUSTOM_TARGETS_JSON_PATH} )
39- endif ()
40-
41- # Check if mbed_app.json was modified
42- # Note: if the path is an empty string, get_filename_component(ABSOLUTE) will convert it to a directory,
43- # so we have to verify that the path we have is a file, not a dir.
44- if (EXISTS "${MBED_APP_JSON_PATH} " AND (NOT IS_DIRECTORY "${MBED_APP_JSON_PATH} " ))
45- file (TIMESTAMP "${MBED_APP_JSON_PATH} " MBED_APP_JSON_TIMESTAMP "%s" UTC)
46- else ()
47- set (MBED_APP_JSON_TIMESTAMP "<none>" )
48- endif ()
49-
50- if (NOT MBED_NEED_TO_RECONFIGURE)
51- if (NOT "${MBED_INTERNAL_LAST_MBED_APP_JSON_TIMESTAMP} " STREQUAL "${MBED_APP_JSON_TIMESTAMP} " )
52- message (STATUS "Mbed: mbed_app.json modified, regenerating configs..." )
30+ # Check if the include file is missing (e.g. because a previous attempt to generate it failed)
31+ if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake)
32+ if (NOT MBED_NEED_TO_RECONFIGURE)
33+ message (STATUS "Mbed: mbed_config.cmake not found, regenerating configs..." )
5334 set (MBED_NEED_TO_RECONFIGURE TRUE )
5435 endif ()
55- endif ()
56- set (MBED_INTERNAL_LAST_MBED_APP_JSON_TIMESTAMP "${MBED_APP_JSON_TIMESTAMP} " CACHE INTERNAL "Previous UTC modification timestamp for mbed_app.json" FORCE)
57-
58- # Check if custom_targets.json was modified
59- if (EXISTS "${CUSTOM_TARGETS_JSON_PATH} " AND (NOT IS_DIRECTORY "${CUSTOM_TARGETS_JSON_PATH} " ))
60- file (TIMESTAMP "${CUSTOM_TARGETS_JSON_PATH} " CUSTOM_TARGETS_JSON_TIMESTAMP "%s" UTC)
6136else ()
62- set (CUSTOM_TARGETS_JSON_TIMESTAMP "<none>" )
37+ # Include the old version of mbed_config.cmake to get the MBED_CONFIG_JSON_SOURCE_FILES variable used below
38+ include (${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake)
6339endif ()
6440
41+ # Check timestamps on all JSON files used to generate the Mbed configuration
6542if (NOT MBED_NEED_TO_RECONFIGURE)
66- if (NOT "${MBED_INTERNAL_LAST_CUSTOM_TARGETS_JSON_TIMESTAMP} " STREQUAL "${CUSTOM_TARGETS_JSON_TIMESTAMP} " )
67- message (STATUS "Mbed: custom_targets.json modified, regenerating configs..." )
68- set (MBED_NEED_TO_RECONFIGURE TRUE )
69- endif ()
43+ file (TIMESTAMP ${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake MBED_CONFIG_CMAKE_TIMESTAMP "%s" UTC)
44+
45+ foreach (CONFIG_JSON ${MBED_CONFIG_JSON_SOURCE_FILES} )
46+ get_filename_component (CONFIG_JSON_ABSPATH ${CONFIG_JSON} ABSOLUTE )
47+
48+ if (NOT EXISTS ${CONFIG_JSON_ABSPATH} )
49+ message (STATUS "Mbed: ${CONFIG_JSON} deleted or renamed, regenerating configs..." )
50+ set (MBED_NEED_TO_RECONFIGURE TRUE )
51+ break ()
52+ endif ()
53+
54+ file (TIMESTAMP ${CONFIG_JSON_ABSPATH} CONFIG_JSON_TIMESTAMP "%s" UTC)
55+ if (${CONFIG_JSON_TIMESTAMP} GREATER ${MBED_CONFIG_CMAKE_TIMESTAMP} )
56+ message (STATUS "Mbed: ${CONFIG_JSON} modified, regenerating configs..." )
57+ set (MBED_NEED_TO_RECONFIGURE TRUE )
58+ break ()
59+ endif ()
60+ endforeach ()
7061endif ()
7162
72- set (MBED_INTERNAL_LAST_CUSTOM_TARGETS_JSON_TIMESTAMP "${CUSTOM_TARGETS_JSON_TIMESTAMP} " CACHE INTERNAL "Previous UTC modification timestamp for custom_targets.json" FORCE)
73-
74- # Check if the include file is missing (e.g. because a previous attempt to generate it failed)
75- if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake)
76- if (NOT MBED_NEED_TO_RECONFIGURE)
77- message (STATUS "Mbed: mbed_config.cmake not found, regenerating configs..." )
78- set (MBED_NEED_TO_RECONFIGURE TRUE )
79- endif ()
80- endif ()
63+ # Convert all relative paths to absolute paths, rooted at CMAKE_SOURCE_DIR.
64+ # This makes sure that they are interpreted the same way everywhere.
65+ get_filename_component (MBED_APP_JSON_PATH "${MBED_APP_JSON_PATH} " ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR} )
66+ get_filename_component (CUSTOM_TARGETS_JSON_PATH "${CUSTOM_TARGETS_JSON_PATH} " ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR} )
8167
8268if (MBED_NEED_TO_RECONFIGURE)
8369 # Generate mbed_config.cmake for this target
@@ -98,7 +84,7 @@ if(MBED_NEED_TO_RECONFIGURE)
9884
9985 set (MBEDTOOLS_CONFIGURE_COMMAND ${Python3_EXECUTABLE}
10086 -m mbed_tools.cli.main
101- -v # without -v, warnings (e.g. "you have tried to override a nonexistent parameter") do not get printed
87+ -v -v # without at least -v, warnings (e.g. "you have tried to override a nonexistent parameter") do not get printed
10288 configure
10389 -t GCC_ARM # GCC_ARM is currently the only supported toolchain
10490 -m "${MBED_TARGET} "
@@ -126,4 +112,7 @@ if(MBED_NEED_TO_RECONFIGURE)
126112endif ()
127113
128114# Include the generated config file
129- include (${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake)
115+ include (${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake)
116+
117+ # Make it so that if any config JSON files are modified, CMake is rerun.
118+ set_property (DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${MBED_CONFIG_JSON_SOURCE_FILES} )
0 commit comments