Skip to content

Commit 36fa6a1

Browse files
authored
CMake: Centralize target linkage in source/CMakeLists.txt (#7584)
* CMake: Centralize target linkage in source/CMakeLists.txt 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 . * Fix: Some testing target are exposed unconditionally * Fix: Tests are built unconditionally * Do not pass all targets to tests * Fix: Link PEXSI properly * Fix: Missing Torch libraries in DeePKS test * Link Torch separately after the main dependency closure * Add missing GTest dependency for DeePKS test support Shared DeePKS test helpers include GoogleTest headers. * Link DeePMD to the ESolver_DP unittest * Resolve typo/mistake * Attempt: Address PEXSI testing failure * Move dependency discovery files to cmake/modules
1 parent a446d94 commit 36fa6a1

82 files changed

Lines changed: 971 additions & 671 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 21 additions & 286 deletions
Large diffs are not rendered by default.

cmake/BuildInfo.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
function(setup_build_info)
88
message(STATUS "Setting up build information...")
99

10-
include(cmake/CollectBuildInfoVars.cmake)
10+
include(${PROJECT_SOURCE_DIR}/cmake/CollectBuildInfoVars.cmake)
1111

1212
set(BUILD_INFO_TEMPLATE "${CMAKE_SOURCE_DIR}/source/source_io/build_info.h.in")
1313
set(BUILD_INFO_OUTPUT "${CMAKE_BINARY_DIR}/source/source_io/build_info.h")

cmake/Testing.cmake

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# =============================================================================
2-
# Setup Testing Environment (GTest, CTest, AddTest function)
2+
# Setup unit-test dependencies and the AddTest helper
33
# ==============================================================================
44

55
# include_guard(GLOBAL)
@@ -12,8 +12,9 @@ macro(set_if_higher VARIABLE VALUE)
1212
endmacro()
1313

1414
# Add performance test in abacus
15-
if(ENABLE_GOOGLEBENCH)
16-
set(BUILD_TESTING ON)
15+
# Benchmarks are test targets; do not make them implicitly enable the full
16+
# unit-test tree for ordinary builds.
17+
if(BUILD_TESTING AND ENABLE_GOOGLEBENCH)
1718
find_package(benchmark HINTS ${BENCHMARK_DIR})
1819
if(NOT ${benchmark_FOUND})
1920
set(BENCHMARK_USE_BUNDLED_GTEST OFF)
@@ -38,17 +39,19 @@ endif()
3839
add_coverage(${UT_TARGET})
3940
endif()
4041

41-
# dependencies & link library
42-
target_link_libraries(${UT_TARGET} PRIVATE ${UT_LIBS} Threads::Threads
43-
GTest::gtest_main GTest::gmock_main)
44-
if(ENABLE_GOOGLEBENCH)
42+
# Dependencies & link library
43+
# Share the numerical/MPI/OpenMP runtime closure but not
44+
# the optional feature closure of the final binary
45+
target_link_libraries(${UT_TARGET} PRIVATE
46+
${UT_LIBS}
47+
GTest::gtest_main
48+
GTest::gmock_main
49+
abacus::linalg_libs)
50+
if(BUILD_TESTING AND ENABLE_GOOGLEBENCH)
4551
target_link_libraries(
4652
${UT_TARGET} PRIVATE benchmark::benchmark)
4753
endif()
4854

49-
if(USE_OPENMP)
50-
target_link_libraries(${UT_TARGET} PRIVATE OpenMP::OpenMP_CXX)
51-
endif()
5255

5356
# Link to build info if needed
5457
if("${UT_SOURCES}" MATCHES "parse_args.cpp")
@@ -64,8 +67,6 @@ endif()
6467

6568
if(BUILD_TESTING)
6669
set_if_higher(CMAKE_CXX_STANDARD 14) # Required in orbital
67-
include(CTest)
68-
enable_testing()
6970
find_package(GTest HINTS /usr/local/lib/ ${GTEST_DIR})
7071
if(NOT ${GTest_FOUND})
7172
include(FetchContent)
@@ -77,7 +78,6 @@ if(BUILD_TESTING)
7778
GIT_PROGRESS TRUE)
7879
FetchContent_MakeAvailable(googletest)
7980
endif()
80-
# TODO: Try the GoogleTest module.
81-
# https://cmake.org/cmake/help/latest/module/GoogleTest.html
82-
add_subdirectory(tests) # Contains integration tests
81+
# Integration tests are registered from source/CMakeLists.txt after the
82+
# final executable has been created.
8383
endif()

0 commit comments

Comments
 (0)