The Quantum Exact Simulation Toolkit v4.3.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 QUEST_FLOAT_PRECISION cannot ever be changed from
11 * their value during source compilation. Finally, it enables
12 * users to access macros such as QUEST_COMPILE_OMP 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(QUEST_FLOAT_PRECISION) || \
38 defined(QUEST_COMPILE_OMP) || \
39 defined(QUEST_COMPILE_MPI) || \
40 defined(QUEST_COMPILE_SUBCOMM) || \
41 defined(QUEST_COMPILE_CUDA) || \
42 defined(QUEST_COMPILE_HIP) || \
43 defined(QUEST_COMPILE_CUQUANTUM) || \
44 defined(QUEST_COMPILE_ADIOS2) || \
45 defined(QUEST_COMPILE_BMI2) || \
46 defined(QUEST_ENABLE_NUMA) || \
47 defined(QUEST_INCLUDE_DEPRECATED_FUNCTIONS) || \
48 defined(QUEST_DISABLE_DEPRECATION_WARNINGS)
49
50 #error "Pre-config macros were erroneously passed directly to the source rather than through the CMake config file."
51
52#endif
53
54
55#if defined(QUEST_VERSION_MAJOR) || \
56 defined(QUEST_VERSION_MINOR) || \
57 defined(QUEST_VERSION_PATCH) || \
58 defined(QUEST_VERSION_STRING)
59
60 #error "QuEST version macros were erroneously passed directly to the source rather than through the CMake config file."
61
62#endif
63
64
65
66/*
67 * save the CMake option values as macros.
68 *
69 * Note we use cmakedefine (rather than just define @VAL) so that
70 * the macro is totally avoided being defined if the corresponding
71 * CMake variable was not passed to this config file, which we can
72 * subsequently detect and error-out below
73 */
74
75
76// crucial to user source (informs API)
77#cmakedefine QUEST_FLOAT_PRECISION @QUEST_FLOAT_PRECISION@
78#cmakedefine01 QUEST_INCLUDE_DEPRECATED_FUNCTIONS
79#cmakedefine01 QUEST_DISABLE_DEPRECATION_WARNINGS
80
81
82// crucial to QuEST source (informs external library usage)
83#cmakedefine01 QUEST_COMPILE_OMP
84#cmakedefine01 QUEST_COMPILE_MPI
85#cmakedefine01 QUEST_COMPILE_SUBCOMM
86#cmakedefine01 QUEST_COMPILE_CUDA
87#cmakedefine01 QUEST_COMPILE_CUQUANTUM
88#cmakedefine01 QUEST_COMPILE_HIP
89#cmakedefine01 QUEST_COMPILE_ADIOS2
90#cmakedefine01 QUEST_COMPILE_BMI2
91
92
93// crucial to QuEST source (informs optional NUMA usage)
94#cmakedefine01 QUEST_ENABLE_NUMA
95
96
97// default parameters which may have been tuned for performance when building the library
98#cmakedefine QUEST_UNSPECIFIED_DEFAULT_NUM_GPU_THREADS_PER_BLOCK @QUEST_UNSPECIFIED_DEFAULT_NUM_GPU_THREADS_PER_BLOCK@
99
100
101
102/*
103 * inherit the version information from CMake.
104 *
105 * Note we do not (and actually cannot) validate these using the
106 * cmakedefine trick used above since they are always gauranteed
107 * to be passed and substituted by CMake
108 */
109
110
111#define QUEST_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
112#define QUEST_VERSION_MINOR @PROJECT_VERSION_MINOR@
113#define QUEST_VERSION_PATCH @PROJECT_VERSION_PATCH@
114#define QUEST_VERSION_STRING "@PROJECT_VERSION@"
115
116
117
118/*
119 * check that all above expected CMake options were
120 * actually passed (since use of 'cmakedefine' means
121 * they otherwise default to no macro definition)
122 */
123
124
125#if ! defined(QUEST_FLOAT_PRECISION) || \
126 ! defined(QUEST_COMPILE_OMP) || \
127 ! defined(QUEST_COMPILE_MPI) || \
128 ! defined(QUEST_COMPILE_SUBCOMM) || \
129 ! defined(QUEST_COMPILE_CUDA) || \
130 ! defined(QUEST_COMPILE_HIP) || \
131 ! defined(QUEST_COMPILE_CUQUANTUM) || \
132 ! defined(QUEST_COMPILE_ADIOS2) || \
133 ! defined(QUEST_COMPILE_BMI2) || \
134 ! defined(QUEST_ENABLE_NUMA) || \
135 ! defined(QUEST_INCLUDE_DEPRECATED_FUNCTIONS) || \
136 ! defined(QUEST_DISABLE_DEPRECATION_WARNINGS)
137
138 #error "Expected macros were not defined by the config.h header, possibly because their corresponding CMake variables were not substituted."
139
140#endif
141
142
143
144/*
145 * validate boolean macro definitions.
146 *
147 * Note that more specific checks (e.g. whether non-boolean
148 * macros have legal values, or whether combinations of
149 * multiple macro values are legal) are performed by the files
150 * that concern them. These checks merely validate the macro
151 * has the right 'type' so will not trip up other preprocesing
152 */
153
154
155#if ! (QUEST_COMPILE_OMP == 0 || QUEST_COMPILE_OMP == 1) || \
156 ! (QUEST_COMPILE_MPI == 0 || QUEST_COMPILE_MPI == 1) || \
157 ! (QUEST_COMPILE_SUBCOMM == 0 || QUEST_COMPILE_SUBCOMM == 1) || \
158 ! (QUEST_COMPILE_CUDA == 0 || QUEST_COMPILE_CUDA == 1) || \
159 ! (QUEST_COMPILE_HIP == 0 || QUEST_COMPILE_HIP == 1) || \
160 ! (QUEST_COMPILE_CUQUANTUM == 0 || QUEST_COMPILE_CUQUANTUM == 1) || \
161 ! (QUEST_COMPILE_ADIOS2 == 0 || QUEST_COMPILE_ADIOS2 == 1) || \
162 ! (QUEST_COMPILE_BMI2 == 0 || QUEST_COMPILE_BMI2 == 1) || \
163 ! (QUEST_ENABLE_NUMA == 0 || QUEST_ENABLE_NUMA == 1) || \
164 ! (QUEST_INCLUDE_DEPRECATED_FUNCTIONS == 0 || QUEST_INCLUDE_DEPRECATED_FUNCTIONS == 1) || \
165 ! (QUEST_DISABLE_DEPRECATION_WARNINGS == 0 || QUEST_DISABLE_DEPRECATION_WARNINGS == 1)
166
167 #error "A macro defined by the config.h header (as inferred from a CMake variable) had an illegal value."
168
169#endif
170
171
172// ensure __cplusplus macro is valid (API headers use #ifdef, not #if)
173
174#ifdef __cplusplus
175#if !__cplusplus
176#error "Preprocessor __cplusplus was 0 and should instead be undefined"
177#endif
178#endif
179
180
181
182#endif // CONFIG_H