From b7a0fe28ccfc2f8f47339d1d7b86c2fa0b8d9efa Mon Sep 17 00:00:00 2001
From: hanchuan <whc.shmily@gmail.com>
Date: Wed, 23 Feb 2022 09:01:55 +0100
Subject: [PATCH] [bin][extractmodule] copy the cmake module folder from parent
 module and rename the macro file

---
 bin/extract_as_new_module.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/bin/extract_as_new_module.py b/bin/extract_as_new_module.py
index dcc59af2a0..f7d2c46d67 100755
--- a/bin/extract_as_new_module.py
+++ b/bin/extract_as_new_module.py
@@ -13,6 +13,7 @@ import argparse
 import shutil
 import textwrap
 import itertools
+import glob
 import multiprocessing as mp
 from distutils.dir_util import copy_tree
 from pathlib import Path
@@ -638,6 +639,16 @@ if __name__ == "__main__":
         newModulePath,
     )
 
+    # get the CMake macro file name of the new module
+    cmakeMacroPattern = os.path.join(newModulePath, "cmake/modules/*Macros.cmake")
+    sourceCMakeMacroName = glob.glob(cmakeMacroPattern)[0]
+    # remove the generated CMake directory and copy the one from the source module
+    shutil. rmtree(os.path.join(newModulePath, "cmake"))
+    copySubFolders(["cmake"], modulePath, newModulePath)
+    # get the name of the extracted CMake macro file name and rename it to match the new module name
+    newModuleCMakeMacroFile = glob.glob(cmakeMacroPattern)[0]
+    os.rename(newModuleCMakeMacroFile, sourceCMakeMacroName)
+
     # guide user through removal of possibly unnecessary folders
     foldersWithoutSources = foldersWithoutSourceFiles(
         newModulePath, subFolder, newHeaders + newSourceFiles
-- 
GitLab