Skip to content

Commit bcca20f

Browse files
committed
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 .
1 parent 59dc884 commit bcca20f

65 files changed

Lines changed: 765 additions & 607 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: 13 additions & 282 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/SetupCuBlasMp.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
include_guard(GLOBAL)
66

7-
function(abacus_setup_cublasmp target_name)
7+
function(abacus_setup_cublasmp)
88
abacus_add_feature_definitions(__CUBLASMP)
99

1010
# 1. Search for cuBLASMp library and header files
@@ -72,7 +72,4 @@ function(abacus_setup_cublasmp target_name)
7272
INTERFACE_INCLUDE_DIRECTORIES "${CUBLASMP_INCLUDE_DIR}")
7373
endif()
7474

75-
# 5. Propagate library usage requirements to all ABACUS targets.
76-
target_link_libraries(abacus_external_deps INTERFACE cublasMp::cublasMp)
77-
7875
endfunction()

cmake/SetupCuSolverMp.cmake

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
include_guard(GLOBAL)
66

7-
function(abacus_setup_cusolvermp target_name)
7+
function(abacus_setup_cusolvermp)
88
abacus_add_feature_definitions(__CUSOLVERMP)
99

1010
# Find cuSOLVERMp first, then decide communicator backend.
@@ -126,10 +126,4 @@ function(abacus_setup_cusolvermp target_name)
126126
INTERFACE_INCLUDE_DIRECTORIES "${CUSOLVERMP_INCLUDE_DIR}")
127127
endif()
128128

129-
# === Link libraries and propagate include directories ===
130-
if(_use_cal)
131-
target_link_libraries(abacus_external_deps INTERFACE CAL::CAL cusolverMp::cusolverMp)
132-
else()
133-
target_link_libraries(abacus_external_deps INTERFACE NCCL::NCCL cusolverMp::cusolverMp)
134-
endif()
135129
endfunction()

cmake/SetupNccl.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include_guard(GLOBAL)
22

33
include(CheckIncludeFileCXX)
44

5-
function(abacus_setup_nccl target_name)
5+
function(abacus_setup_nccl)
66
find_library(NCCL_LIBRARY NAMES nccl
77
HINTS ${NCCL_PATH} ${NVHPC_ROOT_DIR}
88
PATH_SUFFIXES lib lib64 comm_libs/nccl/lib)
@@ -39,5 +39,4 @@ function(abacus_setup_nccl target_name)
3939
endif()
4040
endif()
4141

42-
target_link_libraries(abacus_external_deps INTERFACE NCCL::NCCL)
4342
endfunction()

cmake/Testing.cmake

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ endif()
3939
endif()
4040

4141
# dependencies & link library
42-
target_link_libraries(${UT_TARGET} PRIVATE ${UT_LIBS} Threads::Threads
43-
GTest::gtest_main GTest::gmock_main)
42+
target_link_libraries(${UT_TARGET} PRIVATE
43+
${UT_LIBS}
44+
GTest::gtest_main
45+
GTest::gmock_main
46+
abacus::link_libs)
4447
if(ENABLE_GOOGLEBENCH)
4548
target_link_libraries(
4649
${UT_TARGET} PRIVATE benchmark::benchmark)
4750
endif()
4851

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

5353
# Link to build info if needed
5454
if("${UT_SOURCES}" MATCHES "parse_args.cpp")
@@ -64,7 +64,6 @@ endif()
6464

6565
if(BUILD_TESTING)
6666
set_if_higher(CMAKE_CXX_STANDARD 14) # Required in orbital
67-
include(CTest)
6867
enable_testing()
6968
find_package(GTest HINTS /usr/local/lib/ ${GTEST_DIR})
7069
if(NOT ${GTest_FOUND})
@@ -79,5 +78,4 @@ if(BUILD_TESTING)
7978
endif()
8079
# TODO: Try the GoogleTest module.
8180
# https://cmake.org/cmake/help/latest/module/GoogleTest.html
82-
add_subdirectory(tests) # Contains integration tests
8381
endif()

0 commit comments

Comments
 (0)