OpenMS
BuildInfo.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, 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 #include <QSysInfo>
14 #include <QString>
15 #ifdef _OPENMP
16  #include "omp.h"
17 #endif
18 
19 namespace OpenMS
20 {
21  namespace Internal
22  {
23 
25  std::string OpenMS_OSNames[] = {"unknown", "MacOS", "Windows", "Linux"};
27  std::string OpenMS_ArchNames[] = {"unknown", "32 bit", "64 bit"};
28 
29  class OPENMS_DLLAPI OpenMSOSInfo
30  {
34 
35  public:
37  os_(OS_UNKNOWN),
38  os_version_("unknown"),
39  arch_(ARCH_UNKNOWN)
40  {}
41 
44  {
45  return OpenMS_OSNames[os_];
46  }
47 
50  {
51  return OpenMS_ArchNames[arch_];
52  }
53 
56  {
57  return os_version_;
58  }
59 
62  {
63  size_t bytes = sizeof(size_t);
64  switch (bytes)
65  {
66  case 4:
68  case 8:
70  default:
72  }
73  }
74 
77 
80  {
81  OpenMSOSInfo info;
82  #if defined(WIN32) // Windows
83  info.os_ = OS_WINDOWS;
84  #elif (defined(__MACH__) && defined(__APPLE__)) // MacOS
85  info.os_ = OS_MACOS;
86  #elif (defined(__unix__)) //Linux/FreeBSD TODO make a difference?
87  info.os_ = OS_LINUX;
88  #endif // else stays unknown
89 
90  // returns something meaningful for basically all important platforms
91  info.os_version_ = QSysInfo::productVersion();
92 
93  // identify architecture
94  if (QSysInfo::WordSize == 32)
95  {
96  info.arch_ = ARCH_32BIT;
97  }
98  else
99  {
100  info.arch_ = ARCH_64BIT;
101  }
102 
103  return info;
104  }
105  };
106 
109 
110  {
111  public:
112 
114  static bool isOpenMPEnabled()
115  {
116  #ifdef _OPENMP
117  return true;
118  #else
119  return false;
120  #endif
121  }
122 
125  {
126  return OPENMS_BUILD_TYPE;
127  }
128 
133  {
134  #ifdef _OPENMP
135  return omp_get_max_threads();
136  #else
137  return 1;
138  #endif
139  }
142  static void setOpenMPNumThreads(Int num_threads)
143  {
144  #ifdef _OPENMP
145  omp_set_num_threads(num_threads);
146  #endif
147  (void)num_threads; // avoid 'unreferenced formal parameter' C4100 on Windows
148  }
149  };
150 
151  } // NS Internal
152 } // NS OpenMS
Definition: BuildInfo.h:30
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:61
String os_version_
Definition: BuildInfo.h:32
OpenMS_Architecture arch_
Definition: BuildInfo.h:33
OpenMSOSInfo()
Definition: BuildInfo.h:36
String getOSVersionAsString() const
Get the OS version (e.g. 10.15 for macOS or 10 for Windows)
Definition: BuildInfo.h:55
static OpenMSOSInfo getOSInfo()
Constructs and returns an OpenMSOSInfo object.
Definition: BuildInfo.h:79
OpenMS_OS os_
Definition: BuildInfo.h:31
String getArchAsString() const
Get the current architecture (32-bit or 64-bit)
Definition: BuildInfo.h:49
String getOSAsString() const
Get the current operating system (Windows, MacOS, Linux)
Definition: BuildInfo.h:43
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:76
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
std::string OpenMS_OSNames[]
Definition: BuildInfo.h:25
OpenMS_Architecture
Definition: BuildInfo.h:26
@ ARCH_64BIT
Definition: BuildInfo.h:26
@ ARCH_UNKNOWN
Definition: BuildInfo.h:26
@ ARCH_32BIT
Definition: BuildInfo.h:26
std::string OpenMS_ArchNames[]
Definition: BuildInfo.h:27
OpenMS_OS
Definition: BuildInfo.h:24
@ OS_UNKNOWN
Definition: BuildInfo.h:24
@ OS_WINDOWS
Definition: BuildInfo.h:24
@ OS_LINUX
Definition: BuildInfo.h:24
@ OS_MACOS
Definition: BuildInfo.h:24
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Struct with some static methods to get informations on the build configuration.
Definition: BuildInfo.h:110
static String getBuildType()
Get the build type used during building the OpenMS library.
Definition: BuildInfo.h:124
static Size getOpenMPMaxNumThreads()
Get the maximum number of threads that OpenMP will use (including hyperthreads) Note: This could also...
Definition: BuildInfo.h:132
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:142
static bool isOpenMPEnabled()
Checks if OpenMP was enabled during build, based on the _OPENMP macro.
Definition: BuildInfo.h:114