Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#pragma once
2
3#if defined USE_CMAKE_CONFIG_H
4 #include "cmake_config.h" // IWYU pragma: export
5#else
6 #warning Missing configuration
7#endif
8
9/*
10 * There are three ways a Minetest source file can be built:
11 * 1) we are currently building it for exclusively linking into the client
12 * 2) we are currently building it for exclusively linking into the server
13 * 3) we are building it only once for linking into both the client and server
14 * In case of 1 and 2 that means a single source file may be built twice if
15 * both a client and server build was requested.
16 *
17 * These options map to the following macros:
18 * 1) IS_CLIENT_BUILD = 1 and CHECK_CLIENT_BUILD() = 1
19 * 2) IS_CLIENT_BUILD = 0 and CHECK_CLIENT_BUILD() = 0
20 * 3) IS_CLIENT_BUILD = 0 and CHECK_CLIENT_BUILD() undefined
21 * As a function style macro CHECK_CLIENT_BUILD() has the special property that it
22 * cause a compile error if it used but not defined.
23 *
24 * v v v v v v v v v READ THIS PART v v v v v v v v v
25 * So that object files can be safely shared, these macros need to be used like so:
26 * - use IS_CLIENT_BUILD to exclude optional helpers in header files or similar
27 * - use CHECK_CLIENT_BUILD() in all source files, or in headers where it
28 * influences program behavior or e.g. class structure
29 * In practice this means any shared object files (case 3) cannot include any
30 * code that references CHECK_CLIENT_BUILD(), because a compiler error will occur.
31 * ^ ^ ^ ^ ^ ^ ^ ^ ^ READ THIS PART ^ ^ ^ ^ ^ ^ ^ ^ ^
32 *
33 * The background is that for any files built only once, we need to ensure that
34 * they are perfectly ABI-compatible between client/server or it will not work.
35 * This manifests either as a linker error (good case) or insidious memory corruption
36 * that causes obscure runtime behavior (bad case).
37 * Finally, note that the best option is to split code in such a way that usage
38 * of these macros is not necessary.
39 */
40#if MT_BUILDTARGET == 1
41#define IS_CLIENT_BUILD 1
42#define CHECK_CLIENT_BUILD() 1
43#elif MT_BUILDTARGET == 2
44#define IS_CLIENT_BUILD 0
45#define CHECK_CLIENT_BUILD() 0
46#else
47#define IS_CLIENT_BUILD 0
48#endif
49#undef MT_BUILDTARGET