diff --git a/Help/release/dev/FindPatch.rst b/Help/release/dev/FindPatch.rst new file mode 100644 index 0000000000..31efa66add --- /dev/null +++ b/Help/release/dev/FindPatch.rst @@ -0,0 +1,5 @@ +FindPatch +--------- + +* The :module:`FindPatch` module now supports running in script mode by skipping + the creation of the imported target. diff --git a/Modules/FindPatch.cmake b/Modules/FindPatch.cmake index 62277f8959..65a21bee30 100644 --- a/Modules/FindPatch.cmake +++ b/Modules/FindPatch.cmake @@ -19,6 +19,9 @@ The following :prop_tgt:`IMPORTED` targets are also defined: ``Patch::patch`` The command-line executable. + .. versionchanged:: 3.32 + Imported target is defined only when :prop_gbl:`CMAKE_ROLE` is ``PROJECT``. + Example usage: .. code-block:: cmake @@ -60,12 +63,19 @@ endif() mark_as_advanced(Patch_EXECUTABLE) -if(Patch_EXECUTABLE AND NOT TARGET Patch::patch) +get_property(_patch_role GLOBAL PROPERTY CMAKE_ROLE) + +if( + _patch_role STREQUAL "PROJECT" + AND Patch_EXECUTABLE + AND NOT TARGET Patch::patch +) add_executable(Patch::patch IMPORTED) set_property(TARGET Patch::patch PROPERTY IMPORTED_LOCATION ${Patch_EXECUTABLE}) endif() unset(_patch_path) +unset(_patch_role) unset(_doc) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)