Graphite  Version 3
An experimental 3D geometry processing program
common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef GEOGRAM_BASIC_COMMON
41 #define GEOGRAM_BASIC_COMMON
42 
43 #include <geogram/api/defs.h>
44 
45 // iostream should be included before anything else,
46 // otherwise 'cin', 'cout' and 'cerr' will be uninitialized.
47 #include <iostream>
48 
61 namespace GEO {
62 
66  enum {
85  };
86 
105  void GEOGRAM_API initialize(int flags = GEOGRAM_INSTALL_NONE);
106 
114  void GEOGRAM_API terminate();
115 }
116 
194 #if (defined(NDEBUG) || defined(GEOGRAM_PSM)) && !defined(GEOGRAM_PSM_DEBUG)
195 #undef GEO_DEBUG
196 #undef GEO_PARANOID
197 #else
198 #define GEO_DEBUG
199 #define GEO_PARANOID
200 #endif
201 
202 // =============================== LINUX defines ===========================
203 
204 #if defined(__ANDROID__)
205 #define GEO_OS_ANDROID
206 #endif
207 
208 #if defined(__linux__)
209 
210 #define GEO_OS_LINUX
211 #define GEO_OS_UNIX
212 
213 #ifndef GEO_OS_ANDROID
214 #define GEO_OS_X11
215 #endif
216 
217 #if defined(_OPENMP)
218 # define GEO_OPENMP
219 #endif
220 
221 #if defined(__INTEL_COMPILER)
222 # define GEO_COMPILER_INTEL
223 #elif defined(__clang__)
224 # define GEO_COMPILER_CLANG
225 #elif defined(__GNUC__)
226 # define GEO_COMPILER_GCC
227 #else
228 # error "Unsupported compiler"
229 #endif
230 
231 // The following works on GCC and ICC
232 #if defined(__x86_64)
233 # define GEO_ARCH_64
234 # define GEO_PROCESSOR_X86
235 #else
236 # define GEO_ARCH_32
237 #endif
238 
239 // =============================== WINDOWS defines =========================
240 
241 #elif defined(_WIN32) || defined(_WIN64)
242 
243 #define GEO_OS_WINDOWS
244 #define GEO_PROCESSOR_X86
245 
246 #if defined(_OPENMP)
247 # define GEO_OPENMP
248 #endif
249 
250 #if defined(_MSC_VER)
251 # define GEO_COMPILER_MSVC
252 #elif defined(__MINGW32__) || defined(__MINGW64__)
253 # define GEO_COMPILER_MINGW
254 #endif
255 
256 #if defined(_WIN64)
257 # define GEO_ARCH_64
258 #else
259 # define GEO_ARCH_32
260 #endif
261 
262 // =============================== APPLE defines ===========================
263 
264 #elif defined(__APPLE__)
265 
266 #define GEO_OS_APPLE
267 #define GEO_OS_UNIX
268 
269 #if defined(_OPENMP)
270 # define GEO_OPENMP
271 #endif
272 
273 #if defined(__clang__)
274 # define GEO_COMPILER_CLANG
275 #elif defined(__GNUC__)
276 # define GEO_COMPILER_GCC
277 #else
278 # error "Unsupported compiler"
279 #endif
280 
281 #if defined(__x86_64) || defined(__ppc64__) || defined(__arm64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
282 # define GEO_ARCH_64
283 #else
284 # define GEO_ARCH_32
285 #endif
286 
287 // =============================== Emscripten defines ======================
288 
289 #elif defined(__EMSCRIPTEN__)
290 
291 #define GEO_OS_UNIX
292 #define GEO_OS_LINUX
293 #define GEO_OS_EMSCRIPTEN
294 #define GEO_ARCH_64
295 #define GEO_COMPILER_EMSCRIPTEN
296 #define GEO_COMPILER_CLANG
297 
298 // =============================== Unsupported =============================
299 #else
300 #error "Unsupported operating system"
301 #endif
302 
303 #if defined(GEO_COMPILER_GCC) || \
304  defined(GEO_COMPILER_CLANG) || \
305  defined(GEO_COMPILER_MINGW) || \
306  defined(GEO_COMPILER_EMSCRIPTEN)
307 #define GEO_COMPILER_GCC_FAMILY
308 #endif
309 
310 #ifdef DOXYGEN_ONLY
311 // Keep doxygen happy
312 #define GEO_OS_WINDOWS
313 #define GEO_OS_APPLE
314 #define GEO_OS_ANDROID
315 #define GEO_ARCH_32
316 #define GEO_COMPILER_INTEL
317 #define GEO_COMPILER_MSVC
318 #endif
319 
324 #define CPP_CONCAT_(A, B) A ## B
325 
330 #define CPP_CONCAT(A, B) CPP_CONCAT_(A, B)
331 
332 #if defined(GOMGEN)
333 #define GEO_NORETURN
334 #elif defined(GEO_COMPILER_GCC_FAMILY) || \
335  defined(GEO_COMPILER_INTEL)
336 #define GEO_NORETURN __attribute__((noreturn))
337 #else
338 #define GEO_NORETURN
339 #endif
340 
341 #if defined(GOMGEN)
342 #define GEO_NORETURN_DECL
343 #elif defined(GEO_COMPILER_MSVC)
344 #define GEO_NORETURN_DECL __declspec(noreturn)
345 #else
346 #define GEO_NORETURN_DECL
347 #endif
348 
349 #if defined(GEO_COMPILER_CLANG) || defined(GEO_COMPILER_EMSCRIPTEN)
350 #if __has_feature(cxx_noexcept)
351 #define GEO_NOEXCEPT noexcept
352 #endif
353 #endif
354 
355 // For Graphite GOM generator (swig is confused by throw() specifier)
356 #ifdef GOMGEN
357 #define GEO_NOEXCEPT
358 #endif
359 
360 #ifndef GEO_NOEXCEPT
361 #define GEO_NOEXCEPT throw()
362 #endif
363 
364 #define FOR(I,UPPERBND) for(index_t I = 0; I<index_t(UPPERBND); ++I)
365 
366 // Silence warnings for alloca()
367 // We use it at different places to allocate objects on the stack
368 // (for instance, in multi-precision predicates).
369 #ifdef GEO_COMPILER_CLANG
370 #pragma GCC diagnostic ignored "-Walloca"
371 #endif
372 
373 #endif
Basic definitions for the Geogram C API.
Global Vorpaline namespace.
void terminate()
Cleans up Geogram.
@ GEOGRAM_INSTALL_LOCALE
Sets the locale to POSIX.
Definition: common.h:72
@ GEOGRAM_INSTALL_HANDLERS
Install Geogram's signal handlers.
Definition: common.h:70
@ GEOGRAM_INSTALL_BIBLIO
Enable global citation database.
Definition: common.h:78
@ GEOGRAM_INSTALL_NONE
Do not install error handlers.
Definition: common.h:68
@ GEOGRAM_INSTALL_FPE
Enable or disable FPE during initialization.
Definition: common.h:76
@ GEOGRAM_INSTALL_ALL
Install everything.
Definition: common.h:80
@ GEOGRAM_INSTALL_ERRNO
Reset errno to 0.
Definition: common.h:74
void initialize(int flags=GEOGRAM_INSTALL_NONE)
Initialize Geogram.