| 476 | } |
| 477 | |
| 478 | String File::getOpenMSDataPath() |
| 479 | { |
| 480 | // Use immediately evaluated lambda to protect static variable from concurrent access. |
| 481 | static const String path = [&]() -> String { |
| 482 | String path; |
| 483 | bool path_checked = false; |
| 484 | |
| 485 | String found_path_from; |
| 486 | bool from_env(false); |
| 487 | if (getenv("OPENMS_DATA_PATH") != nullptr) |
| 488 | { |
| 489 | path = getenv("OPENMS_DATA_PATH"); |
| 490 | from_env = true; |
| 491 | path_checked = isOpenMSDataPath_(path); |
| 492 | if (path_checked) |
| 493 | { |
| 494 | found_path_from = "OPENMS_DATA_PATH (environment)"; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | // probe the install path |
| 499 | if (!path_checked) |
| 500 | { |
| 501 | path = OPENMS_INSTALL_DATA_PATH; |
| 502 | path_checked = isOpenMSDataPath_(path); |
| 503 | if (path_checked) |
| 504 | { |
| 505 | found_path_from = "OPENMS_INSTALL_DATA_PATH (compiled)"; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | // probe the OPENMS_DATA_PATH macro |
| 510 | if (!path_checked) |
| 511 | { |
| 512 | path = OPENMS_DATA_PATH; |
| 513 | path_checked = isOpenMSDataPath_(path); |
| 514 | if (path_checked) found_path_from = "OPENMS_DATA_PATH (compiled)"; |
| 515 | } |
| 516 | |
| 517 | #if defined(__APPLE__) |
| 518 | // try to find it relative to the executable in the bundle (e.g. TOPPView) |
| 519 | if (!path_checked) |
| 520 | { |
| 521 | path = getExecutablePath() + "../../../share/OpenMS"; |
| 522 | path_checked = isOpenMSDataPath_(path); |
| 523 | if (path_checked) found_path_from = "bundle path (run time)"; |
| 524 | } |
| 525 | #endif |
| 526 | |
| 527 | // On Linux and Apple check relative from the executable |
| 528 | if (!path_checked) |
| 529 | { |
| 530 | path = getExecutablePath() + "../share/OpenMS"; |
| 531 | path_checked = isOpenMSDataPath_(path); |
| 532 | if (path_checked) |
| 533 | { |
| 534 | found_path_from = "tool path (run time)"; |
| 535 | } |
no test coverage detected