Skip to content

Commit f671ce1

Browse files
authored
[Feature]A new -i/-I/--info argument to show details of configuration and compilation (#6734)
* Add build info printing and update argument parsing Added a function to print detailed build information, including version, compiler info, and library support. Updated argument parsing to include a new option for displaying build info. * Add header guards and update ModuleIO namespace Added header guards and updated namespace for ModuleIO. * Add build_info.h.in for build configuration details * Enhance build info collection in CMakeLists.txt Refactor CMakeLists.txt to improve build information collection and include RapidJSON path. * Add support for '-I' option in argument parsing * Fix typo and enhance documentation in parse_args.h Updated function documentation for clarity and corrected a typo. * Refactor para_json.h for JSON handling Removed unused functions and added new JSON-related functions. * Add script to generate build_info.h for builds This script generates a build_info.h file for Makefile-based builds by detecting system information, compiler flags, and library versions. * Enhance Makefile with build info generation rules Added rules for generating build_info.h and enforcing dependencies. * Add command to remove build directory before cmake * Remove build directory before cmake commands * Fix paths in Makefile for build_info generation * Update input and output file paths in script * Update build_test_makefile.yml * Refactor LCAO algorithm support check * Update preprocessor directives for commit info * Fix preprocessor directive syntax for COMMIT * Add include path for build_info.h in test target Add conditional include path for parse_args.cpp in test target. * Update CMakeLists.txt * Create Testing.cmake * Create CollectBuildInfoVars.cmake * Add BuildInfo.cmake for generating build info header * Update generate_build_info.sh * Update Makefile * Fix indentation in Makefile for parse_args.o rule * Change target_link_libraries to PRIVATE for UT_TARGET * Update Makefile * Update Testing.cmake * Update Makefile * Update build_test_makefile.yml * Update Makefile * Update Testing.cmake * Update Testing.cmake * Link io_basic library with BuildInfo::Headers * target_link_libraries( io_basic PUBLIC BuildInfo::Headers ) * Update CMakeLists.txt * Add ABACUS_ROOT variable to Makefile * Update Makefile * Update CMakeLists.txt * Fix formatting in Makefile for variable assignments * Update CMakeLists.txt * Update CMakeLists.txt * Update Testing.cmake * Update CMakeLists.txt * Update CMakeLists.txt * Update BuildInfo.cmake * Update BuildInfo.cmake * Update Testing.cmake * Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt * Update parse_args_test.cpp * Update parse_args_test.cpp * Update test.yml * Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt * Update .gitignore * Update test.yml * Update FindFFTW3.cmake * Update CollectBuildInfoVars.cmake * Update CollectBuildInfoVars.cmake * Update generate_build_info.sh * Update Testing.cmake * Update Testing.cmake * Update CMakeLists.txt * Update Testing.cmake * Update parse_args_test.cpp * Update parse_args_test.cpp * Update parse_args_test.cpp * Update parse_args_test.cpp
1 parent a4f4678 commit f671ce1

18 files changed

+1228
-161
lines changed

.github/workflows/build_test_cmake.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ jobs:
5454
export PKG_CONFIG_PATH=${GKLIB_ROOT}/lib/pkgconfig:${METIS32_ROOT}/lib/pkgconfig:${PARMETIS32_ROOT}/lib/pkgconfig:${SUPERLU32_DIST_ROOT}/lib/pkgconfig:${PEXSI32_ROOT}/lib/pkgconfig:${PKG_CONFIG_PATH}
5555
export CPATH=${GKLIB_ROOT}/include:${METIS32_ROOT}/include:${PARMETIS32_ROOT}/include:${SUPERLU32_DIST_ROOT}/include:${PEXSI32_ROOT}/include:${CPATH}
5656
export CMAKE_PREFIX_PATH=${PEXSI32_ROOT}:${SUPERLU_DIST32_ROOT}:${PARMETIS32_ROOT}:${METIS32_ROOT}:${GKLIB_ROOT}:${CMAKE_PREFIX_PATH}
57+
rm -rf build
5758
cmake -B build ${{ matrix.build_args }}
5859
cmake --build build -j2

.github/workflows/build_test_makefile.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
- name: Build
2121
run: |
2222
export I_MPI_CXX=icpx
23+
chmod a+x generate_build_info.sh
2324
cd source
24-
make -j2 ${{ matrix.build_args }}
25+
mkdir build && cd build
26+
make -f ../Makefile -j2 ${{ matrix.build_args }}
2527

.github/workflows/cuda.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- name: Build
3434
run: |
3535
nvidia-smi
36+
rm -rf build
3637
cmake -B build -DUSE_CUDA=ON -DBUILD_TESTING=ON
3738
cmake --build build -j4
3839
cmake --install build

.github/workflows/test.yml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,130 +60,130 @@ jobs:
6060
GTEST_COLOR: 'yes'
6161
OMP_NUM_THREADS: '2'
6262
run: |
63-
cmake --build build --target test ARGS="-V --timeout 1700 -R integrated_test"
64-
63+
ctest --test-dir build -V --timeout 1700 -R integrated_test
64+
6565
- name: Module_Base Unittests
6666
env:
6767
GTEST_COLOR: 'yes'
6868
OMP_NUM_THREADS: '2'
6969
run: |
70-
cmake --build build --target test ARGS="-V --timeout 1700 -R MODULE_BASE"
71-
70+
ctest --test-dir build -V --timeout 1700 -R MODULE_BASE
71+
7272
- name: Module_IO Unittests
7373
env:
7474
GTEST_COLOR: 'yes'
7575
OMP_NUM_THREADS: '2'
7676
run: |
77-
cmake --build build --target test ARGS="-V --timeout 1700 -R MODULE_IO"
78-
77+
ctest --test-dir build -V --timeout 1700 -R MODULE_IO
78+
7979
- name: Module_HSolver Unittests
8080
env:
8181
GTEST_COLOR: 'yes'
8282
OMP_NUM_THREADS: '2'
8383
run: |
84-
cmake --build build --target test ARGS="-V --timeout 1700 -R MODULE_HSOLVER"
85-
84+
ctest --test-dir build -V --timeout 1700 -R MODULE_HSOLVER
85+
8686
- name: Module_Cell Unittests
8787
env:
8888
GTEST_COLOR: 'yes'
8989
OMP_NUM_THREADS: '2'
9090
run: |
91-
cmake --build build --target test ARGS="-V --timeout 1700 -R MODULE_CELL"
92-
91+
ctest --test-dir build -V --timeout 1700 -R MODULE_CELL
92+
9393
- name: Module_MD Unittests
9494
env:
9595
GTEST_COLOR: 'yes'
9696
OMP_NUM_THREADS: '2'
9797
run: |
98-
cmake --build build --target test ARGS="-V --timeout 1700 -R MODULE_MD"
99-
98+
ctest --test-dir build -V --timeout 1700 -R MODULE_MD
99+
100100
- name: source_psi Unittests
101101
env:
102102
GTEST_COLOR: 'yes'
103103
OMP_NUM_THREADS: '2'
104104
run: |
105-
cmake --build build --target test ARGS="-V --timeout 1700 -R source_psi"
106-
105+
ctest --test-dir build -V --timeout 1700 -R source_psi
106+
107107
- name: Module_RI Unittests
108108
env:
109109
GTEST_COLOR: 'yes'
110110
OMP_NUM_THREADS: '2'
111111
run: |
112-
cmake --build build --target test ARGS="-V --timeout 1700 -R MODULE_RI"
113-
112+
ctest --test-dir build -V --timeout 1700 -R MODULE_RI
113+
114114
- name: 01_PW Test
115115
env:
116116
GTEST_COLOR: 'yes'
117117
OMP_NUM_THREADS: '2'
118118
run: |
119-
cmake --build build --target test ARGS="-V --timeout 1700 -R 01_PW"
120-
119+
ctest --test-dir build -V --timeout 1700 -R 01_PW
120+
121121
- name: 02_NAO_Gamma Test
122122
env:
123123
GTEST_COLOR: 'yes'
124124
OMP_NUM_THREADS: '2'
125125
run: |
126-
cmake --build build --target test ARGS="-V --timeout 1700 -R 02_NAO_Gamma"
127-
126+
ctest --test-dir build -V --timeout 1700 -R 02_NAO_Gamma
127+
128128
- name: 03_NAO_multik Test
129129
env:
130130
GTEST_COLOR: 'yes'
131131
OMP_NUM_THREADS: '2'
132132
run: |
133-
cmake --build build --target test ARGS="-V --timeout 1700 -R 03_NAO_multik"
134-
133+
ctest --test-dir build -V --timeout 1700 -R 03_NAO_multik
134+
135135
- name: 04_FF Test
136136
env:
137137
GTEST_COLOR: 'yes'
138138
OMP_NUM_THREADS: '2'
139139
run: |
140-
cmake --build build --target test ARGS="-V --timeout 1700 -R 04_FF"
141-
140+
ctest --test-dir build -V --timeout 1700 -R 04_FF
141+
142142
- name: 05_rtTDDFT Test
143143
env:
144144
GTEST_COLOR: 'yes'
145145
OMP_NUM_THREADS: '2'
146146
run: |
147-
cmake --build build --target test ARGS="-V --timeout 1700 -R 05_rtTDDFT"
148-
147+
ctest --test-dir build -V --timeout 1700 -R 05_rtTDDFT
148+
149149
- name: 06_SDFT Test
150150
env:
151151
GTEST_COLOR: 'yes'
152152
OMP_NUM_THREADS: '2'
153153
run: |
154-
cmake --build build --target test ARGS="-V --timeout 1700 -R 06_SDFT"
155-
154+
ctest --test-dir build -V --timeout 1700 -R 06_SDFT
155+
156156
- name: 07_OFDFT Test
157157
env:
158158
GTEST_COLOR: 'yes'
159159
OMP_NUM_THREADS: '2'
160160
run: |
161-
cmake --build build --target test ARGS="-V --timeout 1700 -R 07_OFDFT"
162-
161+
ctest --test-dir build -V --timeout 1700 -R 07_OFDFT
162+
163163
- name: 08_EXX Test
164164
env:
165165
GTEST_COLOR: 'yes'
166166
OMP_NUM_THREADS: '2'
167167
run: |
168-
cmake --build build --target test ARGS="-V --timeout 1700 -R 08_EXX"
169-
168+
ctest --test-dir build -V --timeout 1700 -R 08_EXX
169+
170170
- name: 09_DeePKS Test
171171
env:
172172
GTEST_COLOR: 'yes'
173173
OMP_NUM_THREADS: '2'
174174
run: |
175-
cmake --build build --target test ARGS="-V --timeout 1700 -R 09_DeePKS"
176-
175+
ctest --test-dir build -V --timeout 1700 -R 09_DeePKS
176+
177177
- name: 10_others Test
178178
env:
179179
GTEST_COLOR: 'yes'
180180
OMP_NUM_THREADS: '2'
181181
run: |
182-
cmake --build build --target test ARGS="-V --timeout 1700 -R 10_others"
183-
182+
ctest --test-dir build -V --timeout 1700 -R 10_others
183+
184184
- name: Other Unittests
185185
env:
186186
GTEST_COLOR: 'yes'
187187
OMP_NUM_THREADS: '2'
188188
run: |
189-
cmake --build build --target test ARGS="-V --timeout 1700 -E 'integrate_test|01_PW|02_NAO_Gamma|03_NAO_multik|04_FF|05_rtTDDFT|06_SDFT|07_OFDFT|08_EXX|09_DeePKS|10_others|11_PW_GPU|12_NAO_Gamma_GPU|13_NAO_multik_GPU|15_rtTDDFT_GPU|16_SDFT_GPU|MODULE_BASE|MODULE_IO|MODULE_HSOLVER|MODULE_CELL|MODULE_MD|source_psi|MODULE_RI'"
189+
ctest --test-dir build -V --timeout 1700 -E 'integrate_test|01_PW|02_NAO_Gamma|03_NAO_multik|04_FF|05_rtTDDFT|06_SDFT|07_OFDFT|08_EXX|09_DeePKS|10_others|11_PW_GPU|12_NAO_Gamma_GPU|13_NAO_multik_GPU|15_rtTDDFT_GPU|16_SDFT_GPU|MODULE_BASE|MODULE_IO|MODULE_HSOLVER|MODULE_CELL|MODULE_MD|source_psi|MODULE_RI'

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/build*
2+
build_info.h
23
bin
34
obj
45
*.o
@@ -24,4 +25,4 @@ abacus.json
2425
*.npy
2526
toolchain/install/
2627
toolchain/abacus_env.sh
27-
.trae
28+
.trae

CMakeLists.txt

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ if(ENABLE_RAPIDJSON)
7474
OFF
7575
CACHE INTERNAL "")
7676
FetchContent_MakeAvailable(rapidjson)
77-
set(RapidJSON_INCLUDE_PATH "${rapidjson_SOURCE_DIR}/include")
7877
endif()
78+
set(RapidJSON_INCLUDE_PATH "${rapidjson_SOURCE_DIR}/include")
7979
add_compile_definitions(__RAPIDJSON)
8080
add_definitions(-DRAPIDJSON_HAS_CXX11_NOEXCEPT=0)
8181
include_directories(${RapidJSON_INCLUDE_PATH})
@@ -182,6 +182,7 @@ if(ENABLE_COVERAGE)
182182
add_coverage(${ABACUS_BIN_NAME})
183183
endif()
184184

185+
185186
macro(set_if_higher VARIABLE VALUE)
186187
if(${VARIABLE} LESS ${VALUE})
187188
set(${VARIABLE} ${VALUE})
@@ -669,73 +670,13 @@ if(INFO)
669670
# modifications on blas_connector and lapack_connector
670671
endif()
671672

672-
# Add performance test in abacus
673-
if(ENABLE_GOOGLEBENCH)
674-
set(BUILD_TESTING ON)
675-
find_package(benchmark HINTS ${BENCHMARK_DIR})
676-
if(NOT ${benchmark_FOUND})
677-
set(BENCHMARK_USE_BUNDLED_GTEST OFF)
678-
include(FetchContent)
679-
FetchContent_Declare(
680-
benchmark
681-
GIT_REPOSITORY https://github.com/google/benchmark.git
682-
GIT_TAG "origin/main"
683-
GIT_SHALLOW TRUE
684-
GIT_PROGRESS TRUE)
685-
set(BENCHMARK_ENABLE_TESTING OFF)
686-
FetchContent_MakeAvailable(benchmark)
687-
endif()
688-
endif()
689-
690-
if(BUILD_TESTING)
691-
set_if_higher(CMAKE_CXX_STANDARD 14) # Required in orbital
692-
include(CTest)
693-
enable_testing()
694-
find_package(GTest HINTS /usr/local/lib/ ${GTEST_DIR})
695-
if(NOT ${GTest_FOUND})
696-
include(FetchContent)
697-
FetchContent_Declare(
698-
googletest
699-
GIT_REPOSITORY https://github.com/google/googletest.git
700-
GIT_TAG "origin/main"
701-
GIT_SHALLOW TRUE
702-
GIT_PROGRESS TRUE)
703-
FetchContent_MakeAvailable(googletest)
704-
endif()
705-
# TODO: Try the GoogleTest module.
706-
# https://cmake.org/cmake/help/latest/module/GoogleTest.html
707-
add_subdirectory(tests) # Contains integration tests
708-
709-
function(AddTest) # function for UT
710-
cmake_parse_arguments(UT "DYN" "TARGET"
711-
"LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN})
712-
add_executable(${UT_TARGET} ${UT_SOURCES})
713-
714-
if(ENABLE_COVERAGE)
715-
add_coverage(${UT_TARGET})
716-
endif()
717-
718-
# dependencies & link library
719-
target_link_libraries(${UT_TARGET} ${UT_LIBS} Threads::Threads
720-
GTest::gtest_main GTest::gmock_main)
721-
if(ENABLE_GOOGLEBENCH)
722-
target_link_libraries(
723-
${UT_TARGET} benchmark::benchmark)
724-
endif()
725-
726-
if(USE_OPENMP)
727-
target_link_libraries(${UT_TARGET} OpenMP::OpenMP_CXX)
728-
endif()
729-
install(TARGETS ${UT_TARGET} DESTINATION ${CMAKE_BINARY_DIR}/tests)
730-
add_test(
731-
NAME ${UT_TARGET}
732-
COMMAND ${UT_TARGET}
733-
WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET}>)
734-
endfunction(AddTest)
735-
endif()
673+
include(cmake/Testing.cmake)
736674

737675
add_subdirectory(source)
738676

677+
include(cmake/BuildInfo.cmake)
678+
setup_build_info()
679+
739680
target_link_libraries(
740681
${ABACUS_BIN_NAME}
741682
base

cmake/BuildInfo.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# =============================================================================
2+
# Generate Build Information Header (Including Information Collection)
3+
# ==============================================================================
4+
5+
# include_guard(GLOBAL)
6+
7+
function(setup_build_info)
8+
message(STATUS "Setting up build information...")
9+
10+
include(cmake/CollectBuildInfoVars.cmake)
11+
12+
set(BUILD_INFO_TEMPLATE "${CMAKE_SOURCE_DIR}/source/source_io/build_info.h.in")
13+
set(BUILD_INFO_OUTPUT "${CMAKE_BINARY_DIR}/source/source_io/build_info.h")
14+
15+
configure_file(
16+
${BUILD_INFO_TEMPLATE}
17+
${BUILD_INFO_OUTPUT}
18+
@ONLY
19+
)
20+
21+
# add_library(BuildInfo::Headers INTERFACE IMPORTED GLOBAL)
22+
# target_include_directories(BuildInfo::Headers
23+
# INTERFACE
24+
# ${CMAKE_BINARY_DIR}/source/source_io
25+
# )
26+
27+
message(STATUS "Build info header configured: ${BUILD_INFO_OUTPUT}")
28+
endfunction()

0 commit comments

Comments
 (0)