convert static class members with git info to functions to simplify auto-export on Windows

This commit is contained in:
Axel Kohlmeyer
2022-01-27 17:20:05 -05:00
parent 62ff23abe7
commit d391ae845b
6 changed files with 37 additions and 37 deletions

View File

@ -24,10 +24,10 @@ if(GIT_FOUND AND EXISTS ${LAMMPS_DIR}/.git)
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
set(temp "${temp}const bool LAMMPS_NS::LAMMPS::has_git_info = ${temp_git_info};\n")
set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_commit[] = \"${temp_git_commit}\";\n")
set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_branch[] = \"${temp_git_branch}\";\n")
set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_descriptor[] = \"${temp_git_describe}\";\n")
set(temp "${temp}bool LAMMPS_NS::LAMMPS::has_git_info() { return ${temp_git_info}; }\n")
set(temp "${temp}const char *LAMMPS_NS::LAMMPS::git_commit() { return \"${temp_git_commit}\"; }\n")
set(temp "${temp}const char *LAMMPS_NS::LAMMPS::git_branch() { return \"${temp_git_branch}\"; }\n")
set(temp "${temp}const char *LAMMPS_NS::LAMMPS::git_descriptor() { return \"${temp_git_describe}\"; }\n")
set(temp "${temp}#endif\n\n")
message(STATUS "Generating lmpgitversion.h...")

View File

@ -356,10 +356,10 @@ gitversion:
branch='(unknown)' ; \
describe='(unknown)' ; \
fi ; \
echo "const bool LAMMPS_NS::LAMMPS::has_git_info = $${git};" >> ${TMPNAME}.lmpgitversion ; \
echo "const char LAMMPS_NS::LAMMPS::git_commit[] = \"$${commit}\";" >> ${TMPNAME}.lmpgitversion ; \
echo "const char LAMMPS_NS::LAMMPS::git_branch[] = \"$${branch}\";" >> ${TMPNAME}.lmpgitversion ; \
echo "const char LAMMPS_NS::LAMMPS::git_descriptor[] = \"$${describe}\";" >> ${TMPNAME}.lmpgitversion
echo "bool LAMMPS_NS::LAMMPS::has_git_info() { return $${git}; }" >> ${TMPNAME}.lmpgitversion ; \
echo "const char *LAMMPS_NS::LAMMPS::git_commit() { return \"$${commit}\"; }" >> ${TMPNAME}.lmpgitversion ; \
echo "const char *LAMMPS_NS::LAMMPS::git_branch() { return \"$${branch}\"; }" >> ${TMPNAME}.lmpgitversion ; \
echo "const char *LAMMPS_NS::LAMMPS::git_descriptor() { return \"$${describe}\"; }" >> ${TMPNAME}.lmpgitversion
@echo '#endif' >> ${TMPNAME}.lmpgitversion
@if [ -f lmpgitversion.h ]; \
then test "`diff --brief ${TMPNAME}.lmpgitversion lmpgitversion.h`" != "" && \

View File

@ -278,9 +278,9 @@ void Info::command(int narg, char **arg)
fmt::print(out,"\nLAMMPS version: {} / {}\n",
lmp->version, lmp->num_ver);
if (lmp->has_git_info)
if (lmp->has_git_info())
fmt::print(out,"Git info: {} / {} / {}\n",
lmp->git_branch, lmp->git_descriptor,lmp->git_commit);
lmp->git_branch(), lmp->git_descriptor(),lmp->git_commit());
fmt::print(out,"\nOS information: {}\n\n",platform::os_info());

View File

@ -1149,9 +1149,9 @@ void _noopt LAMMPS::help()
// general help message about command line and flags
if (has_git_info) {
if (has_git_info()) {
fprintf(fp,"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - "
LAMMPS_VERSION UPDATE_STRING "\nGit info (%s / %s)\n\n",git_branch, git_descriptor);
LAMMPS_VERSION UPDATE_STRING "\nGit info (%s / %s)\n\n",git_branch(), git_descriptor());
} else {
fprintf(fp,"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - "
LAMMPS_VERSION UPDATE_STRING "\n\n");

View File

@ -73,10 +73,10 @@ class LAMMPS {
static const char *installed_packages[];
static bool is_installed_pkg(const char *pkg);
static const bool has_git_info;
static const char git_commit[];
static const char git_branch[];
static const char git_descriptor[];
static bool has_git_info();
static const char *git_commit();
static const char *git_branch();
static const char *git_descriptor();
LAMMPS(int, char **, MPI_Comm);
~LAMMPS();

View File

@ -90,14 +90,14 @@ TEST_F(LAMMPS_plain, InitMembers)
EXPECT_EQ(lmp->memoryKK, nullptr);
EXPECT_NE(lmp->python, nullptr);
EXPECT_EQ(lmp->citeme, nullptr);
if (LAMMPS::has_git_info) {
EXPECT_STRNE(LAMMPS::git_commit, "");
EXPECT_STRNE(LAMMPS::git_branch, "");
EXPECT_STRNE(LAMMPS::git_descriptor, "");
if (LAMMPS::has_git_info()) {
EXPECT_STRNE(LAMMPS::git_commit(), "");
EXPECT_STRNE(LAMMPS::git_branch(), "");
EXPECT_STRNE(LAMMPS::git_descriptor(), "");
} else {
EXPECT_STREQ(LAMMPS::git_commit, "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch, "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor, "(unknown)");
EXPECT_STREQ(LAMMPS::git_commit(), "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch(), "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor(), "(unknown)");
}
}
@ -225,14 +225,14 @@ TEST_F(LAMMPS_omp, InitMembers)
EXPECT_EQ(lmp->memoryKK, nullptr);
EXPECT_NE(lmp->python, nullptr);
EXPECT_NE(lmp->citeme, nullptr);
if (LAMMPS::has_git_info) {
EXPECT_STRNE(LAMMPS::git_commit, "");
EXPECT_STRNE(LAMMPS::git_branch, "");
EXPECT_STRNE(LAMMPS::git_descriptor, "");
if (LAMMPS::has_git_info()) {
EXPECT_STRNE(LAMMPS::git_commit(), "");
EXPECT_STRNE(LAMMPS::git_branch(), "");
EXPECT_STRNE(LAMMPS::git_descriptor(), "");
} else {
EXPECT_STREQ(LAMMPS::git_commit, "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch, "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor, "(unknown)");
EXPECT_STREQ(LAMMPS::git_commit(), "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch(), "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor(), "(unknown)");
}
}
@ -312,14 +312,14 @@ TEST_F(LAMMPS_kokkos, InitMembers)
EXPECT_NE(lmp->memoryKK, nullptr);
EXPECT_NE(lmp->python, nullptr);
EXPECT_NE(lmp->citeme, nullptr);
if (LAMMPS::has_git_info) {
EXPECT_STRNE(LAMMPS::git_commit, "");
EXPECT_STRNE(LAMMPS::git_branch, "");
EXPECT_STRNE(LAMMPS::git_descriptor, "");
if (LAMMPS::has_git_info()) {
EXPECT_STRNE(LAMMPS::git_commit(), "");
EXPECT_STRNE(LAMMPS::git_branch(), "");
EXPECT_STRNE(LAMMPS::git_descriptor(), "");
} else {
EXPECT_STREQ(LAMMPS::git_commit, "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch, "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor, "(unknown)");
EXPECT_STREQ(LAMMPS::git_commit(), "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch(), "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor(), "(unknown)");
}
}