Skip to content

Commit b0a9ab3

Browse files
authored
Merge pull request #676 from caic99/develop
Test: UTs only build with related sources
2 parents 674cd11 + f140995 commit b0a9ab3

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ trim_trailing_whitespace = true
1010

1111
[*.yaml]
1212
indent_size = 2
13+
14+
[CMakeLists.txt]
15+
indent_style = space
16+
indent_size = 2

CMakeLists.txt

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ find_package(MPI REQUIRED)
4242
include_directories(${MPI_CXX_INCLUDE_PATH})
4343
target_link_libraries(${ABACUS_BIN_NAME} MPI::MPI_CXX)
4444
add_compile_definitions(__MPI)
45+
list(APPEND math_libs MPI::MPI_CXX)
4546

4647
find_package(Threads REQUIRED)
4748
target_link_libraries(${ABACUS_BIN_NAME} Threads::Threads)
@@ -132,48 +133,41 @@ if(ENABLE_ASAN)
132133
-fsanitize=address
133134
)
134135
# `add_link_options` only affects executables added after.
135-
target_link_libraries(${ABACUS_BIN_NAME}
136-
-fsanitize=address
137-
)
136+
target_link_libraries(${ABACUS_BIN_NAME} -fsanitize=address)
138137
endif()
139138

140139
if(DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT)
141140
set(MKLROOT "$ENV{MKLROOT}")
142141
endif()
143142
if(MKLROOT)
144143
find_package(IntelMKL REQUIRED)
145-
add_definitions(-D__MKL -DMKL_ILP64)
144+
add_definitions(-D__MKL)
146145
include_directories(${MKL_INCLUDE_DIRS} ${MKL_INCLUDE_DIRS}/fftw)
147146

148147
# Since libtorch will find its own MKL, the fftw part conflicts with the original one.
149148
# When enable deepks, mkl will be linked within ${TORCH_LIBRARIES}.
150-
if(ENABLE_DEEPKS)
151-
target_link_libraries(${ABACUS_BIN_NAME}
152-
-lifcore
153-
# IntelMKL::MKL
154-
)
155-
else()
156-
target_link_libraries(${ABACUS_BIN_NAME}
157-
-lifcore
158-
IntelMKL::MKL
159-
)
149+
if(NOT ENABLE_DEEPKS)
150+
list(APPEND math_libs IntelMKL::MKL)
160151
endif()
161152
else()
162153
find_package(FFTW3 REQUIRED)
163154
find_package(LAPACK REQUIRED)
164155
find_package(ScaLAPACK REQUIRED)
165156
include_directories(${FFTW3_INCLUDE_DIRS})
166-
target_link_libraries(${ABACUS_BIN_NAME}
157+
list(APPEND math_libs
167158
FFTW3::FFTW3
168159
LAPACK::LAPACK
169160
ScaLAPACK::ScaLAPACK
170161
)
171-
if(CMAKE_COMPILER_IS_GNUCXX)
172-
target_link_libraries(${ABACUS_BIN_NAME}
173-
-lgfortran
174-
)
162+
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
163+
list(APPEND math_libs -lgfortran)
164+
elseif(CMAKE_CXX_COMPILER_ID MATCHES Intel)
165+
list(APPEND math_libs -lifcore)
166+
else()
167+
message(WARNING "Cannot find the correct library for Fortran.")
175168
endif()
176169
endif()
170+
target_link_libraries(${ABACUS_BIN_NAME} ${math_libs})
177171

178172
if(ENABLE_DEEPKS)
179173
set(CMAKE_CXX_STANDARD 14)
@@ -245,22 +239,19 @@ IF (BUILD_TESTING)
245239
# https://cmake.org/cmake/help/latest/module/GoogleTest.html
246240
add_subdirectory(tests) # Contains integration tests
247241

242+
function(AddTest) # function for UT
243+
cmake_parse_arguments(UT "DYN" "TARGET" "LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN})
244+
add_executable(${UT_TARGET} ${UT_SOURCES})
245+
#dependencies & link library
246+
target_link_libraries(${UT_TARGET} ${UT_LIBS}
247+
OpenMP::OpenMP_CXX pthread GTest::gtest_main GTest::gmock_main)
248+
install(TARGETS ${UT_TARGET} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../../../tests )
249+
add_test(NAME ${UT_TARGET}
250+
COMMAND ${UT_TARGET}
251+
WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET}>
252+
)
253+
endfunction(AddTest)
248254
endif()
249-
function(AddTest)
250-
cmake_parse_arguments(UT "DYN" "TARGET" "LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN})
251-
add_executable(${UT_TARGET} ${UT_SOURCES})
252-
#dependencies & link library
253-
get_target_property(ABACUS_LINK_LIBRARIES ${ABACUS_BIN_NAME} LINK_LIBRARIES)
254-
target_link_libraries(${UT_TARGET} ${UT_LIBS} ${ABACUS_LINK_LIBRARIES}
255-
base cell symmetry md
256-
neighbor orb io ions lcao parallel mrrr pdiag pw ri driver
257-
pthread GTest::gtest_main GTest::gmock_main)
258-
install(TARGETS ${UT_TARGET} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../../../tests )
259-
add_test(NAME ${UT_TARGET}
260-
COMMAND ${UT_TARGET}
261-
WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET}>
262-
)
263-
endfunction(AddTest)
264255

265256
add_subdirectory(source)
266257

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
remove_definitions(-D__MPI)
12
AddTest(
23
TARGET base_matrix3
3-
SOURCES matrix3_test.cpp
4+
LIBS ${math_libs}
5+
SOURCES matrix3_test.cpp ../matrix3.cpp ../matrix.cpp ../tool_quit.cpp ../global_variable.cpp ../global_file.cpp ../memory.cpp ../timer.cpp
46
)
57
AddTest(
68
TARGET base_blas_connector
9+
LIBS ${math_libs}
710
SOURCES blas_connector_test.cpp
811
)
912
AddTest(
1013
TARGET base_complexarray
11-
SOURCES complexarray_test.cpp
14+
SOURCES complexarray_test.cpp ../complexarray.cpp
1215
)
1316
AddTest(
1417
TARGET tool_check
15-
SOURCES tool_check_test.cpp
18+
SOURCES tool_check_test.cpp ../tool_check.cpp ../tool_quit.cpp ../global_variable.cpp ../global_file.cpp ../memory.cpp ../timer.cpp
1619
)
1720
AddTest(
1821
TARGET tool_quit
19-
SOURCES tool_quit_test.cpp
22+
SOURCES tool_quit_test.cpp ../tool_quit.cpp ../global_variable.cpp ../global_file.cpp ../memory.cpp ../timer.cpp
2023
)

0 commit comments

Comments
 (0)