Zivid C++ API 2.14.0+e4a0c4a9-1
ToolchainDetector.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of the Zivid API
3 *
4 * Copyright 2015-2024 (C) Zivid AS
5 * All rights reserved.
6 *
7 * Zivid Software License, v1.0
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of Zivid AS nor the names of its contributors may be used
20 * to endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * 4. This software, with or without modification, must not be used with any
24 * other 3D camera than from Zivid AS.
25 *
26 * 5. Any software provided in binary form under this license must not be
27 * reverse engineered, decompiled, modified and/or disassembled.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
41 * Info: http://www.zivid.com
42 ******************************************************************************/
43
44#pragma once
45
48
49#include <string>
50
51#define ZIVID_STRINGIZE_1(X) #X
52#define ZIVID_STRINGIZE(X) ZIVID_STRINGIZE_1(X)
53
54namespace Zivid
55{
56 class Application;
57
58#ifndef NO_DOC
60 namespace Detail
61 {
64 ZIVID_CORE_EXPORT Application createApplicationForWrapper(EnvironmentInfo::Wrapper wrapper);
65
66 inline EnvironmentInfo::UserToolchain::Compiler detectCompiler()
67 {
68 using CompilerType = EnvironmentInfo::UserToolchain::Compiler::ID;
69 using CompilerVersion = EnvironmentInfo::UserToolchain::Compiler::Version;
70
71 CompilerType type;
72 CompilerVersion version;
73
74 // Note: Intel compiler can define _MSC_VER and __GNUC__ depending on platform, so check for it first.
75# if defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_COMPILER)
76 type = CompilerType{ CompilerType::ValueType::intel };
77 version = CompilerVersion{ __VERSION__ };
78 // Note: both _MSC_VER and __clang__ can be defined if using Clang on Windows.
79# elif defined(_MSC_VER) && !defined(__clang__)
80 type = CompilerType{ CompilerType::ValueType::msvc };
81 version = CompilerVersion{ ZIVID_STRINGIZE(_MSC_FULL_VER) };
82# elif defined(__clang__)
83 type = CompilerType{ CompilerType::ValueType::clang };
84 version = CompilerVersion{ __clang_version__ };
85# elif defined(__GNUC__)
86 type = CompilerType{ CompilerType::ValueType::gcc };
87 version = CompilerVersion{ ZIVID_STRINGIZE(__GNUC__) "." ZIVID_STRINGIZE(
88 __GNUC_MINOR__) "." ZIVID_STRINGIZE(__GNUC_PATCHLEVEL__) };
89# endif
90
91# if defined(__MINGW32__) || defined(__MINGW64__)
92 constexpr bool isMingw = true;
93# else
94 constexpr bool isMingw = false;
95# endif
96
97 if(isMingw)
98 {
99 if(type.value() == CompilerType::ValueType::gcc)
100 {
101 type = CompilerType{ CompilerType::ValueType::mingwGcc };
102 }
103 else if(type.value() == CompilerType::ValueType::clang)
104 {
105 type = CompilerType{ CompilerType::ValueType::mingwClang };
106 }
107 else
108 {
109 type = CompilerType{ CompilerType::ValueType::mingwUnknown };
110 }
111 }
112
113 return EnvironmentInfo::UserToolchain::Compiler{ type, version };
114 }
115
116 inline EnvironmentInfo::UserToolchain::StandardLibrary detectStandardLibrary()
117 {
118 using StdlibType = EnvironmentInfo::UserToolchain::StandardLibrary::ID;
119 using StdlibVersion = EnvironmentInfo::UserToolchain::StandardLibrary::Version;
120
121 StdlibType type;
122 StdlibVersion version;
123
124# if defined(_MSC_VER)
125 type = StdlibType{ StdlibType::ValueType::msvc };
126 version = StdlibVersion{ ZIVID_STRINGIZE(_MSC_FULL_VER) };
127# elif defined(_LIBCPP_VERSION)
128 type = StdlibType{ StdlibType::ValueType::libcxx };
129 version = StdlibVersion{ ZIVID_STRINGIZE(_LIBCPP_VERSION) };
130# elif defined(__GLIBCXX__)
131 type = StdlibType{ StdlibType::ValueType::libstdcxx };
132 version = StdlibVersion{ ZIVID_STRINGIZE(__GLIBCXX__) };
133# endif
134
135 return EnvironmentInfo::UserToolchain::StandardLibrary{ type, version };
136 }
137
138 inline EnvironmentInfo::UserToolchain::CxxStandard detectCxxStandard()
139 {
140 // MSVC does not properly set __cplusplus unless compiling in conformance mode.
141 // (See https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170)
142# if defined(_MSC_VER)
143 return EnvironmentInfo::UserToolchain::CxxStandard{ std::to_string(_MSVC_LANG) };
144# else
145 return EnvironmentInfo::UserToolchain::CxxStandard{ std::to_string(__cplusplus) };
146# endif
147 }
148
149 inline EnvironmentInfo::UserToolchain detectToolchain()
150 {
151 return EnvironmentInfo::UserToolchain{ detectCompiler(), detectStandardLibrary(), detectCxxStandard() };
152 }
153 } // namespace Detail
154#endif
155
156} // namespace Zivid
#define ZIVID_CORE_EXPORT
Definition CoreExport.h:56
#define ZIVID_STRINGIZE(X)
Definition ToolchainDetector.h:52
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:84