2 #include <Library/LibrarySettings.hpp>
4 #include <score/application/ApplicationContext.hpp>
6 #include <QApplication>
9 #include <QDirIterator>
11 #include <llvm/ADT/StringMap.h>
12 #include <llvm/ADT/StringRef.h>
14 #if LLVM_VERSION_MAJOR >= 17
15 #include <llvm/TargetParser/Host.h>
17 #include <llvm/Support/Host.h>
24 #if __has_include(<llvm/Config/llvm-config-64.h>)
25 #include <llvm/Config/llvm-config-64.h>
26 #elif __has_include(<llvm/Config/llvm-config.h>)
27 #include <llvm/Config/llvm-config.h>
30 #if defined(__has_feature)
31 #if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__)
32 #define __SANITIZE_ADDRESS__ 1
36 #if defined(SCORE_FHS_BUILD)
37 #define SCORE_USE_DISTRO_SYSROOT 1
39 #if defined(SCORE_DEPLOYMENT_BUILD)
40 #define SCORE_USE_DISTRO_SYSROOT 0
42 #define SCORE_USE_DISTRO_SYSROOT 1
46 #include <JitCpp/JitOptions.hpp>
48 #include <score_git_info.hpp>
53 static inline std::string locateSDK()
55 if(QString sdk = qgetenv(
"SCORE_JIT_SDK"); !sdk.isEmpty())
56 return sdk.toStdString();
59 QString path = ctx.getSDKPath();
61 if(QString libPath = QStringLiteral(
"%1/%2/usr").arg(path).arg(SCORE_TAG_NO_V);
62 QDir(libPath +
"/include/c++").exists())
64 return libPath.toStdString();
67 if(QString libPath = path +
"/usr"; QDir(libPath +
"/include/c++").exists())
69 return libPath.toStdString();
72 auto appFolder = qApp->applicationDirPath();
80 return d.absolutePath().toStdString();
82 #elif defined(__linux__)
87 return d.absolutePath().toStdString();
89 #elif defined(__APPLE__)
93 if(d.cd(
"Frameworks"))
95 if(d.cd(
"Score.Framework"))
97 return d.absolutePath().toStdString();
100 auto framework = QString(appFolder +
"/Score.Framework");
101 if(QDir{}.exists(framework))
102 return framework.toStdString();
104 return "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/"
105 "Developer/SDKs/MacOSX.sdk/usr";
110 #if defined(__APPLE__)
111 return "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/"
112 "Developer/SDKs/MacOSX.sdk/usr";
114 if(QFileInfo(
"/usr/include/c++").isDir())
120 return ctx.getSDKPath().toStdString();
126 populateCompileOptions(std::vector<std::string>& args, CompilerOptions opts)
128 args.push_back(
"-triple");
129 args.push_back(llvm::sys::getDefaultTargetTriple());
131 args.push_back(
"-target-cpu");
132 args.push_back(llvm::sys::getHostCPUName().lower());
135 llvm::StringMap<bool> HostFeatures;
136 #if LLVM_VERSION_MAJOR < 19
137 bool ok = llvm::sys::getHostCPUFeatures(HostFeatures);
139 constexpr
bool ok =
true;
140 HostFeatures = llvm::sys::getHostCPUFeatures();
144 for(
const llvm::StringMapEntry<bool>& F : HostFeatures)
146 args.push_back(
"-target-feature");
147 args.push_back((F.second ?
"+" :
"-") + F.first().str());
152 args.push_back(
"-std=c++2b");
153 args.push_back(
"-disable-free");
154 args.push_back(
"-fdeprecated-macro");
155 args.push_back(
"-fmath-errno");
160 args.push_back(
"-mthread-model");
161 args.push_back(
"posix");
163 args.push_back(
"-mconstructor-aliases");
168 args.push_back(
"-fno-use-cxa-atexit");
172 args.push_back(
"-fno-signed-zeros");
173 args.push_back(
"-mreassociate");
174 args.push_back(
"-freciprocal-math");
175 args.push_back(
"-fno-rounding-math");
178 args.push_back(
"-ffp-contract=fast");
180 #if !defined(__linux__)
183 args.push_back(
"-Ofast");
184 args.push_back(
"-menable-no-infs");
185 args.push_back(
"-menable-no-nans");
186 args.push_back(
"-ffinite-math-only");
187 args.push_back(
"-ffast-math");
189 args.push_back(
"-O3");
190 args.push_back(
"-fno-builtin");
194 args.push_back(
"-mno-stack-arg-probe");
196 args.push_back(
"-fgnuc-version=4.2.1");
198 #if defined(__APPLE__)
199 args.push_back(
"-fmax-type-align=16");
201 args.push_back(
"-mrelocation-model");
202 args.push_back(
"pic");
203 args.push_back(
"-pic-level");
208 args.push_back(
"-fvisibility=hidden");
210 args.push_back(
"-fvisibility-inlines-hidden");
213 args.push_back(
"-ftls-model=local-exec");
217 args.push_back(
"-mrelax-all");
218 args.push_back(
"-disable-llvm-verifier");
219 args.push_back(
"-discard-value-names");
220 #if defined(__SANITIZE_ADDRESS__)
241 args.push_back(
"-fno-assume-sane-operator-new");
243 args.push_back(
"-stack-protector");
245 if(opts.NoExceptions)
247 args.push_back(
"-fno-rtti");
251 #if LLVM_VERSION_MAJOR <= 13
252 args.push_back(
"-munwind-tables");
255 args.push_back(
"-fcxx-exceptions");
256 args.push_back(
"-fexceptions");
257 args.push_back(
"-fexternc-nounwind");
259 args.push_back(
"-exception-model=seh");
262 args.push_back(
"-faddrsig");
265 args.push_back(
"-vectorize-loops");
266 args.push_back(
"-vectorize-slp");
269 static inline void populateDefinitions(std::vector<std::string>& args)
271 #if defined(__APPLE__)
273 args.push_back(
"-DMOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE=");
275 args.push_back(
"-DBOOST_MATH_DISABLE_FLOAT128=1");
276 args.push_back(
"-DBOOST_ASIO_DISABLE_CONCEPTS=1");
277 args.push_back(
"-DBOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING");
278 args.push_back(
"-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE");
279 args.push_back(
"-DQT_CORE_LIB");
280 args.push_back(
"-DQT_DISABLE_DEPRECATED_BEFORE=0x050800");
281 args.push_back(
"-DQT_GUI_LIB");
282 args.push_back(
"-DQT_NETWORK_LIB");
283 args.push_back(
"-DQT_NO_KEYWORDS");
284 args.push_back(
"-DQT_QML_LIB");
285 args.push_back(
"-DQT_QUICK_LIB");
286 args.push_back(
"-DQT_SERIALPORT_LIB");
287 args.push_back(
"-DQT_STATICPLUGIN");
288 args.push_back(
"-DQT_SVG_LIB");
289 args.push_back(
"-DQT_WEBSOCKETS_LIB");
290 args.push_back(
"-DQT_WIDGETS_LIB");
291 args.push_back(
"-DQT_XML_LIB");
292 args.push_back(
"-DRAPIDJSON_HAS_STDSTRING=1");
298 args.push_back(
"-DSPDLOG_NO_TLS=1");
299 args.push_back(
"-DMOODYCAMEL_NO_THREAD_LOCAL=1");
301 args.push_back(
"-D__thread=__do_not_use_thread_local__");
302 args.push_back(
"-Dthread_local=__do_not_use_thread_local__");
303 args.push_back(
"-D_Thread_local=__do_not_use_thread_local__");
306 #if defined(SCORE_DEBUG)
307 args.push_back(
"-DSCORE_DEBUG");
309 args.push_back(
"-DSCORE_LIB_BASE");
310 args.push_back(
"-DSCORE_LIB_DEVICE");
311 args.push_back(
"-DSCORE_LIB_INSPECTOR");
312 args.push_back(
"-DSCORE_LIB_LOCALTREE");
313 args.push_back(
"-DSCORE_LIB_PROCESS");
314 args.push_back(
"-DSCORE_LIB_STATE");
315 args.push_back(
"-DSCORE_PLUGIN_GFX");
316 args.push_back(
"-DSCORE_PLUGIN_REMOTECONTROL");
317 args.push_back(
"-DSCORE_PLUGIN_NODAL");
318 args.push_back(
"-DSCORE_PLUGIN_AUDIO");
319 args.push_back(
"-DSCORE_PLUGIN_AUTOMATION");
320 args.push_back(
"-DSCORE_PLUGIN_CURVE");
321 args.push_back(
"-DSCORE_PLUGIN_DATAFLOW");
322 args.push_back(
"-DSCORE_PLUGIN_DEVICEEXPLORER");
323 args.push_back(
"-DSCORE_PLUGIN_ENGINE");
324 args.push_back(
"-DSCORE_PLUGIN_LIBRARY");
325 args.push_back(
"-DSCORE_PLUGIN_MAPPING");
326 args.push_back(
"-DSCORE_PLUGIN_MEDIA");
327 args.push_back(
"-DSCORE_PLUGIN_PROTOCOLS");
328 args.push_back(
"-DSCORE_PLUGIN_SCENARIO");
329 args.push_back(
"-DSCORE_PLUGIN_MIDI");
330 args.push_back(
"-DSCORE_PLUGIN_PROTOCOLS");
331 args.push_back(
"-DSCORE_PLUGIN_RECORDING");
332 args.push_back(
"-DSCORE_PLUGIN_TRANSPORT");
334 args.push_back(
"-DTINYSPLINE_DOUBLE_PRECISION");
335 args.push_back(
"-D_GNU_SOURCE=1");
336 args.push_back(
"-D__STDC_CONSTANT_MACROS");
337 args.push_back(
"-D__STDC_FORMAT_MACROS");
338 args.push_back(
"-D__STDC_LIMIT_MACROS");
339 #if defined(FFTW_SINGLE_ONLY)
340 args.push_back(
"-DFFTW_SINGLE_ONLY");
341 #elif defined(FFTW_DOUBLE_ONLY)
342 args.push_back(
"-DFFTW_DOUBLE_ONLY");
346 static inline auto getPotentialTriples()
348 std::vector<QString> triples;
349 triples.push_back(LLVM_DEFAULT_TARGET_TRIPLE);
350 triples.push_back(LLVM_HOST_TRIPLE);
351 #if defined(__x86_64__)
352 triples.push_back(
"x86_64-pc-linux-gnu");
353 #elif defined(__i686__)
354 triples.push_back(
"i686-pc-linux-gnu");
355 #elif defined(__i586__)
356 triples.push_back(
"i586-pc-linux-gnu");
357 #elif defined(__i486__)
358 triples.push_back(
"i486-pc-linux-gnu");
359 #elif defined(__i386__)
360 triples.push_back(
"i386-pc-linux-gnu");
361 #elif defined(__arm__)
362 triples.push_back(
"armv8-none-linux-gnueabi");
363 triples.push_back(
"armv8-pc-linux-gnueabi");
364 triples.push_back(
"armv8-none-linux-gnu");
365 triples.push_back(
"armv8-pc-linux-gnu");
366 triples.push_back(
"armv7-none-linux-gnueabi");
367 triples.push_back(
"armv7-pc-linux-gnueabi");
368 triples.push_back(
"armv7-none-linux-gnu");
369 triples.push_back(
"armv7-pc-linux-gnu");
370 triples.push_back(
"armv6-none-linux-gnueabi");
371 triples.push_back(
"armv6-pc-linux-gnueabi");
372 triples.push_back(
"armv6-none-linux-gnu");
373 triples.push_back(
"armv6-pc-linux-gnu");
374 #elif defined(__aarch64__)
375 triples.push_back(
"aarch64-none-linux-gnueabi");
376 triples.push_back(
"aarch64-pc-linux-gnueabi");
377 triples.push_back(
"aarch64-none-linux-gnu");
378 triples.push_back(
"aarch64-pc-linux-gnu");
379 triples.push_back(
"aarch64-redhat-linux");
423 static inline void populateIncludeDirs(std::vector<std::string>& args)
425 auto sdk = locateSDK();
426 auto qsdk = QString::fromStdString(sdk);
427 std::cerr <<
"\nLooking for sdk in: " << sdk <<
"\n";
428 qDebug() <<
"Looking for sdk in: " << qsdk;
430 bool sdk_found =
true;
434 if(!dir.cd(
"include") || !dir.cd(
"c++"))
436 qDebug() <<
"Unable to locate standard headers, fallback to /usr";
440 if(!dir.cd(
"include") || !dir.cd(
"c++"))
442 qDebug() <<
"Unable to locate standard headers++";
443 throw std::runtime_error(
"Unable to compile");
449 qDebug() <<
"SDK located: " << qsdk;
450 std::string llvm_lib_version = SCORE_LLVM_VERSION;
451 #if defined(__APPLE__) && SCORE_FHS_BUILD
452 llvm_lib_version =
"13.0.0";
455 QDir resDir = QString(qsdk +
"/lib/clang");
456 auto entries = resDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
457 if(!entries.empty() && !entries.contains(SCORE_LLVM_VERSION))
458 llvm_lib_version = entries.front().toStdString();
460 #if defined(__APPLE__) && SCORE_FHS_BUILD
461 std::string appleSharedSdk
462 =
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/"
464 args.push_back(
"-resource-dir");
465 args.push_back(appleSharedSdk +
"/lib/clang/" + llvm_lib_version);
467 args.push_back(
"-resource-dir");
468 args.push_back(sdk +
"/lib/clang/" + llvm_lib_version);
471 #if defined(_LIBCPP_VERSION)
472 args.push_back(
"-stdlib=libc++");
473 args.push_back(
"-internal-isystem");
475 #if defined(__APPLE__) && SCORE_FHS_BUILD
476 args.push_back(appleSharedSdk +
"/include/c++/v1");
478 args.push_back(sdk +
"/include/c++/v1");
481 #elif defined(_GLIBCXX_RELEASE)
485 const auto libstdcpp_major = QString::number(_GLIBCXX_RELEASE);
487 QDir cpp_dir{
"/usr/include/c++"};
489 QDirIterator cpp_it{cpp_dir};
490 while(cpp_it.hasNext())
493 auto ver = cpp_it.fileName();
494 if(!ver.isEmpty() && ver.startsWith(libstdcpp_major))
496 auto gcc = ver.toStdString();
499 args.push_back(
"-internal-isystem");
500 args.push_back(
"/usr/include/c++/" + gcc);
503 for(
auto& triple : getPotentialTriples())
505 if(cpp_dir.exists(triple))
508 args.push_back(
"-internal-isystem");
509 args.push_back(
"/usr/include/c++/" + gcc +
"/" + triple.toStdString());
520 #if defined(__APPLE__) && SCORE_FHS_BUILD
521 args.push_back(
"-internal-isystem");
522 args.push_back(appleSharedSdk +
"/lib/clang/" + llvm_lib_version +
"/include");
523 args.push_back(
"-internal-externc-isystem");
525 "/Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/"
526 "SDKs/MacOSX.sdk/usr/include");
528 args.push_back(
"-internal-isystem");
529 args.push_back(sdk +
"/lib/clang/" + llvm_lib_version +
"/include");
530 args.push_back(
"-internal-externc-isystem");
531 args.push_back(sdk +
"/include");
543 auto include = [&](
const std::string& path) {
544 args.push_back(
"-I" + sdk +
"/include/" + path);
547 #if defined(__linux__)
548 include(
"x86_64-linux-gnu");
551 QDirIterator qtVersionFolder{
552 qsdk +
"/include/qt/QtCore",
554 QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot,
556 std::string qt_version = QT_VERSION_STR;
557 if(qtVersionFolder.hasNext())
559 QDir sub = qtVersionFolder.next();
560 qt_version = sub.dirName().toStdString();
563 include(
"qt/QtCore");
564 include(
"qt/QtCore/" + qt_version);
565 include(
"qt/QtCore/" + qt_version +
"/QtCore");
567 include(
"qt/QtGui/" + qt_version);
568 include(
"qt/QtGui/" + qt_version +
"/QtGui");
569 include(
"qt/QtWidgets");
570 include(
"qt/QtWidgets/" + qt_version);
571 include(
"qt/QtWidgets/" + qt_version +
"/QtWidgets");
573 include(
"qt/QtQml/" + qt_version);
574 include(
"qt/QtQml/" + qt_version +
"/QtQml");
576 include(
"qt/QtNetwork");
579 include(
"qt/QtOpenGL");
580 include(
"qt/QtShaderTools");
581 include(
"qt/QtShaderTools/" + qt_version);
582 include(
"qt/QtShaderTools/" + qt_version +
"/QtShaderTools");
583 include(
"qt/QtSerialBus");
584 include(
"qt/QtSerialPort");
587 bool deploying =
true;
589 bool deploying =
false;
592 if(deploying && sdk_found)
598 auto src_include_dirs
599 = {
"/3rdparty/libossia/src",
600 "/3rdparty/libossia/3rdparty/boost_1_82_0",
601 "/3rdparty/libossia/3rdparty/nano-signal-slot/include",
602 "/3rdparty/libossia/3rdparty/spdlog/include",
603 "/3rdparty/libossia/3rdparty/brigand/include",
604 "/3rdparty/libossia/3rdparty/Flicks",
605 "/3rdparty/libossia/3rdparty/fmt/include",
606 "/3rdparty/libossia/3rdparty/readerwriterqueue",
607 "/3rdparty/libossia/3rdparty/concurrentqueue",
608 "/3rdparty/libossia/3rdparty/SmallFunction/smallfun/include",
609 "/3rdparty/libossia/3rdparty/websocketpp",
610 "/3rdparty/libossia/3rdparty/rapidjson/include",
611 "/3rdparty/libossia/3rdparty/libremidi/include",
612 "/3rdparty/libossia/3rdparty/oscpack",
613 "/3rdparty/libossia/3rdparty/rnd/include",
614 "/3rdparty/libossia/3rdparty/span/include",
615 "/3rdparty/libossia/3rdparty/tuplet/include",
616 "/3rdparty/libossia/3rdparty/unordered_dense/include",
617 "/3rdparty/libossia/3rdparty/multi_index/include",
618 "/3rdparty/libossia/3rdparty/verdigris/src",
619 "/3rdparty/libossia/3rdparty/weakjack",
620 "/3rdparty/avendish/include",
622 "/src/plugins/score-lib-state",
623 "/src/plugins/score-lib-device",
624 "/src/plugins/score-lib-process",
625 "/src/plugins/score-lib-inspector",
626 "/src/plugins/score-plugin-avnd",
627 "/src/plugins/score-plugin-gfx",
628 "/src/plugins/score-plugin-jit",
629 "/src/plugins/score-plugin-nodal",
630 "/src/plugins/score-plugin-remotecontrol",
631 "/src/plugins/score-plugin-audio",
632 "/src/plugins/score-plugin-curve",
633 "/src/plugins/score-plugin-dataflow",
634 "/src/plugins/score-plugin-engine",
635 "/src/plugins/score-plugin-scenario",
636 "/src/plugins/score-plugin-library",
637 "/src/plugins/score-plugin-deviceexplorer",
638 "/src/plugins/score-plugin-media",
639 "/src/plugins/score-plugin-loop",
640 "/src/plugins/score-plugin-midi",
641 "/src/plugins/score-plugin-protocols",
642 "/src/plugins/score-plugin-recording",
643 "/src/plugins/score-plugin-automation",
644 "/src/plugins/score-plugin-js",
645 "/src/plugins/score-plugin-mapping"};
647 for(
auto path : src_include_dirs)
649 args.push_back(
"-I" + std::string(SCORE_ROOT_SOURCE_DIR) + path);
655 "/src/plugins/score-lib-state",
656 "/src/plugins/score-lib-device",
657 "/src/plugins/score-lib-process",
658 "/src/plugins/score-lib-inspector",
659 "/src/plugins/score-plugin-avnd",
660 "/src/plugins/score-plugin-gfx",
661 "/src/plugins/score-plugin-jit",
662 "/src/plugins/score-plugin-nodal",
663 "/src/plugins/score-plugin-remotecontrol",
664 "/src/plugins/score-plugin-audio",
665 "/src/plugins/score-plugin-curve",
666 "/src/plugins/score-plugin-dataflow",
667 "/src/plugins/score-plugin-engine",
668 "/src/plugins/score-plugin-scenario",
669 "/src/plugins/score-plugin-library",
670 "/src/plugins/score-plugin-deviceexplorer",
671 "/src/plugins/score-plugin-media",
672 "/src/plugins/score-plugin-loop",
673 "/src/plugins/score-plugin-midi",
674 "/src/plugins/score-plugin-protocols",
675 "/src/plugins/score-plugin-recording",
676 "/src/plugins/score-plugin-automation",
677 "/src/plugins/score-plugin-js",
678 "/src/plugins/score-plugin-mapping",
679 "/3rdparty/libossia/src"};
681 for(
auto path : src_build_dirs)
683 args.push_back(
"-I" + std::string(SCORE_ROOT_BINARY_DIR) + path);
Definition: LibrarySettings.hpp:46
T & settings() const
Access a specific Settings model instance.
Definition: ApplicationContext.hpp:40