Skip to content

Commit 525ab76

Browse files
committed
use Cmake config file to pass CMake variables to Idefix. Add compiler infos to idefix.
1 parent 1258c28 commit 525ab76

8 files changed

Lines changed: 68 additions & 13 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,15 @@ if(Idefix_EVOLVE_VECTOR_POTENTIAL)
183183
endif()
184184
#update version.hpp if possible
185185
git_describe(GIT_SHA1)
186-
set(Idefix_VERSION ${Idefix_VERSION_MAJOR}.${Idefix_VERSION_MINOR}.${Idefix_VERSION_PATCH}-${GIT_SHA1})
187-
file(WRITE ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_GIT_COMMIT \"${GIT_SHA1}\"\n")
188-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION_MAJOR \"${Idefix_VERSION_MAJOR}\"\n")
189-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION_MINOR \"${Idefix_VERSION_MINOR}\"\n")
190-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION_PATCH \"${Idefix_VERSION_PATCH}\"\n")
191-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION \"${Idefix_VERSION}\"\n")
192186

193187

188+
set(Idefix_VERSION ${Idefix_VERSION_MAJOR}.${Idefix_VERSION_MINOR}.${Idefix_VERSION_PATCH}-${GIT_SHA1})
189+
configure_file(
190+
${CMAKE_SOURCE_DIR}/src/version.h.in
191+
${CMAKE_BINARY_DIR}/build/generated/version.h
192+
@ONLY
193+
)
194+
194195
if(NOT ${Idefix_DEFS} STREQUAL "definitions.hpp")
195196
add_compile_definitions("DEFINITIONS_FILE=\"${Idefix_DEFS}\"")
196197
endif()
@@ -269,6 +270,15 @@ target_include_directories(idefix PUBLIC
269270

270271
target_link_libraries(idefix Kokkos::kokkos)
271272

273+
# Generate header with compiler information (name, flags, path)
274+
configure_file(
275+
${CMAKE_SOURCE_DIR}/src/compiler_info.h.in
276+
${CMAKE_BINARY_DIR}/build/generated/compiler_info.h
277+
@ONLY
278+
)
279+
# Make sure the generated header is on the include path
280+
target_include_directories(idefix PRIVATE ${CMAKE_BINARY_DIR}/build/generated)
281+
272282
message(STATUS "Idefix final configuration")
273283
if(Idefix_EVOLVE_VECTOR_POTENTIAL)
274284
message(STATUS " MHD: ${Idefix_MHD} (Vector potential)")

src/compiler_info.h.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ***********************************************************************************
2+
// Idefix MHD astrophysical code
3+
// Copyright(C) Geoffroy R. J. Lesur <geoffroy.lesur@univ-grenoble-alpes.fr>
4+
// and other code contributors
5+
// Licensed under CeCILL 2.1 License, see COPYING for more information
6+
// ***********************************************************************************
7+
8+
#ifndef COMPILER_INFO_H
9+
#define COMPILER_INFO_H
10+
11+
namespace CompilerInfo {
12+
inline constexpr const char* name = "@CMAKE_CXX_COMPILER_ID@";
13+
inline constexpr const char* version = "@CMAKE_CXX_COMPILER_VERSION@";
14+
inline constexpr const char* path = "@CMAKE_CXX_COMPILER@";
15+
}
16+
17+
#endif

src/dataBlock/dumpToFile.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "dataBlock.hpp"
1212
#include "version.hpp"
1313
#include "fluid.hpp"
14+
#include "version.h"
1415

1516
#define NAMESIZE 16
1617
#define HEADERSIZE 128
@@ -78,7 +79,7 @@ void DataBlock::DumpToFile(std::string filebase) {
7879

7980
// Write Header
8081
char header[HEADERSIZE];
81-
std::snprintf(header, HEADERSIZE, "Idefix %s Debug DataBlock", IDEFIX_VERSION);
82+
std::snprintf(header, HEADERSIZE, "Idefix %s Debug DataBlock", VersionInfo::version);
8283
fwrite (header, sizeof(char), HEADERSIZE, fileHdl);
8384

8485
// Write Vc

src/input.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "input.hpp"
2121
#include "version.hpp"
2222
#include "profiler.hpp"
23+
#include "version.h"
24+
#include "compiler_info.h"
2325

2426
// Flag will be set if a signal has been received
2527
bool Input::abortRequested = false;
@@ -415,7 +417,10 @@ void Input::PrintOptions() {
415417
}
416418

417419
void Input::PrintVersion() {
418-
idfx::cout << " Idefix version " << IDEFIX_VERSION << std::endl;
419-
idfx::cout << " Built against Kokkos " << KOKKOS_VERSION << std::endl;
420-
idfx::cout << " Compiled on " << __DATE__ << " at " << __TIME__ << std::endl;
420+
idfx::cout << "Idefix version " << VersionInfo::version << std::endl;
421+
idfx::cout << "Built against Kokkos " << KOKKOS_VERSION << std::endl;
422+
idfx::cout << "Compiled on " << __DATE__ << " at " << __TIME__ << std::endl;
423+
idfx::cout << "Compiler name: " << CompilerInfo::name << std::endl;
424+
idfx::cout << "Compiler version: " << CompilerInfo::version << std::endl;
425+
idfx::cout << "Compiler path: " << CompilerInfo::path << std::endl;
421426
}

src/output/dump.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "gridHost.hpp"
2626
#include "output.hpp"
2727
#include "fluid.hpp"
28+
#include "version.h"
2829

2930
// Max size of array name
3031
#define NAMESIZE 16
@@ -880,7 +881,7 @@ int Dump::Write(Output& output) {
880881

881882
char header[HEADERSIZE];
882883
std::snprintf(header, HEADERSIZE, "Idefix %s Dump Data %s endian",
883-
IDEFIX_VERSION, endian.c_str());
884+
VersionInfo::version, endian.c_str());
884885
WriteString(fileHdl, header, HEADERSIZE);
885886

886887
for(int dir = 0; dir < 3 ; dir++) {

src/output/vtk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "gridHost.hpp"
2727
#include "output.hpp"
2828
#include "fluid.hpp"
29+
#include "version.h"
2930

3031
#define VTK_RECTILINEAR_GRID 14
3132
#define VTK_STRUCTURED_GRID 35
@@ -385,7 +386,7 @@ void Vtk::WriteHeader(IdfxFileHandler fvtk, real time) {
385386
2. Header
386387
------------------------------------------- */
387388

388-
ssheader << "Idefix " << IDEFIX_VERSION << " VTK Data" << std::endl;
389+
ssheader << "Idefix " << VersionInfo::version << " VTK Data" << std::endl;
389390

390391
/* ------------------------------------------
391392
3. File format

src/output/xdmf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "dataBlockHost.hpp"
2727
#include "gridHost.hpp"
2828
#include "output.hpp"
29+
#include "version.h"
2930

3031
// Whether or not we write the time in the XDMF file
3132
#define WRITE_TIME
@@ -526,7 +527,7 @@ void Xdmf::WriteHeader(
526527

527528
dimstr = 1;
528529

529-
ssheader << "Idefix " << IDEFIX_VERSION << " XDMF Data";
530+
ssheader << "Idefix " << VersionInfo::version << " XDMF Data";
530531
strspace = H5Screate_simple(1, &dimstr, NULL);
531532
string_type = H5Tcopy(H5T_C_S1);
532533
H5Tset_size(string_type, strlen( ssheader.str().c_str() ));

src/version.h.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ***********************************************************************************
2+
// Idefix MHD astrophysical code
3+
// Copyright(C) Geoffroy R. J. Lesur <geoffroy.lesur@univ-grenoble-alpes.fr>
4+
// and other code contributors
5+
// Licensed under CeCILL 2.1 License, see COPYING for more information
6+
// ***********************************************************************************
7+
8+
#ifndef VERSION_H
9+
#define VERSION_H
10+
11+
namespace VersionInfo {
12+
inline constexpr const char* gitCommit = "@GIT_SHA1@";
13+
inline constexpr const char* versionMajor = "@Idefix_VERSION_MAJOR@";
14+
inline constexpr const char* versionMinor = "@Idefix_VERSION_MINOR@";
15+
inline constexpr const char* versionPatch = "@Idefix_VERSION_PATCH@";
16+
inline constexpr const char* version = "@Idefix_VERSION@";
17+
}
18+
19+
#endif

0 commit comments

Comments
 (0)