The Quantum Exact Simulation Toolkit v4.2.0
Loading...
Searching...
No Matches
config.h.in
1/** @file
2 * The input file to CMake's configure_file() which produces
3 * the config.h header, which in-turn defines macros needed by
4 * the QuEST source, as informed by user-specified CMake options.
5 *
6 * Use of this configured header file enables all macros to be
7 * defined in one central place (right here) rather than being
8 * passed to each source file as compiler flags. It further
9 * ensures that when QuEST is installed, critical user-facing
10 * macros such as FLOAT_PRECISION cannot ever be changed from
11 * their value during source compilation. Finally, it enables
12 * users to access macros such as COMPILE_OPENMP at pre-build
13 * time of their own source code, which could prove necessary
14 * when interfacing with external libraries.
15 *
16 * Use of this config file however means that manual compilation
17 * (through GNUMake or a manual script) requires generating the
18 * config.h file manually.
19 *
20 * @author Luc Jaulmes
21 * @author Oliver Brown
22 * @author Tyson Jones (centralising macros, validation, doc)
23 */
24
25#ifndef CONFIG_H
26#define CONFIG_H
27
28
29
30/*
31 * check that the below CMake options are not being erroneously
32 * passed as macros (as was previously accepted), which would
33 * anyway trigger a 'macro redefined' warning below.
34 */
35
36
37#if defined(FLOAT_PRECISION) || \
38 defined(COMPILE_OPENMP) || \
39 defined(COMPILE_MPI) || \
40 defined(COMPILE_CUDA) || \
41 defined(COMPILE_HIP) || \
42 defined(COMPILE_CUQUANTUM) || \
43 defined(NUMA_AWARE) || \
44 defined(INCLUDE_DEPRECATED_FUNCTIONS) || \
45 defined(DISABLE_DEPRECATION_WARNINGS)
46
47 #error "Pre-config macros were erroneously passed directly to the source rather than through the CMake config file."
48
49#endif
50
51
52#if defined(QUEST_VERSION_MAJOR) || \
53 defined(QUEST_VERSION_MINOR) || \
54 defined(QUEST_VERSION_PATCH) || \
55 defined(QUEST_VERSION_STRING)
56
57 #error "QuEST version macros were erroneously passed directly to the source rather than through the CMake config file."
58
59#endif
60
61
62
63/*
64 * save the CMake option values as macros.
65 *
66 * Note we use cmakedefine (rather than just define @VAL) so that
67 * the macro is totally avoided being defined if the corresponding
68 * CMake variable was not passed to this config file, which we can
69 * subsequently detect and error-out below
70 */
71
72
73// crucial to user source (informs API)
74#cmakedefine FLOAT_PRECISION @FLOAT_PRECISION@
75#cmakedefine01 INCLUDE_DEPRECATED_FUNCTIONS
76#cmakedefine01 DISABLE_DEPRECATION_WARNINGS
77
78
79// crucial to QuEST source (informs external library usage)
80#cmakedefine01 COMPILE_OPENMP
81#cmakedefine01 COMPILE_MPI
82#cmakedefine01 COMPILE_CUDA
83#cmakedefine01 COMPILE_CUQUANTUM
84
85
86// not actually a CMake option (user cannot disable) but nonetheless crucial
87#cmakedefine01 NUMA_AWARE
88
89
90// not consulted by src (included for book-keeping)
91#cmakedefine01 COMPILE_HIP
92
93
94
95/*
96 * inherit the version information from CMake.
97 *
98 * Note we do not (and actually cannot) validate these using the
99 * cmakedefine trick used above since they are always gauranteed
100 * to be passed and substituted by CMake
101 */
102
103
104#define QUEST_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
105#define QUEST_VERSION_MINOR @PROJECT_VERSION_MINOR@
106#define QUEST_VERSION_PATCH @PROJECT_VERSION_PATCH@
107#define QUEST_VERSION_STRING "@PROJECT_VERSION@"
108
109
110
111/*
112 * check that all above expected CMake options were
113 * actually passed (since use of 'cmakedefine' means
114 * they otherwise default to no macro definition)
115 */
116
117
118#if ! defined(FLOAT_PRECISION) || \
119 ! defined(COMPILE_OPENMP) || \
120 ! defined(COMPILE_MPI) || \
121 ! defined(COMPILE_CUDA) || \
122 ! defined(COMPILE_HIP) || \
123 ! defined(COMPILE_CUQUANTUM) || \
124 ! defined(NUMA_AWARE) || \
125 ! defined(INCLUDE_DEPRECATED_FUNCTIONS) || \
126 ! defined(DISABLE_DEPRECATION_WARNINGS)
127
128 #error "Expected macros were not defined by the config.h header, possibly because their corresponding CMake variables were not substituted."
129
130#endif
131
132
133
134/*
135 * validate boolean macro definitions.
136 *
137 * Note that more specific checks (e.g. whether non-boolean
138 * macros have legal values, or whether combinations of
139 * multiple macro values are legal) are performed by the files
140 * that concern them. These checks merely validate the macro
141 * has the right 'type' so will not trip up other preprocesing
142 */
143
144
145#if ! (COMPILE_OPENMP == 0 || COMPILE_OPENMP == 1) || \
146 ! (COMPILE_MPI == 0 || COMPILE_MPI == 1) || \
147 ! (COMPILE_CUDA == 0 || COMPILE_CUDA == 1) || \
148 ! (COMPILE_HIP == 0 || COMPILE_HIP == 1) || \
149 ! (COMPILE_CUQUANTUM == 0 || COMPILE_CUQUANTUM == 1) || \
150 ! (NUMA_AWARE == 0 || NUMA_AWARE == 1) || \
151 ! (INCLUDE_DEPRECATED_FUNCTIONS == 0 || INCLUDE_DEPRECATED_FUNCTIONS == 1) || \
152 ! (DISABLE_DEPRECATION_WARNINGS == 0 || DISABLE_DEPRECATION_WARNINGS == 1)
153
154 #error "A macro defined by the config.h header (as inferred from a CMake variable) had an illegal value."
155
156#endif
157
158
159// ensure __cplusplus macro is valid (API headers use #ifdef, not #if)
160
161#ifdef __cplusplus
162#if !__cplusplus
163#error "Preprocessor __cplusplus was 0 and should instead be undefined"
164#endif
165#endif
166
167
168
169#endif // CONFIG_H