OpenMS
BuildInfo.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Julianus Pfeuffer $
32 // $Authors: Julianus Pfeuffer $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/build_config.h>
39 #include <QSysInfo>
40 #include <QString>
41 #ifdef _OPENMP
42  #include "omp.h"
43 #endif
44 
45 namespace OpenMS
46 {
47  namespace Internal
48  {
49 
51  std::string OpenMS_OSNames[] = {"unknown", "MacOS", "Windows", "Linux"};
53  std::string OpenMS_ArchNames[] = {"unknown", "32 bit", "64 bit"};
54 
56  {
60 
61  public:
63  os_(OS_UNKNOWN),
64  os_version_("unknown"),
66  {}
67 
70  {
71  return OpenMS_OSNames[os_];
72  }
73 
76  {
77  return OpenMS_ArchNames[arch_];
78  }
79 
82  {
83  return os_version_;
84  }
85 
88  {
89  size_t bytes = sizeof(size_t);
90  switch (bytes)
91  {
92  case 4:
94  case 8:
96  default:
98  }
99  }
100 
103  {
104  OpenMSOSInfo info;
105  #if defined(WIN32) // Windows
106  info.os_ = OS_WINDOWS;
107  #elif (defined(__MACH__) && defined(__APPLE__)) // MacOS
108  info.os_ = OS_MACOS;
109  #elif (defined(__unix__)) //Linux/FreeBSD TODO make a difference?
110  info.os_ = OS_LINUX;
111  #endif // else stays unknown
112 
113  // returns something meaningful for basically all important platforms
114  info.os_version_ = QSysInfo::productVersion();
115 
116  // identify architecture
117  if (QSysInfo::WordSize == 32)
118  {
119  info.arch_ = ARCH_32BIT;
120  }
121  else
122  {
123  info.arch_ = ARCH_64BIT;
124  }
125 
126  return info;
127  }
128  };
129 
132 
133  {
134  public:
135 
137  static bool isOpenMPEnabled()
138  {
139  #ifdef _OPENMP
140  return true;
141  #else
142  return false;
143  #endif
144  }
145 
148  {
149  return OPENMS_BUILD_TYPE;
150  }
151 
156  {
157  #ifdef _OPENMP
158  return omp_get_max_threads();
159  #else
160  return 1;
161  #endif
162  }
165  static void setOpenMPNumThreads(Int num_threads)
166  {
167  #ifdef _OPENMP
168  omp_set_num_threads(num_threads);
169  #endif
170  }
171  };
172 
173  } // NS Internal
174 } // NS OpenMS
Definition: BuildInfo.h:56
static String getBinaryArchitecture()
Get Architecture of this binary (simply by looking at size of a pointer, i.e. size_t).
Definition: BuildInfo.h:87
String os_version_
Definition: BuildInfo.h:58
OpenMS_Architecture arch_
Definition: BuildInfo.h:59
OpenMSOSInfo()
Definition: BuildInfo.h:62
String getOSVersionAsString() const
Get the OS version (e.g. 10.15 for macOS or 10 for Windows)
Definition: BuildInfo.h:81
static OpenMSOSInfo getOSInfo()
Constructs and returns an OpenMSOSInfo object.
Definition: BuildInfo.h:102
OpenMS_OS os_
Definition: BuildInfo.h:57
String getArchAsString() const
Get the current architecture (32-bit or 64-bit)
Definition: BuildInfo.h:75
String getOSAsString() const
Get the current operating system (Windows, MacOS, Linux)
Definition: BuildInfo.h:69
A more convenient string class.
Definition: String.h:60
int Int
Signed integer type.
Definition: Types.h:102
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::string OpenMS_OSNames[]
Definition: BuildInfo.h:51
OpenMS_Architecture
Definition: BuildInfo.h:52
@ ARCH_64BIT
Definition: BuildInfo.h:52
@ ARCH_UNKNOWN
Definition: BuildInfo.h:52
@ ARCH_32BIT
Definition: BuildInfo.h:52
std::string OpenMS_ArchNames[]
Definition: BuildInfo.h:53
OpenMS_OS
Definition: BuildInfo.h:50
@ OS_UNKNOWN
Definition: BuildInfo.h:50
@ OS_WINDOWS
Definition: BuildInfo.h:50
@ OS_LINUX
Definition: BuildInfo.h:50
@ OS_MACOS
Definition: BuildInfo.h:50
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Struct with some static methods to get informations on the build configuration.
Definition: BuildInfo.h:133
static String getBuildType()
Get the build type used during building the OpenMS library.
Definition: BuildInfo.h:147
static Size getOpenMPMaxNumThreads()
Get the maximum number of threads that OpenMP will use (including hyperthreads) Note: This could also...
Definition: BuildInfo.h:155
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:165
static bool isOpenMPEnabled()
Checks if OpenMP was enabled during build, based on the _OPENMP macro.
Definition: BuildInfo.h:137