Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy only necessary cmake macros to case #4492

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions CIME/case/case_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,30 @@ def _create_macros_cmake(
###############################################################################
if not os.path.isfile(os.path.join(caseroot, "Macros.cmake")):
safe_copy(os.path.join(cmake_macros_dir, "Macros.cmake"), caseroot)
if not os.path.exists(os.path.join(caseroot, "cmake_macros")):
shutil.copytree(cmake_macros_dir, case_cmake_path)

copy_depends_files(
mach_obj.get_machine_name(), mach_obj.machines_dir, caseroot, compiler
)
mach = mach_obj.get_machine_name()
if Config.instance().copy_all_cmake_macros:
if not os.path.exists(case_cmake_path):
shutil.copytree(cmake_macros_dir, case_cmake_path)
else:
if not os.path.exists(case_cmake_path):
os.mkdir(case_cmake_path)

# This impl is coupled to contents of Macros.cmake
macros = [
"universal.cmake",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you should include cesm. To do that you just need to add a couple more files:
${OS}.cmake
${COMPILER}_${OS}.cmake

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jedwards4b , I am happy to do so. I don't have access to you guys' Macros.cmake file, so I didn't know for sure if it had been changed to load different patterns. I will change it so that it works for both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our Macros.cmake file is generated in cime/CIME/build.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedwards4b , are you sure? I can see where the Makefile macros are generated (from the Cmake ones) but I think the cmake ones need to exist already:

        cmake_macro = os.path.join(caseroot, "Macros.cmake")
        expect(
            os.path.exists(cmake_macro),
            "Cannot generate Makefile macro without {}".format(cmake_macro),
        )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I just tried a build with this PR and it works fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedwards4b , great. So do you approve of this PR now?

compiler + ".cmake",
mach + ".cmake",
"{}_{}.cmake".format(compiler, mach),
"CMakeLists.txt",
]
for macro in macros:
repo_macro = os.path.join(cmake_macros_dir, macro)
case_macro = os.path.join(case_cmake_path, macro)
if not os.path.exists(case_macro) and os.path.exists(repo_macro):
safe_copy(repo_macro, case_cmake_path)

copy_depends_files(mach, mach_obj.machines_dir, caseroot, compiler)


###############################################################################
Expand Down
5 changes: 5 additions & 0 deletions CIME/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def __init__(self):
False,
desc="If set to `True` the model is built using using CMake otherwise Make is used.",
)
self._set_attribute(
"copy_all_cmake_macros",
True,
desc="If set to `True` copies all cmake_macros to case without trying to filter based on need.",
)
self._set_attribute(
"build_cime_component_lib",
True,
Expand Down
Loading