From fcf6a840cbf7cf046403f5314561dee3f235b9c7 Mon Sep 17 00:00:00 2001 From: Oliver Thomson Brown <8394906+otbrown@users.noreply.github.com> Date: Wed, 11 Jun 2025 17:24:14 +0100 Subject: [PATCH 1/4] Promoted variables set in compile_option CMake function to parent scope, which ensures correct values are generated in the header file. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1080c55fc..16ea69e83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ else() set(MULTI_LIB_HEADERS 0) function(compile_option VAR VALUE) target_compile_definitions(QuEST PRIVATE ${VAR}=${VALUE}) - set(${VAR} ${VALUE}) + set(${VAR} ${VALUE} PARENT_SCOPE) endfunction() endif() From 61cd1dced475b5c756bed06815e92bba5805d36c Mon Sep 17 00:00:00 2001 From: Oliver Thomson Brown Date: Fri, 13 Jun 2025 14:50:41 +0100 Subject: [PATCH 2/4] Separated compilation configuration defines into config.h --- CMakeLists.txt | 7 ++++++- quest/include/CMakeLists.txt | 2 +- quest/include/config.h.in | 15 +++++++++++++++ quest/include/{quest.h.in => quest.h} | 12 ++---------- 4 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 quest/include/config.h.in rename quest/include/{quest.h.in => quest.h} (87%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16ea69e83..d10721947 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -576,13 +576,18 @@ install(FILES DESTINATION "${QuEST_INSTALL_CONFIGDIR}" ) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/quest.h" +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/quest/include/quest.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/quest/include/config.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/quest/include" +) + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/quest/include" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/quest" FILES_MATCHING PATTERN "*.h" + PATTERN "quest.h" EXCLUDE ) install(EXPORT QuESTTargets diff --git a/quest/include/CMakeLists.txt b/quest/include/CMakeLists.txt index 86a542dc5..bf0d1cd09 100644 --- a/quest/include/CMakeLists.txt +++ b/quest/include/CMakeLists.txt @@ -2,4 +2,4 @@ # @author Erich Essmann # @author Luc Jaulmes (using config file) -configure_file(quest.h.in "${CMAKE_BINARY_DIR}/include/quest.h" @ONLY) +configure_file(config.h.in "${CMAKE_BINARY_DIR}/include/quest/include/config.h" @ONLY) diff --git a/quest/include/config.h.in b/quest/include/config.h.in new file mode 100644 index 000000000..4c832a76e --- /dev/null +++ b/quest/include/config.h.in @@ -0,0 +1,15 @@ +#ifndef CONFIG_H +#define CONFIG_H + + +// bind compile settings to installed exec +#if !@MULTI_LIB_HEADERS@ +#cmakedefine FLOAT_PRECISION @FLOAT_PRECISION@ +#cmakedefine01 COMPILE_MPI +#cmakedefine01 COMPILE_OPENMP +#cmakedefine01 COMPILE_CUDA +#cmakedefine01 COMPILE_CUQUANTUM +#endif + + +#endif \ No newline at end of file diff --git a/quest/include/quest.h.in b/quest/include/quest.h similarity index 87% rename from quest/include/quest.h.in rename to quest/include/quest.h index 4ba420478..fcc49ab76 100644 --- a/quest/include/quest.h.in +++ b/quest/include/quest.h @@ -31,20 +31,12 @@ #define QUEST_H -// bind compile settings to installed exec -#if !@MULTI_LIB_HEADERS@ -#cmakedefine FLOAT_PRECISION @FLOAT_PRECISION@ -#cmakedefine01 COMPILE_MPI -#cmakedefine01 COMPILE_OPENMP -#cmakedefine01 COMPILE_CUDA -#cmakedefine01 COMPILE_CUQUANTUM -#endif - - // include version first so it is accessible to // debuggers in case a subsequent include fails #include "quest/include/version.h" +#include "quest/include/config.h" + // include before API headers since it validates // preprocessor configuration, and affirms macro // preconditions assumed by subsequent header From 85f8ed06bb0e4eaa7ec24182f909f65925f44f19 Mon Sep 17 00:00:00 2001 From: Oliver Thomson Brown Date: Fri, 13 Jun 2025 15:34:03 +0100 Subject: [PATCH 3/4] Added guards to check at least one of the required compiler macros is undefined as proposed by @TysonRayJones --- quest/include/config.h.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/quest/include/config.h.in b/quest/include/config.h.in index 4c832a76e..8326259b6 100644 --- a/quest/include/config.h.in +++ b/quest/include/config.h.in @@ -1,6 +1,12 @@ #ifndef CONFIG_H #define CONFIG_H +// be warned, the below is sensitive to whitespace after the slash +#if !defined(FLOAT_PRECISION)\ + || !defined(COMPILE_MPI)\ + || !defined(COMPILE_OPENMP)\ + || !defined(COMPILE_CUDA)\ + || !defined(COMPILE_CUQUANTUM) // bind compile settings to installed exec #if !@MULTI_LIB_HEADERS@ @@ -11,5 +17,6 @@ #cmakedefine01 COMPILE_CUQUANTUM #endif +#endif #endif \ No newline at end of file From 1f1e70288a57beca091f8f84bc55eefdad037ac4 Mon Sep 17 00:00:00 2001 From: Oliver Thomson Brown Date: Fri, 13 Jun 2025 15:48:50 +0100 Subject: [PATCH 4/4] modes.h: removed guards which prevented COMPILE macros from being defined, as proposed by @TysonRayJones --- quest/include/modes.h | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/quest/include/modes.h b/quest/include/modes.h index b90797acd..667a3f053 100644 --- a/quest/include/modes.h +++ b/quest/include/modes.h @@ -15,27 +15,8 @@ -// ensure all mode flags are defined - -#ifndef COMPILE_MPI - #error "Compiler must define COMPILE_MPI" -#endif - -#ifndef COMPILE_OPENMP - #error "Compiler must define COMPILE_OPENMP" -#endif - -#ifndef COMPILE_CUDA - #error "Compiler must define COMPILE_CUDA" -#endif - -#ifndef COMPILE_CUQUANTUM - #error "Compiler must define COMPILE_CUQUANTUM" -#endif - - - // ensure all mode flags are valid values +// undefined allowed as undefined == 0 in C/C++ standards #if ! (COMPILE_MPI == 0 || COMPILE_MPI == 1) #error "Macro COMPILE_MPI must have value 0 or 1"