Skip to content

Commit f28691c

Browse files
authored
Patched quest.h generation (#645)
- Promoted variables set in compile_option CMake function to parent scope, which ensures correct values are generated in the header file. - Separated compilation configuration defines into config.h - Added guards to check at least one of the required compiler macros is undefined as proposed by @TysonRayJones - Removed guards from modes.h which prevented COMPILE macros from being defined, as proposed by @TysonRayJones
1 parent c357267 commit f28691c

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ else()
7979
set(MULTI_LIB_HEADERS 0)
8080
function(compile_option VAR VALUE)
8181
target_compile_definitions(QuEST PRIVATE ${VAR}=${VALUE})
82-
set(${VAR} ${VALUE})
82+
set(${VAR} ${VALUE} PARENT_SCOPE)
8383
endfunction()
8484
endif()
8585

@@ -576,13 +576,18 @@ install(FILES
576576
DESTINATION "${QuEST_INSTALL_CONFIGDIR}"
577577
)
578578

579-
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/quest.h"
579+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/quest/include/quest.h"
580580
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
581581
)
582582

583+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/quest/include/config.h"
584+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/quest/include"
585+
)
586+
583587
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/quest/include"
584588
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/quest"
585589
FILES_MATCHING PATTERN "*.h"
590+
PATTERN "quest.h" EXCLUDE
586591
)
587592

588593
install(EXPORT QuESTTargets

quest/include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# @author Erich Essmann
33
# @author Luc Jaulmes (using config file)
44

5-
configure_file(quest.h.in "${CMAKE_BINARY_DIR}/include/quest.h" @ONLY)
5+
configure_file(config.h.in "${CMAKE_BINARY_DIR}/include/quest/include/config.h" @ONLY)

quest/include/config.h.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef CONFIG_H
2+
#define CONFIG_H
3+
4+
// be warned, the below is sensitive to whitespace after the slash
5+
#if !defined(FLOAT_PRECISION)\
6+
|| !defined(COMPILE_MPI)\
7+
|| !defined(COMPILE_OPENMP)\
8+
|| !defined(COMPILE_CUDA)\
9+
|| !defined(COMPILE_CUQUANTUM)
10+
11+
// bind compile settings to installed exec
12+
#if !@MULTI_LIB_HEADERS@
13+
#cmakedefine FLOAT_PRECISION @FLOAT_PRECISION@
14+
#cmakedefine01 COMPILE_MPI
15+
#cmakedefine01 COMPILE_OPENMP
16+
#cmakedefine01 COMPILE_CUDA
17+
#cmakedefine01 COMPILE_CUQUANTUM
18+
#endif
19+
20+
#endif
21+
22+
#endif

quest/include/modes.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,8 @@
1515

1616

1717

18-
// ensure all mode flags are defined
19-
20-
#ifndef COMPILE_MPI
21-
#error "Compiler must define COMPILE_MPI"
22-
#endif
23-
24-
#ifndef COMPILE_OPENMP
25-
#error "Compiler must define COMPILE_OPENMP"
26-
#endif
27-
28-
#ifndef COMPILE_CUDA
29-
#error "Compiler must define COMPILE_CUDA"
30-
#endif
31-
32-
#ifndef COMPILE_CUQUANTUM
33-
#error "Compiler must define COMPILE_CUQUANTUM"
34-
#endif
35-
36-
37-
3818
// ensure all mode flags are valid values
19+
// undefined allowed as undefined == 0 in C/C++ standards
3920

4021
#if ! (COMPILE_MPI == 0 || COMPILE_MPI == 1)
4122
#error "Macro COMPILE_MPI must have value 0 or 1"

quest/include/quest.h.in renamed to quest/include/quest.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,12 @@
3131
#define QUEST_H
3232

3333

34-
// bind compile settings to installed exec
35-
#if !@MULTI_LIB_HEADERS@
36-
#cmakedefine FLOAT_PRECISION @FLOAT_PRECISION@
37-
#cmakedefine01 COMPILE_MPI
38-
#cmakedefine01 COMPILE_OPENMP
39-
#cmakedefine01 COMPILE_CUDA
40-
#cmakedefine01 COMPILE_CUQUANTUM
41-
#endif
42-
43-
4434
// include version first so it is accessible to
4535
// debuggers in case a subsequent include fails
4636
#include "quest/include/version.h"
4737

38+
#include "quest/include/config.h"
39+
4840
// include before API headers since it validates
4941
// preprocessor configuration, and affirms macro
5042
// preconditions assumed by subsequent header

0 commit comments

Comments
 (0)