Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
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
61namespace GEO {
62
66 enum {
85 };
86
105 void GEOGRAM_API initialize(int flags = GEOGRAM_INSTALL_NONE);
106
114 void GEOGRAM_API terminate();
115}
116
198#if (defined(NDEBUG) || defined(GEOGRAM_PSM)) && !defined(GEOGRAM_PSM_DEBUG)
199#undef GEO_DEBUG
200#undef GEO_PARANOID
201#else
202#define GEO_DEBUG
203#define GEO_PARANOID
204#endif
205
206// =============================== LINUX defines ===========================
207
208#if defined(__ANDROID__)
209#define GEO_OS_ANDROID
210#endif
211
212#if defined(__linux__)
213
214#define GEO_OS_LINUX
215#define GEO_OS_UNIX
216
217#ifndef GEO_OS_ANDROID
218#define GEO_OS_X11
219#endif
220
221#if defined(_OPENMP)
222# define GEO_OPENMP
223#endif
224
225#if defined(__INTEL_COMPILER)
226# define GEO_COMPILER_INTEL
227#elif defined(__clang__)
228# define GEO_COMPILER_CLANG
229#elif defined(__GNUC__)
230# define GEO_COMPILER_GCC
231#else
232# error "Unsupported compiler"
233#endif
234
235// The following works on GCC and ICC
236#if defined(__x86_64)
237# define GEO_ARCH_64
238# define GEO_PROCESSOR_X86
239#else
240# define GEO_ARCH_32
241#endif
242
243// =============================== WINDOWS defines =========================
244
245#elif defined(_WIN32) || defined(_WIN64)
246
247#define GEO_OS_WINDOWS
248#define GEO_PROCESSOR_X86
249
250#if defined(_OPENMP)
251# define GEO_OPENMP
252#endif
253
254#if defined(_MSC_VER)
255# define GEO_COMPILER_MSVC
256#elif defined(__MINGW32__) || defined(__MINGW64__)
257# define GEO_COMPILER_MINGW
258#endif
259
260#if defined(_WIN64)
261# define GEO_ARCH_64
262#else
263# define GEO_ARCH_32
264#endif
265
266// =============================== APPLE defines ===========================
267
268#elif defined(__APPLE__)
269
270#define GEO_OS_APPLE
271#define GEO_OS_UNIX
272
273#if defined(_OPENMP)
274# define GEO_OPENMP
275#endif
276
277#if defined(__clang__)
278# define GEO_COMPILER_CLANG
279#elif defined(__GNUC__)
280# define GEO_COMPILER_GCC
281#else
282# error "Unsupported compiler"
283#endif
284
285#if defined(__x86_64) || defined(__ppc64__) || defined(__arm64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch_lp64)
286# define GEO_ARCH_64
287#else
288# define GEO_ARCH_32
289#endif
290
291// =============================== Emscripten defines ======================
292
293#elif defined(__EMSCRIPTEN__)
294
295#include <emscripten.h>
296
297#define GEO_OS_UNIX
298#define GEO_OS_LINUX
299#define GEO_OS_EMSCRIPTEN
300#define GEO_ARCH_64
301#define GEO_COMPILER_EMSCRIPTEN
302#define GEO_COMPILER_CLANG
303
304// =============================== Unsupported =============================
305#else
306#error "Unsupported operating system"
307#endif
308
309#if defined(GEO_COMPILER_GCC) || \
310 defined(GEO_COMPILER_CLANG) || \
311 defined(GEO_COMPILER_MINGW) || \
312 defined(GEO_COMPILER_EMSCRIPTEN)
313#define GEO_COMPILER_GCC_FAMILY
314#endif
315
316#ifdef DOXYGEN_ONLY
317// Keep doxygen happy
318#define GEO_OS_WINDOWS
319#define GEO_OS_APPLE
320#define GEO_OS_ANDROID
321#define GEO_ARCH_32
322#define GEO_COMPILER_INTEL
323#define GEO_COMPILER_MSVC
324#endif
325
330#define CPP_CONCAT_(A, B) A ## B
331
336#define CPP_CONCAT(A, B) CPP_CONCAT_(A, B)
337
338#if defined(GOMGEN)
339#define GEO_NORETURN
340#elif defined(GEO_COMPILER_GCC_FAMILY) || \
341 defined(GEO_COMPILER_INTEL)
342#define GEO_NORETURN __attribute__((noreturn))
343#else
344#define GEO_NORETURN
345#endif
346
347#if defined(GOMGEN)
348#define GEO_NORETURN_DECL
349#elif defined(GEO_COMPILER_MSVC)
350#define GEO_NORETURN_DECL __declspec(noreturn)
351#else
352#define GEO_NORETURN_DECL
353#endif
354
355#if defined(GEO_COMPILER_CLANG) || defined(GEO_COMPILER_EMSCRIPTEN)
356#if __has_feature(cxx_noexcept)
357#define GEO_NOEXCEPT noexcept
358#endif
359#endif
360
361// For Graphite GOM generator (swig is confused by throw() specifier)
362#ifdef GOMGEN
363#define GEO_NOEXCEPT
364#endif
365
366#ifndef GEO_NOEXCEPT
367#define GEO_NOEXCEPT throw()
368#endif
369
370#if defined(GOMGEN)
371#define GEO_NODISCARD
372#else
373#define GEO_NODISCARD [[nodiscard]]
374#endif
375
376#define FOR(I,UPPERBND) for(index_t I = 0; I<index_t(UPPERBND); ++I)
377
378// Silence warnings for alloca()
379// We use it at different places to allocate objects on the stack
380// (for instance, in multi-precision predicates).
381#ifdef GEO_COMPILER_CLANG
382#pragma GCC diagnostic ignored "-Walloca"
383#endif
384
385// =============================== Parallel STL ============================
386
387#if !defined(GEO_COMPILER_CLANG) && \
388 !defined(GEO_OS_EMSCRIPTEN) && \
389 !defined(GEO_NO_PARALLEL_STL)
390#define GEO_PARALLEL_STL
391#endif
392
393#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.