@@ -122,6 +122,58 @@ static inline std::string locateSDK()
122122#endif
123123}
124124
125+ struct located_sdk
126+ {
127+ std::string path;
128+ enum
129+ {
130+ none, // Nothing was found
131+ platform, // Building against /usr/include, useful for dev builds
132+ official // The SDK obtained from official score releases
133+ } sdk_kind
134+ = none;
135+
136+ // Do we use the score source dir or the headers from the SDK
137+ #if !SCORE_FHS_BUILD
138+ static constexpr bool deploying = true ;
139+ #else
140+ static constexpr bool deploying = false ;
141+ #endif
142+ };
143+
144+ inline located_sdk locateSDKWithFallback ()
145+ {
146+ located_sdk ret;
147+ ret.path = locateSDK ();
148+ if (ret.path .empty ())
149+ ret.sdk_kind = located_sdk::none;
150+ if (ret.path .starts_with (" /usr" ) || ret.path .starts_with (" /Applications" ))
151+ ret.sdk_kind = located_sdk::official;
152+ else
153+ ret.sdk_kind = located_sdk::platform;
154+
155+ {
156+ QDir dir (QString::fromStdString (ret.path ));
157+ if (!dir.exists ())
158+ ret.sdk_kind = located_sdk::none;
159+
160+ if (!dir.cd (" include" ) || !dir.cd (" c++" ))
161+ {
162+ qDebug () << " Unable to locate standard headers, fallback to /usr" ;
163+ ret.path = " /usr" ;
164+ dir.setPath (" /usr" );
165+ if (!dir.cd (" include" ) || !dir.cd (" c++" ))
166+ {
167+ qDebug () << " Unable to locate any standard headers, install C++ development "
168+ " toolchain" ;
169+ throw std::runtime_error (" Unable to compile" );
170+ }
171+ ret.sdk_kind = located_sdk::platform;
172+ }
173+ }
174+ return ret;
175+ }
176+
125177static inline void
126178populateCompileOptions (std::vector<std::string>& args, CompilerOptions opts)
127179{
@@ -580,29 +632,9 @@ static inline auto getPotentialTriples()
580632 */
581633static inline void populateIncludeDirs (std::vector<std::string>& args)
582634{
583- auto sdk = locateSDK ();
635+ auto sdk_location = locateSDKWithFallback ();
636+ auto & sdk = sdk_location.path ;
584637 auto qsdk = QString::fromStdString (sdk);
585- std::cerr << " \n Looking for sdk in: " << sdk << " \n " ;
586- qDebug () << " Looking for sdk in: " << qsdk;
587-
588- bool sdk_found = true ;
589-
590- {
591- QDir dir (qsdk);
592- if (!dir.cd (" include" ) || !dir.cd (" c++" ))
593- {
594- qDebug () << " Unable to locate standard headers, fallback to /usr" ;
595- qsdk = " /usr" ;
596- sdk = " /usr" ;
597- dir.setPath (" /usr" );
598- if (!dir.cd (" include" ) || !dir.cd (" c++" ))
599- {
600- qDebug () << " Unable to locate standard headers++" ;
601- throw std::runtime_error (" Unable to compile" );
602- }
603- sdk_found = false ;
604- }
605- }
606638
607639 qDebug () << " SDK located: " << qsdk;
608640 std::string llvm_lib_version = SCORE_LLVM_VERSION ;
@@ -699,12 +731,27 @@ static inline void populateIncludeDirs(std::vector<std::string>& args)
699731 // /build/score.AppDir/usr/include/
700732
701733 auto include = [&](const std::string& path) {
702- args.push_back (" -isystem" + sdk + " /include/" + path);
734+ std::string path_to_include = sdk + " /include/" + path;
735+ auto qpath = QString::fromStdString (path_to_include);
736+ if (!QFileInfo{qpath}.isDir ())
737+ {
738+ qDebug () << " Trying to include non-existent path: " << qpath;
739+ }
740+ else
741+ {
742+ args.push_back (" -isystem" + sdk + " /include/" + path);
743+ }
703744 };
704745
705746#if defined(__linux__)
706- include (" x86_64-linux-gnu" ); // #debian
747+ // #debian
748+ #if defined(__x86_64__)
749+ include (" x86_64-linux-gnu" );
750+ #else
751+ include (" aarch64-linux-gnu" );
707752#endif
753+ #endif
754+
708755 // include(""); // /usr/include
709756 std::string qt_folder = " qt" ;
710757 if (QFile::exists (qsdk + " /include/qt6/QtCore" ))
@@ -745,16 +792,9 @@ static inline void populateIncludeDirs(std::vector<std::string>& args)
745792 include (qt_folder + " /QtShaderTools" );
746793 include (qt_folder + " /QtShaderTools/" + qt_version);
747794 include (qt_folder + " /QtShaderTools/" + qt_version + " /QtShaderTools" );
748- include (qt_folder + " /QtSerialBus" );
749795 include (qt_folder + " /QtSerialPort" );
750796
751- #if !SCORE_FHS_BUILD
752- bool deploying = true ;
753- #else
754- bool deploying = false ;
755- #endif
756-
757- if (deploying && sdk_found)
797+ if (sdk_location.sdk_kind == located_sdk::official && sdk_location.deploying )
758798 {
759799 include (" score" );
760800 }
0 commit comments