Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:31

0001 #pragma once
0002 /**
0003 sbuild.h
0004 =========
0005 
0006 ~/o/sysrap/tests/sbuild_test.sh
0007 
0008 Curious the simple script build has no problem
0009 with variable names the same as the macros, but the
0010 CMake build gives error::
0011 
0012     <command-line>: error: expected unqualified-id before numeric constant
0013     /home/blyth/opticks/sysrap/tests/../sbuild.h:39:33: note: in expansion of macro ‘WITH_CHILD’
0014        39 |     static constexpr const bool WITH_CHILD = true ;
0015           |                                 ^~~~~~~~~~
0016 
0017 The difference is not from c++11 vs c++17, must be some other option with the CMake build.
0018 Due to this prefixed the names with underscore.
0019 
0020 **/
0021 
0022 #include <cstring>
0023 #include <string>
0024 #include <sstream>
0025 
0026 #include "srng.h"
0027 
0028 
0029 struct sbuild
0030 {
0031     static constexpr const char* Debug   = "Debug" ;
0032     static constexpr const char* Release = "Release" ;
0033 
0034 
0035 #if defined(CONFIG_Debug)
0036     static constexpr const char* BUILD_TYPE = "Debug" ;
0037 #elif defined(CONFIG_Release)
0038     static constexpr const char* BUILD_TYPE = "Release" ;
0039 #elif defined(CONFIG_RelWithDebInfo)
0040     static constexpr const char* BUILD_TYPE = "RelWithDebInfo" ;
0041 #elif defined(CONFIG_MinSizeRel)
0042     static constexpr const char* BUILD_TYPE = "MinSizeRel" ;
0043 #else
0044     static constexpr const char* BUILD_TYPE = "sbuild-ERROR-NO-CONFIG-MACROS" ;
0045 #endif
0046 
0047 #if defined(PRODUCTION)
0048     static constexpr const bool _PRODUCTION = true ;
0049 #else
0050     static constexpr const bool _PRODUCTION = false ;
0051 #endif
0052 
0053 #if defined(WITH_CHILD)
0054     static constexpr const bool _WITH_CHILD = true ;
0055 #else
0056     static constexpr const bool _WITH_CHILD = false ;
0057 #endif
0058 
0059 #if defined(WITH_CUSTOM4)
0060     static constexpr const bool _WITH_CUSTOM4 = true ;
0061 #else
0062     static constexpr const bool _WITH_CUSTOM4 = false ;
0063 #endif
0064 
0065 #if defined(PLOG_LOCAL)
0066     static constexpr const bool _PLOG_LOCAL = true ;
0067 #else
0068     static constexpr const bool _PLOG_LOCAL = false ;
0069 #endif
0070 
0071 #if defined(DEBUG_PIDX)
0072     static constexpr const bool _DEBUG_PIDX = true ;
0073 #else
0074     static constexpr const bool _DEBUG_PIDX = false ;
0075 #endif
0076 
0077 #if defined(DEBUG_TAG)
0078     static constexpr const bool _DEBUG_TAG = true ;
0079 #else
0080     static constexpr const bool _DEBUG_TAG = false ;
0081 #endif
0082 
0083 
0084 #if defined(RNG_XORWOW)
0085     static constexpr const bool _RNG_XORWOW = true ;
0086 #else
0087     static constexpr const bool _RNG_XORWOW = false ;
0088 #endif
0089 
0090 #if defined(RNG_PHILOX)
0091     static constexpr const bool _RNG_PHILOX = true ;
0092 #else
0093     static constexpr const bool _RNG_PHILOX = false ;
0094 #endif
0095 
0096 #if defined(RNG_PHILITEOX)
0097     static constexpr const bool _RNG_PHILITEOX = true ;
0098 #else
0099     static constexpr const bool _RNG_PHILITEOX = false ;
0100 #endif
0101 
0102 
0103     static const char* RNGName()
0104     {
0105         return srng<RNG>::NAME ;
0106     }
0107     static bool IsDebug(){   return strcmp(BUILD_TYPE, Debug) == 0 ; }
0108     static bool IsRelease(){ return strcmp(BUILD_TYPE, Release) == 0 ; }
0109 
0110     static std::string Desc();
0111     static std::string ContextString();
0112     static const char* BuildType();
0113 
0114     static bool BuildTypeMatches(const char* arg);
0115     static bool RNGMatches(const char* arg);
0116     static bool Matches(const char* arg);
0117 };
0118 
0119 
0120 inline std::string sbuild::Desc() // static
0121 {
0122     std::stringstream ss ;
0123     ss
0124        << "[sbuild::Desc\n"
0125        << " sbuild::ContextString() : [" << ContextString() << "]\n"
0126        << " sbuild::BUILD_TYPE      : [" << BUILD_TYPE << "]\n"
0127        << " sbuild::IsDebug()       :  "  << ( IsDebug() ? "YES" : "NO " ) << "\n"
0128        << " sbuild::IsRelease()     :  "  << ( IsRelease() ? "YES" : "NO " ) << "\n"
0129        << " sbuild::BuildTypeMatches(\"Cheese\") : " << sbuild::BuildTypeMatches("Cheese") << "\n"
0130        << " sbuild::BuildTypeMatches(\"Cheese Debug \") : " << sbuild::BuildTypeMatches("Cheese Debug") << "\n"
0131        << " sbuild::BuildTypeMatches(\"Cheese Release \") : " << sbuild::BuildTypeMatches("Cheese Release ") << "\n"
0132        << " srng<RNG>::NAME      : [" << srng<RNG>::NAME << "]\n"
0133        << " sbuild::RNGName()    : [" << RNGName() << "]\n"
0134        << " sbuild::RNGMatches(\"Cheese\") : " << sbuild::RNGMatches("Cheese") << "\n"
0135        << " sbuild::RNGMatches(\"Cheese XORWOW\") : " << sbuild::RNGMatches("Cheese XORWOW ") << "\n"
0136        << " sbuild::RNGMatches(\"Cheese Philox\") : " << sbuild::RNGMatches("Cheese Philox ") << "\n"
0137        << " _PRODUCTION          : " << ( _PRODUCTION ? "YES" :  "NO " ) << "\n"
0138        << " _WITH_CHILD          : " << ( _WITH_CHILD ? "YES" :  "NO " ) << "\n"
0139        << " _WITH_CUSTOM4        : " << ( _WITH_CUSTOM4 ? "YES" :  "NO " ) << "\n"
0140        << " _PLOG_LOCAL          : " << ( _PLOG_LOCAL ? "YES" :  "NO " ) << "\n"
0141        << " _DEBUG_PIDX          : " << ( _DEBUG_PIDX ? "YES" :  "NO " ) << "\n"
0142        << " _DEBUG_TAG           : " << ( _DEBUG_TAG ? "YES" :  "NO " ) << "\n"
0143        << " _RNG_XORWOW          : " << ( _RNG_XORWOW ? "YES" :  "NO " ) << "\n"
0144        << " _RNG_PHILOX          : " << ( _RNG_PHILOX ? "YES" :  "NO " ) << "\n"
0145        << " _RNG_PHILITEOX       : " << ( _RNG_PHILITEOX ? "YES" :  "NO " ) << "\n"
0146        << " sbuild::Matches(\"ALL99_Release_XORWOW\") : " << sbuild::Matches("ALL99_Release_XORWOW") << "\n"
0147        << " sbuild::Matches(\"ALL99_Release_Philox\") : " << sbuild::Matches("ALL99_Release_Philox") << "\n"
0148        << " sbuild::Matches(\"ALL99_Debug_XORWOW\") : " << sbuild::Matches("ALL99_Debug_XORWOW") << "\n"
0149        << " sbuild::Matches(\"ALL99_Debug_Philox\") : " << sbuild::Matches("ALL99_Debug_Philox") << "\n"
0150        << "]sbuild::Desc\n"
0151        ;
0152     std::string str = ss.str() ;
0153     return str ;
0154 }
0155 
0156 inline std::string sbuild::ContextString() // static
0157 {
0158     std::stringstream ss ;
0159     ss << BUILD_TYPE << "_" << RNGName() ;
0160     std::string str = ss.str() ;
0161     return str ;
0162 }
0163 
0164 inline const char* sbuild::BuildType() // static
0165 {
0166     return BUILD_TYPE ;
0167 }
0168 
0169 
0170 
0171 /**
0172 sbuild::BuildTypeMatches
0173 --------------------------
0174 
0175 When the argument string contains "Debug" or "Release"
0176 then then sbuild::BUILD_TYPE is required to match
0177 that to return true.
0178 
0179 **/
0180 
0181 inline bool sbuild::BuildTypeMatches(const char* arg)
0182 {
0183     if(arg == nullptr) return false ;
0184     int match = 0 ;
0185     if(strstr(arg, Debug)   && IsDebug())   match += 1 ;
0186     if(strstr(arg, Release) && IsRelease()) match += 1 ;
0187     return match == 1 ;
0188 }
0189 
0190 inline bool sbuild::RNGMatches(const char* arg)
0191 {
0192     return srng_Matches<RNG>(arg);
0193 }
0194 
0195 /**
0196 sbuild::Matches
0197 -----------------
0198 
0199 * Release/Debug
0200 * XORWOW/Philox
0201 
0202 Returns true when the argument contains the choices of the above
0203 strings that match the build settings.
0204 To make them match it is necessary to rebuild with different
0205 CMake level macro settings.
0206 
0207 This is used to ensure that descriptive TEST strings
0208 from envvars set in runner scripts correspond to the
0209 build currently being used. Those TEST strings are used
0210 to control output directories of saved events.
0211 
0212 **/
0213 
0214 inline bool sbuild::Matches(const char* arg)
0215 {
0216     return RNGMatches(arg) && BuildTypeMatches(arg) ;
0217 }
0218 
0219