Browse Source

[CMAKE] Change clean_* targets to call <backend> clean

Removing CMAKE_CURRENT_BINARY_DIR directly is problematic, since it
also removes files generated by cmake and can cause errors that will
require regenerating the build system files.

Instead, call <backend> clean (e.g. make clean or ninja clean) in
CMAKE_CURRENT_BINARY_DIR. This ensures all the files generated by
the build system are removed, but any files generated as a part of
cmake's configuration step are preserved.
master
Alberto García Hierro 4 years ago
parent
commit
2e3000798b
  1. 40
      cmake/stm32.cmake

40
cmake/stm32.cmake

@ -413,28 +413,20 @@ function(target_stm32)
endif()
# clean_<target>
set(clean_target "clean_${name}")
if(CMAKE_VERSION VERSION_LESS 3.17)
if(CMAKE_HOST_SYSTEM MATCHES ".*Windows.*")
set(rm del /s /q)
set(rmdir rmdir /s /q)
else()
set(rm rm -fr)
set(rmdir ${rm})
endif()
else()
set(rm ${CMAKE_COMMAND} -E rm -fr)
set(rmdir ${rm})
endif()
add_custom_target(${clean_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${rmdir} "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND ${rm} ${main_hex_filename}
COMMAND ${rm} ${bl_hex_filename}
COMMAND ${rm} ${main_hex_filename}
COMMENT "Removing intermediate files for ${name}")
set_property(TARGET ${clean_target} PROPERTY
TARGET_MESSAGES OFF
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
set(generator_cmd "")
if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(generator_cmd "make")
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
set(generator_cmd "ninja")
endif()
if (NOT generator_cmd STREQUAL "")
set(clean_target "clean_${name}")
add_custom_target(${clean_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${generator_cmd} clean
COMMENT "Removing intermediate files for ${name}")
set_property(TARGET ${clean_target} PROPERTY
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
endfunction()
Loading…
Cancel
Save