OpenMS
BuildInfo.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Julianus Pfeuffer $
6 // $Authors: Julianus Pfeuffer $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/build_config.h>
13 
14 #include <QtCore/QSysInfo>
15 #include <QtCore/QString>
16 
17 #ifdef _OPENMP
18  #include "omp.h"
19 #endif
20 
21 namespace OpenMS
22 {
23  namespace Internal
24  {
25 
27  std::string OpenMS_OSNames[] = {"unknown", "MacOS", "Windows", "Linux"};
29  std::string OpenMS_ArchNames[] = {"unknown", "32 bit", "64 bit"};
30 
31  class OPENMS_DLLAPI OpenMSOSInfo
32  {
36 
37  public:
39  os_(OS_UNKNOWN),
40  os_version_("unknown"),
41  arch_(ARCH_UNKNOWN)
42  {}
43 
46  {
47  return OpenMS_OSNames[os_];
48  }
49 
52  {
53  return OpenMS_ArchNames[arch_];
54  }
55 
58  {
59  return os_version_;
60  }
61 
64  {
65  size_t bytes = sizeof(size_t);
66  switch (bytes)
67  {
68  case 4:
70  case 8:
72  default:
74  }
75  }
76 
79 
82  {
83  OpenMSOSInfo info;
84  #if defined(WIN32) // Windows
85  info.os_ = OS_WINDOWS;
86  #elif (defined(__MACH__) && defined(__APPLE__)) // MacOS
87  info.os_ = OS_MACOS;
88  #elif (defined(__unix__)) //Linux/FreeBSD TODO make a difference?
89  info.os_ = OS_LINUX;
90  #endif // else stays unknown
91 
92  // returns something meaningful for basically all important platforms
93  info.os_version_ = QSysInfo::productVersion();
94 
95  // identify architecture
96  if (QSysInfo::WordSize == 32)
97  {
98  info.arch_ = ARCH_32BIT;
99  }
100  else
101  {
102  info.arch_ = ARCH_64BIT;
103  }
104 
105  return info;
106  }
107  };
108 
111 
112  {
113  public:
114 
116  static bool isOpenMPEnabled()
117  {
118  #ifdef _OPENMP
119  return true;
120  #else
121  return false;
122  #endif
123  }
124 
127  {
128  return OPENMS_BUILD_TYPE;
129  }
130 
135  {
136  #ifdef _OPENMP
137  return omp_get_max_threads();
138  #else
139  return 1;
140  #endif
141  }
144  static void setOpenMPNumThreads(Int num_threads)
145  {
146  #ifdef _OPENMP
147  omp_set_num_threads(num_threads);
148  #endif
149  (void)num_threads; // avoid 'unreferenced formal parameter' C4100 on Windows
150  }
151  };
152 
153  } // NS Internal
154 } // NS OpenMS
Definition: BuildInfo.h:32
static String getActiveSIMDExtensions()
Obtain a list of SIMD extensions which are currently in use (i.e. used by the compiler during optimiz...
static String getBinaryArchitecture()
Get Architecture of this binary (simply by looking at size of a pointer, i.e. size_t).
Definition: BuildInfo.h:63
String os_version_
Definition: BuildInfo.h:34
OpenMS_Architecture arch_
Definition: BuildInfo.h:35
OpenMSOSInfo()
Definition: BuildInfo.h:38
String getOSVersionAsString() const
Get the OS version (e.g. 10.15 for macOS or 10 for Windows)
Definition: BuildInfo.h:57
static OpenMSOSInfo getOSInfo()
Constructs and returns an OpenMSOSInfo object.
Definition: BuildInfo.h:81
OpenMS_OS os_
Definition: BuildInfo.h:33
String getArchAsString() const
Get the current architecture (32-bit or 64-bit)
Definition: BuildInfo.h:51
String getOSAsString() const
Get the current operating system (Windows, MacOS, Linux)
Definition: BuildInfo.h:45
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:72
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
std::string OpenMS_OSNames[]
Definition: BuildInfo.h:27
OpenMS_Architecture
Definition: BuildInfo.h:28
@ ARCH_64BIT
Definition: BuildInfo.h:28
@ ARCH_UNKNOWN
Definition: BuildInfo.h:28
@ ARCH_32BIT
Definition: BuildInfo.h:28
std::string OpenMS_ArchNames[]
Definition: BuildInfo.h:29
OpenMS_OS
Definition: BuildInfo.h:26
@ OS_UNKNOWN
Definition: BuildInfo.h:26
@ OS_WINDOWS
Definition: BuildInfo.h:26
@ OS_LINUX
Definition: BuildInfo.h:26
@ OS_MACOS
Definition: BuildInfo.h:26
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Struct with some static methods to get informations on the build configuration.
Definition: BuildInfo.h:112
static String getBuildType()
Get the build type used during building the OpenMS library.
Definition: BuildInfo.h:126
static Size getOpenMPMaxNumThreads()
Get the maximum number of threads that OpenMP will use (including hyperthreads) Note: This could also...
Definition: BuildInfo.h:134
static void setOpenMPNumThreads(Int num_threads)
Set the number of threads that OpenMP will use (including hyperthreads) Note: Can be initialized by t...
Definition: BuildInfo.h:144
static bool isOpenMPEnabled()
Checks if OpenMP was enabled during build, based on the _OPENMP macro.
Definition: BuildInfo.h:116