@@ -27,57 +27,41 @@ 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 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 ${CONFIG_JSON_SOURCE_FILES} )
46+ if (NOT EXISTS ${CMAKE_SOURCE_DIR} /${CONFIG_JSON} )
47+ message (STATUS "Mbed: ${CONFIG_JSON} deleted or renamed, regenerating configs..." )
48+ set (MBED_NEED_TO_RECONFIGURE TRUE )
49+ break ()
50+ endif ()
51+
52+ file (TIMESTAMP ${CMAKE_SOURCE_DIR} /${CONFIG_JSON} CONFIG_JSON_TIMESTAMP "%s" UTC)
53+ if (${CONFIG_JSON_TIMESTAMP} GREATER ${MBED_CONFIG_CMAKE_TIMESTAMP} )
54+ message (STATUS "Mbed: ${CONFIG_JSON} modified, regenerating configs..." )
55+ set (MBED_NEED_TO_RECONFIGURE TRUE )
56+ break ()
57+ endif ()
58+ endforeach ()
7059endif ()
7160
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 ()
61+ # Convert all relative paths to absolute paths, rooted at CMAKE_SOURCE_DIR.
62+ # This makes sure that they are interpreted the same way everywhere.
63+ get_filename_component (MBED_APP_JSON_PATH "${MBED_APP_JSON_PATH} " ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR} )
64+ get_filename_component (CUSTOM_TARGETS_JSON_PATH "${CUSTOM_TARGETS_JSON_PATH} " ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR} )
8165
8266if (MBED_NEED_TO_RECONFIGURE)
8367 # Generate mbed_config.cmake for this target
@@ -98,13 +82,14 @@ if(MBED_NEED_TO_RECONFIGURE)
9882
9983 set (MBEDTOOLS_CONFIGURE_COMMAND ${Python3_EXECUTABLE}
10084 -m mbed_tools.cli.main
101- -v # without -v, warnings (e.g. "you have tried to override a nonexistent parameter") do not get printed
85+ -v -v # without at least -v, warnings (e.g. "you have tried to override a nonexistent parameter") do not get printed
10286 configure
10387 -t GCC_ARM # GCC_ARM is currently the only supported toolchain
10488 -m "${MBED_TARGET} "
10589 --mbed-os-path ${CMAKE_CURRENT_LIST_DIR} /../..
10690 --output -dir ${CMAKE_CURRENT_BINARY_DIR}
10791 --program -path ${CMAKE_SOURCE_DIR}
92+ --cmake-build -dir ${CMAKE_BINARY_DIR}
10893 ${APP_CONFIG_ARGUMENT}
10994 ${CUSTOM_TARGET_ARGUMENT} )
11095
@@ -126,4 +111,7 @@ if(MBED_NEED_TO_RECONFIGURE)
126111endif ()
127112
128113# Include the generated config file
129- include (${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake)
114+ include (${CMAKE_CURRENT_BINARY_DIR} /mbed_config.cmake)
115+
116+ # Make it so that if any config JSON files are modified, CMake is rerun.
117+ set_property (DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CONFIG_JSON_SOURCE_FILES} )
0 commit comments