Zivid C++ API 2.18.0+1b44dbef-1
ToolchainDetector.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of the Zivid API
3 *
4 * Copyright 2015-2026 (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 struct OpenCLContextPtr;
58 struct CUDAContextPtr;
59
60#ifndef NO_DOC
62 namespace Detail
63 {
66 ZIVID_CORE_EXPORT Application createApplicationForWrapper(EnvironmentInfo::Wrapper wrapper);
67
69 ZIVID_CORE_EXPORT Application createApplicationForWrapper(
70 EnvironmentInfo::Wrapper wrapper,
71 OpenCLContextPtr openclContext,
72 CUDAContextPtr cudaContext);
73
74 inline EnvironmentInfo::UserToolchain::Compiler detectCompiler()
75 {
76 using CompilerType = EnvironmentInfo::UserToolchain::Compiler::ID;
77 using CompilerVersion = EnvironmentInfo::UserToolchain::Compiler::Version;
78
79 CompilerType type;
80 CompilerVersion version;
81
82 // Note: Intel compiler can define _MSC_VER and __GNUC__ depending on platform, so check for it first.
83# if defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_COMPILER)
84 type = CompilerType{ CompilerType::ValueType::intel };
85 version = CompilerVersion{ __VERSION__ };
86 // Note: both _MSC_VER and __clang__ can be defined if using Clang on Windows.
87# elif defined(_MSC_VER) && !defined(__clang__)
88 type = CompilerType{ CompilerType::ValueType::msvc };
89 version = CompilerVersion{ ZIVID_STRINGIZE(_MSC_FULL_VER) };
90# elif defined(__clang__)
91 type = CompilerType{ CompilerType::ValueType::clang };
92 version = CompilerVersion{ __clang_version__ };
93# elif defined(__GNUC__)
94 type = CompilerType{ CompilerType::ValueType::gcc };
95 version = CompilerVersion{ ZIVID_STRINGIZE(__GNUC__) "." ZIVID_STRINGIZE(
96 __GNUC_MINOR__) "." ZIVID_STRINGIZE(__GNUC_PATCHLEVEL__) };
97# endif
98
99# if defined(__MINGW32__) || defined(__MINGW64__)
100 constexpr bool isMingw = true;
101# else
102 constexpr bool isMingw = false;
103# endif
104
105 if(isMingw)
106 {
107 if(type.value() == CompilerType::ValueType::gcc)
108 {
109 type = CompilerType{ CompilerType::ValueType::mingwGcc };
110 }
111 else if(type.value() == CompilerType::ValueType::clang)
112 {
113 type = CompilerType{ CompilerType::ValueType::mingwClang };
114 }
115 else
116 {
117 type = CompilerType{ CompilerType::ValueType::mingwUnknown };
118 }
119 }
120
121 return EnvironmentInfo::UserToolchain::Compiler{ type, version };
122 }
123
124 inline EnvironmentInfo::UserToolchain::StandardLibrary detectStandardLibrary()
125 {
126 using StdlibType = EnvironmentInfo::UserToolchain::StandardLibrary::ID;
127 using StdlibVersion = EnvironmentInfo::UserToolchain::StandardLibrary::Version;
128
129 StdlibType type;
130 StdlibVersion version;
131
132# ifdef _MSC_VER
133 type = StdlibType{ StdlibType::ValueType::msvc };
134 version = StdlibVersion{ ZIVID_STRINGIZE(_MSC_FULL_VER) };
135# elif defined(_LIBCPP_VERSION)
136 type = StdlibType{ StdlibType::ValueType::libcxx };
137 version = StdlibVersion{ ZIVID_STRINGIZE(_LIBCPP_VERSION) };
138# elif defined(__GLIBCXX__)
139 type = StdlibType{ StdlibType::ValueType::libstdcxx };
140 version = StdlibVersion{ ZIVID_STRINGIZE(__GLIBCXX__) };
141# endif
142
143 return EnvironmentInfo::UserToolchain::StandardLibrary{ type, version };
144 }
145
146 inline EnvironmentInfo::UserToolchain::CxxStandard detectCxxStandard()
147 {
148 // MSVC does not properly set __cplusplus unless compiling in conformance mode.
149 // (See https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170)
150# ifdef _MSC_VER
151 return EnvironmentInfo::UserToolchain::CxxStandard{ std::to_string(_MSVC_LANG) };
152# else
153 return EnvironmentInfo::UserToolchain::CxxStandard{ std::to_string(__cplusplus) };
154# endif
155 }
156
157 inline EnvironmentInfo::UserToolchain detectToolchain()
158 {
159 return EnvironmentInfo::UserToolchain{ detectCompiler(), detectStandardLibrary(), detectCxxStandard() };
160 }
161 } // namespace Detail
162#endif
163
164} // 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:85