Skip to content

CMake: Centralize target linkage in source/CMakeLists.txt#7584

Open
Growl1234 wants to merge 10 commits into
deepmodeling:developfrom
Growl1234:cmake
Open

CMake: Centralize target linkage in source/CMakeLists.txt#7584
Growl1234 wants to merge 10 commits into
deepmodeling:developfrom
Growl1234:cmake

Conversation

@Growl1234

@Growl1234 Growl1234 commented Jul 3, 2026

Copy link
Copy Markdown

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #7585.

Unit Tests and/or Case Tests for my changes

  • A unit test is added for each new feature or bug fix.

What's changed?

This refactors the CMake layout so that the top-level CMakeLists.txt is limited to project configuration: options, feature resolution, platform/compiler setup, and package discovery.

Target construction and linkage are centralized in source/CMakeLists.txt, which now owns:

  • the common linear-algebra dependency interface;
  • optional external feature dependencies;
  • the final external link closure;
  • the ABACUS executable and its ordered internal target linkage;
  • unit-test setup and registration of the top-level integration tests.

The final link closure is kept in one explicit location. Its order is part of the build contract, especially for static or mixed static/shared builds:

  1. internal ABACUS targets, from higher-level consumers to lower-level providers;
  2. optional external feature libraries;
  3. numerical backends and their MPI, OpenMP, compiler-runtime, and system dependencies.

Dependencies are therefore no longer accumulated through the legacy ${math_libs} path or scattered between the root CMakeLists.txt, test directories, and setup modules. The old global OpenMP flag/link-option handling is also removed in favour of imported targets and their usage requirements.

The top-level integration-test directory is registered only after the final executable and its path are available. No integration-test cases are changed.

This is a structural cleanup only. It does not touch dependency discovery or change the current provider-selection logic, part of which need to be revised seperately .

Any changes of core modules? (ignore if not applicable)

  • Example: I have added a new virtual function in the esolver base class in order to ...

Copilot AI review requested due to automatic review settings July 3, 2026 04:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the CMake build layout to centralize all ABACUS target construction and final link ordering in source/CMakeLists.txt, leaving the top-level CMakeLists.txt focused on option/package discovery and feature resolution. It also updates unit-test CMake fragments to stop manually appending ${math_libs} and instead rely on the centralized link interface.

Changes:

  • Introduces centralized dependency interface targets (abacus::linalg_libs, abacus::feature_libs, abacus::link_libs) and moves the ABACUS executable + final ordered link closure into source/CMakeLists.txt.
  • Updates the AddTest() helper to link tests against abacus::link_libs, and removes ${math_libs} from many per-test LIBS lists.
  • Adjusts auxiliary CMake modules to align with the new “centralized linkage” model (e.g., NCCL/cuBLASMp/cuSOLVERMp setup and build-info include path).

Reviewed changes

Copilot reviewed 62 out of 65 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
source/source_relax/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists to rely on centralized link interface.
source/source_relax/CMakeLists.txt Whitespace-only cleanup.
source/source_pw/module_stodft/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_pw/module_pwdft/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_pw/module_pwdft/kernels/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_psi/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_md/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_rt/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_ri/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists / normalizes ordering.
source/source_lcao/module_ri/module_exx_symmetry/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_ri/module_exx_symmetry/CMakeLists.txt Whitespace-only cleanup.
source/source_lcao/module_ri/CMakeLists.txt Whitespace-only cleanup.
source/source_lcao/module_operator_lcao/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_lr/utils/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_lr/ri_benchmark/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_lr/dm_trans/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_lr/ao_to_mo_transformer/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_hcontainer/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_gint/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_dftu/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_deltaspin/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_lcao/module_deepks/test/CMakeLists.txt Removes ${math_libs} from the DEEPKS unit-test library list.
source/source_io/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_io/test_serial/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_io/module_json/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_hsolver/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists (incl. ELPA/PEXSI branches).
source/source_hsolver/kernels/test/CMakeLists.txt Removes ${math_libs} from unit-test/perf-test link lists.
source/source_hamilt/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists; formatting cleanup.
source/source_hamilt/module_xc/test/CMakeLists.txt Removes ${math_libs} from XC unit-test link lists; formatting cleanup.
source/source_hamilt/module_xc/kernels/test/CMakeLists.txt Removes ${math_libs} from XC kernels unit-test link lists.
source/source_hamilt/module_vdw/test/CMakeLists.txt Removes ${math_libs} from vdw unit-test link lists.
source/source_hamilt/module_surchem/test/CMakeLists.txt Removes ${math_libs} from surchem unit-test link lists.
source/source_estate/test/CMakeLists.txt Removes ${math_libs} from elecstate unit-test link lists.
source/source_estate/test_mpi/CMakeLists.txt Removes ${math_libs} from MPI unit-test link lists.
source/source_estate/module_dm/test/CMakeLists.txt Removes ${math_libs} from dm unit-test link lists.
source/source_estate/kernels/test/CMakeLists.txt Removes ${math_libs} from kernels unit-test link lists.
source/source_esolver/test/CMakeLists.txt Removes ${math_libs} from esolver unit-test link lists.
source/source_cell/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_cell/test_pw/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_cell/module_symmetry/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_cell/module_neighlist/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_cell/module_neighbor/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_basis/module_pw/test/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_basis/module_pw/test_serial/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_basis/module_pw/test_gpu/CMakeLists.txt Removes ${math_libs} from unit-test link lists.
source/source_basis/module_pw/kernels/test/CMakeLists.txt Removes ${math_libs} from kernels unit-test link lists.
source/source_basis/module_nao/test/CMakeLists.txt Removes ${math_libs} from NAO unit-test link lists.
source/source_basis/module_ao/test/CMakeLists.txt Removes ${math_libs} from AO unit-test link lists.
source/source_base/test/CMakeLists.txt Removes ${math_libs} from base unit-test link lists.
source/source_base/test_parallel/CMakeLists.txt Removes ${math_libs} from parallel unit-test link lists.
source/source_base/module_mixing/test/CMakeLists.txt Removes ${math_libs} from mixing unit-test link lists.
source/source_base/module_grid/test/CMakeLists.txt Drops ${math_libs} link list from grid unit test (now relies on centralized closure).
source/source_base/module_device/test/CMakeLists.txt Removes ${math_libs} from device unit-test link lists.
source/source_base/module_container/test/CMakeLists.txt Removes ${math_libs} from container unit-test link lists.
source/source_base/module_container/ATen/ops/test/CMakeLists.txt Removes ${math_libs} from ops unit-test link lists.
source/source_base/module_container/ATen/kernels/test/CMakeLists.txt Removes ${math_libs} from kernels unit-test link lists.
source/source_base/kernels/test/CMakeLists.txt Removes ${math_libs} from kernels unit-test link lists.
source/CMakeLists.txt New central “single source of truth” for ABACUS target linkage, dependency interfaces, final ordered link closure, and test registration.
CMakeLists.txt Refocuses top-level configuration on options/packages/feature resolution; moves target construction/linkage into source/.
cmake/Testing.cmake Updates AddTest() to link with abacus::link_libs and removes per-test OpenMP/Threads handling.
cmake/SetupNccl.cmake Adjusts NCCL setup function signature to align with centralized linkage.
cmake/SetupCuSolverMp.cmake Adjusts cuSOLVERMp setup function signature; stops directly linking into the old global deps interface.
cmake/SetupCuBlasMp.cmake Adjusts cuBLASMp setup function signature; stops directly linking into the old global deps interface.
cmake/BuildInfo.cmake Uses ${PROJECT_SOURCE_DIR} for a stable include path to CollectBuildInfoVars.cmake.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/CMakeLists.txt Outdated
@Growl1234

Growl1234 commented Jul 3, 2026

Copy link
Copy Markdown
Author

The testing failure seems to be related to conflict symbols between OpenBLAS and pre-built libtorch:

Details
327: [ RUN      ] 025_PW_DS_sca
327: [c2fdeac92c3f:21720] *** Process received signal ***
327: [c2fdeac92c3f:21720] Signal: Segmentation fault (11)
327: [c2fdeac92c3f:21720] Signal code: Address not mapped (1)
327: [c2fdeac92c3f:21720] Failing at address: 0x10
327: [c2fdeac92c3f:21720] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7fdc7d746520]
327: [c2fdeac92c3f:21720] [ 1] /opt/libtorch/lib/libtorch_cpu.so(ZDOTC+0x1f)[0x7fdc87b8facf]
327: [c2fdeac92c3f:21720] [ 2] /lib/x86_64-linux-gnu/libscalapack-openmpi.so.2.1(pzpotf2_+0x4a5)[0x7fdc80e25ea5]
327: [c2fdeac92c3f:21720] [ 3] /lib/x86_64-linux-gnu/libscalapack-openmpi.so.2.1(pzpotrf_+0x34c)[0x7fdc80e2687c]
327: [c2fdeac92c3f:21720] [ 4] /lib/x86_64-linux-gnu/libscalapack-openmpi.so.2.1(pzhegvx_+0xcbc)[0x7fdc80dcf8dc]
327: [c2fdeac92c3f:21720] [ 5] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x233305)[0x55cf04adb305]
327: [c2fdeac92c3f:21720] [ 6] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x236117)[0x55cf04ade117]
327: [c2fdeac92c3f:21720] [ 7] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x211261)[0x55cf04ab9261]
327: [c2fdeac92c3f:21720] [ 8] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x212585)[0x55cf04aba585]
327: [c2fdeac92c3f:21720] [ 9] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x2131d3)[0x55cf04abb1d3]
327: [c2fdeac92c3f:21720] [10] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x21fae4)[0x55cf04ac7ae4]
327: [c2fdeac92c3f:21720] [11] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x2234d6)[0x55cf04acb4d6]
327: [c2fdeac92c3f:21720] [12] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x141afe)[0x55cf049e9afe]
327: [c2fdeac92c3f:21720] [13] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x13c30a)[0x55cf049e430a]
327: [c2fdeac92c3f:21720] [14] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x13c8eb)[0x55cf049e48eb]
327: [c2fdeac92c3f:21720] [15] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x3e0252)[0x55cf04c88252]
327: [c2fdeac92c3f:21720] [16] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x1390ff)[0x55cf049e10ff]
327: [c2fdeac92c3f:21720] [17] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x133fba)[0x55cf049dbfba]
327: [c2fdeac92c3f:21720] [18] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x134170)[0x55cf049dc170]
327: [c2fdeac92c3f:21720] [19] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x131f79)[0x55cf049d9f79]
327: [c2fdeac92c3f:21720] [20] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7fdc7d72dd90]
327: [c2fdeac92c3f:21720] [21] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7fdc7d72de40]
327: [c2fdeac92c3f:21720] [22] /__w/abacus-develop/abacus-develop/build/source/abacus_max_para(+0x1325b5)[0x55cf049da5b5]
327: [c2fdeac92c3f:21720] *** End of error message ***

@Growl1234 Growl1234 marked this pull request as ready for review July 3, 2026 07:33
@Growl1234 Growl1234 force-pushed the cmake branch 2 times, most recently from 23f3d5a to 5721bbb Compare July 3, 2026 09:41
@Growl1234

Copy link
Copy Markdown
Author

Are there still ways I can make the current checklist green?

Growl1234 added 8 commits July 4, 2026 13:20
This refactors the CMake layout so that the top-level CMakeLists.txt is limited
to project configuration: options, feature resolution, platform/compiler setup,
and package discovery.

Target construction and linkage are centralized in source/CMakeLists.txt, which
now owns:

- the common linear-algebra dependency interface;
- optional external feature dependencies;
- the final external link closure;
- the ABACUS executable and its ordered internal target linkage;
- unit-test setup and registration of the top-level integration tests.

The final link closure is kept in one explicit location. Its order is part of
the build contract, especially for static or mixed static/shared builds:

1. internal ABACUS targets, from higher-level consumers to lower-level
   providers;
2. optional external feature libraries;
3. numerical backends and their MPI, OpenMP, compiler-runtime, and system
   dependencies.

Dependencies are therefore no longer accumulated through the legacy
`${math_libs}` path or scattered between the root CMakeLists.txt, test
directories, and setup modules. The old global OpenMP flag/link-option handling
is also removed in favour of imported targets and their usage requirements.

The top-level integration-test directory is registered only after the final
executable and its path are available. No integration-test cases are changed.

This is a structural cleanup only. It does not redesign dependency discovery or
change the current provider-selection logic for MKL, cuSOLVERMp, PEXSI, ELPA,
FFTW, ScaLAPACK, KML, or GPU dependencies, part of which need to be revised
seperately .
Shared DeePKS test helpers include GoogleTest headers.
Comment thread source/source_basis/module_pw/test_gpu/CMakeLists.txt
Comment thread cmake/Testing.cmake Outdated
Comment thread source/CMakeLists.txt
Comment thread source/CMakeLists.txt
set(_abacus_feature_include_dirs)
set(_abacus_feature_compile_options)

if(ENABLE_RAPIDJSON)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No .so files in Rapidjson?

@Growl1234 Growl1234 Jul 4, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, a guard in configuration step is missing; fortunately, #7583 has added it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CMake configure fails when CUDA tests are enabled without ENABLE_FLOAT_FFTW

5 participants