Skip to content

Commit 8e59cf5

Browse files
nikosavolahughcars
authored andcommitted
Change approach for dependency versions to fetch git SHA
Fetch git SHA from build/extern folders
1 parent f28a2ba commit 8e59cf5

File tree

3 files changed

+89
-98
lines changed

3 files changed

+89
-98
lines changed

palace/CMakeLists.txt

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -265,69 +265,40 @@ if(NOT GIT_COMMIT_ID MATCHES "NOTFOUND")
265265
)
266266
endif()
267267

268-
# Add dependency version information
269-
if(nlohmann_json_VERSION)
270-
set_property(
271-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
272-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_NLOHMANN_JSON_VERSION=\"${nlohmann_json_VERSION}\""
273-
)
274-
endif()
275268

276-
if(fmt_VERSION)
277-
set_property(
278-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
279-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_FMT_VERSION=\"${fmt_VERSION}\""
280-
)
281-
endif()
282-
283-
if(scn_VERSION)
284-
set_property(
285-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
286-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_SCN_VERSION=\"${scn_VERSION}\""
287-
)
288-
endif()
289-
290-
if(Eigen3_VERSION)
291-
set_property(
292-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
293-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_EIGEN_VERSION=\"${Eigen3_VERSION}\""
294-
)
295-
endif()
296-
297-
if(MFEM_VERSION)
298-
set_property(
299-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
300-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_MFEM_VERSION=\"${MFEM_VERSION}\""
301-
)
302-
endif()
303-
304-
if(libCEED_VERSION)
305-
set_property(
306-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
307-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_LIBCEED_VERSION=\"${libCEED_VERSION}\""
308-
)
309-
endif()
310-
311-
if(PALACE_WITH_SLEPC AND PETSc_VERSION)
312-
set_property(
313-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
314-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_PETSC_VERSION=\"${PETSc_VERSION}\""
315-
)
316-
endif()
317-
318-
if(PALACE_WITH_SLEPC AND SLEPc_VERSION)
319-
set_property(
320-
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
321-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_SLEPC_VERSION=\"${SLEPc_VERSION}\""
322-
)
323-
endif()
324-
325-
if(PALACE_WITH_ARPACK AND arpackng_VERSION)
269+
# For each dependency with a git SHA, set a compile definition <DEPENDENCY>_COMMIT_SHA
270+
set(dependency_folders
271+
STRUMPACK
272+
arpack-ng
273+
eigen
274+
fmt
275+
gslib
276+
hypre
277+
json
278+
libCEED
279+
libxsmm
280+
magma
281+
metis
282+
mfem
283+
mumps
284+
parmetis
285+
petsc
286+
scalapack
287+
scn
288+
slepc
289+
sundials
290+
superlu_dist
291+
)
292+
foreach(dep_folder IN LISTS dependency_folders)
293+
message(DEBUG "Checking dependency in folder ${dep_folder}")
294+
get_dependency_git_sha("${CMAKE_BINARY_DIR}/../extern/${dep_folder}" dep_sha)
295+
message(DEBUG "Git SHA for ${dep_folder}: ${dep_sha}")
296+
string(REPLACE "-" "_" dep_folder_sanitized "${dep_folder}")
326297
set_property(
327298
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
328-
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_ARPACK_VERSION=\"${arpackng_VERSION}\""
299+
APPEND PROPERTY COMPILE_DEFINITIONS "${dep_folder_sanitized}_COMMIT_SHA=\"${dep_sha}\""
329300
)
330-
endif()
301+
endforeach()
331302

332303
# Check C++ compiler support for constexpr std::sqrt and std::filesystem
333304
include(CheckCompilerFeatureSupport)

palace/cmake/GetGitDescription.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,30 @@ function(git_describe _var)
9898
set(${_var} "${out}" PARENT_SCOPE)
9999
endif()
100100
endfunction()
101+
102+
103+
# Helper to get git SHA for a dependency
104+
function(get_dependency_git_sha dep_source_dir _var)
105+
find_package(Git QUIET)
106+
if(NOT GIT_FOUND)
107+
message(WARNING "Git not found, cannot get SHA for ${dep_source_dir}")
108+
return()
109+
endif()
110+
111+
# Run git describe in the given source directory
112+
# Do not consider parent directories (--git-dir .git)
113+
execute_process(
114+
COMMAND "${GIT_EXECUTABLE}" --git-dir .git describe --tags --always --dirty
115+
WORKING_DIRECTORY "${dep_source_dir}"
116+
RESULT_VARIABLE res
117+
OUTPUT_VARIABLE out
118+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
119+
)
120+
if(NOT res EQUAL 0)
121+
message(DEBUG "Git SHA for not found in ${dep_source_dir}")
122+
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
123+
else()
124+
message(DEBUG "Git SHA for ${dep_name_source_dir}: ${out}")
125+
set(${_var} ${out} PARENT_SCOPE)
126+
endif()
127+
endfunction()

palace/main.cpp

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,54 +42,47 @@ static const char *GetPalaceGitTag()
4242

4343
static void PrintPalaceVersionInfo(MPI_Comm comm)
4444
{
45+
4546
if (std::strcmp(GetPalaceGitTag(), "UNKNOWN"))
4647
{
4748
Mpi::Print(comm, "Git commit: {}\n", GetPalaceGitTag());
4849
}
4950

50-
// Print build dependencies
5151
Mpi::Print(comm, "\nBuild dependencies:\n");
5252

53-
#define PRINT_VERSION(NAME, VERSION_MACRO) \
54-
Mpi::Print(comm, " " NAME ": {}\n", VERSION_MACRO)
55-
56-
#if defined(PALACE_MFEM_VERSION)
57-
PRINT_VERSION("MFEM", PALACE_MFEM_VERSION);
58-
#endif
59-
60-
#if defined(PALACE_LIBCEED_VERSION)
61-
PRINT_VERSION("libCEED", PALACE_LIBCEED_VERSION);
62-
#endif
63-
64-
#if defined(PALACE_WITH_SLEPC) && defined(PALACE_SLEPC_VERSION)
65-
PRINT_VERSION("SLEPc", PALACE_SLEPC_VERSION);
66-
#endif
67-
68-
#if defined(PALACE_WITH_SLEPC) && defined(PALACE_PETSC_VERSION)
69-
PRINT_VERSION("PETSc", PALACE_PETSC_VERSION);
70-
#endif
71-
72-
#if defined(PALACE_WITH_ARPACK) && defined(PALACE_ARPACK_VERSION)
73-
PRINT_VERSION("ARPACK", PALACE_ARPACK_VERSION);
74-
#endif
53+
// X-macro to check if a dependency macro is defined and print the SHA
54+
#define X(DEP_NAME) \
55+
Mpi::Print(comm, " " #DEP_NAME ": {}\n", DEP_NAME ## _COMMIT_SHA);
56+
57+
// List of dependencies and their corresponding macros
58+
#define PRINT_DEP_SHA_LIST \
59+
X(STRUMPACK) \
60+
X(arpack_ng) \
61+
X(eigen) \
62+
X(fmt) \
63+
X(gslib) \
64+
X(hypre) \
65+
X(json) \
66+
X(libCEED) \
67+
X(libxsmm) \
68+
X(magma) \
69+
X(metis) \
70+
X(mfem) \
71+
X(mumps) \
72+
X(parmetis) \
73+
X(petsc) \
74+
X(scalapack) \
75+
X(scn) \
76+
X(slepc) \
77+
X(sundials) \
78+
X(superlu_dist)
79+
80+
// Iterate over the list and print if macro is defined
81+
PRINT_DEP_SHA_LIST
82+
83+
#undef X
7584

76-
#if defined(PALACE_NLOHMANN_JSON_VERSION)
77-
PRINT_VERSION("nlohmann/json", PALACE_NLOHMANN_JSON_VERSION);
78-
#endif
79-
80-
#if defined(PALACE_FMT_VERSION)
81-
PRINT_VERSION("fmt", PALACE_FMT_VERSION);
82-
#endif
83-
84-
#if defined(PALACE_SCN_VERSION)
85-
PRINT_VERSION("scn", PALACE_SCN_VERSION);
86-
#endif
87-
88-
#if defined(PALACE_EIGEN_VERSION)
89-
PRINT_VERSION("Eigen", PALACE_EIGEN_VERSION);
90-
#endif
9185

92-
Mpi::Print(comm, "\n");
9386
}
9487

9588
static const char *GetPalaceCeedJitSourceDir()

0 commit comments

Comments
 (0)