Commit 89e60963 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add initial support for compile-time project paths (#1050)

Eg,
    #define FOAM_CONFIGURED_PROJECT_ETC "/usr/share/openfoam/etc"

This provides some easy to file patching locations, but is not yet
integrated in the build system at all.
parent fd348374
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -27,6 +27,14 @@ License ...@@ -27,6 +27,14 @@ License
#include "foamVersion.H" #include "foamVersion.H"
#include "OSspecific.H" #include "OSspecific.H"
// Note contains handling for compile-time configuration of some paths
// via defines:
// - FOAM_CONFIGURED_PROJECT_DIR
// - FOAM_CONFIGURED_PROJECT_ETC
// Eg,
// #define FOAM_CONFIGURED_PROJECT_ETC "/usr/share/openfoam/etc"
// * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * * //
// //
...@@ -108,8 +116,11 @@ static inline bool userResourceDir(Foam::fileName& queried) ...@@ -108,8 +116,11 @@ static inline bool userResourceDir(Foam::fileName& queried)
// //
// Corresponds to foamEtcFile -mode=g // Corresponds to foamEtcFile -mode=g
// Looks for // Looks for
// - $WM_PROJECT_SITE/etc // - ${WM_PROJECT_SITE}/etc
// - $WM_PROJECT_DIR/site/etc // - ${WM_PROJECT_DIR}/site/etc
//
// Optionally (compile-time defined):
// - FOAM_CONFIGURED_PROJECT_DIR/site/etc
static inline bool groupResourceDir(Foam::fileName& queried) static inline bool groupResourceDir(Foam::fileName& queried)
{ {
#ifdef FOAM_RESOURCE_SITE_ENVNAME #ifdef FOAM_RESOURCE_SITE_ENVNAME
...@@ -127,15 +138,25 @@ static inline bool groupResourceDir(Foam::fileName& queried) ...@@ -127,15 +138,25 @@ static inline bool groupResourceDir(Foam::fileName& queried)
#ifdef FOAM_RESOURCE_SITE_FALLBACK_ENVNAME #ifdef FOAM_RESOURCE_SITE_FALLBACK_ENVNAME
queried = Foam::getEnv(FOAM_RESOURCE_SITE_FALLBACK_ENVNAME)/"site/etc"; queried = Foam::getEnv(FOAM_RESOURCE_SITE_FALLBACK_ENVNAME)/"site/etc";
if (queried.size() > 8) if (queried.size() > 8 && Foam::isDir(queried))
{ {
return Foam::isDir(queried); return true;
} }
#elif defined FULLDEBUG #elif defined FULLDEBUG
#warning FOAM_RESOURCE_SITE_FALLBACK_ENVNAME \ #warning FOAM_RESOURCE_SITE_FALLBACK_ENVNAME \
is undefined (was this intentional?) is undefined (was this intentional?)
#endif #endif
// Compile-time paths
#ifdef FOAM_CONFIGURED_PROJECT_DIR
queried = FOAM_CONFIGURED_PROJECT_DIR/Foam::string("site/etc");
if (queried.size() > 8 && Foam::isDir(queried))
{
return true;
}
#endif
queried.clear(); queried.clear();
return false; return false;
} }
...@@ -147,14 +168,36 @@ static inline bool groupResourceDir(Foam::fileName& queried) ...@@ -147,14 +168,36 @@ static inline bool groupResourceDir(Foam::fileName& queried)
// //
// Corresponds to foamEtcFile -mode=o // Corresponds to foamEtcFile -mode=o
// Looks for // Looks for
// - $WM_PROJECT_DIR/etc // - ${WM_PROJECT_DIR}/etc
//
// Optionally (compile-time defined):
// - FOAM_CONFIGURED_PROJECT_ETC
// - FOAM_CONFIGURED_PROJECT_DIR/"etc"
static inline bool projectResourceDir(Foam::fileName& queried) static inline bool projectResourceDir(Foam::fileName& queried)
{ {
queried = Foam::getEnv("WM_PROJECT_DIR")/"etc"; queried = Foam::getEnv("WM_PROJECT_DIR")/"etc";
if (queried.size() > 3) if (queried.size() > 3 && Foam::isDir(queried))
{ {
return Foam::isDir(queried); return true;
}
// Compile-time paths
#ifdef FOAM_CONFIGURED_PROJECT_ETC
queried = FOAM_CONFIGURED_PROJECT_ETC;
if (Foam::isDir(queried))
{
return true;
} }
#endif
#ifdef FOAM_CONFIGURED_PROJECT_DIR
queried = FOAM_CONFIGURED_PROJECT_DIR/Foam::word("etc");
if (queried.size() > 3 && Foam::isDir(queried))
{
return true;
}
#endif
queried.clear(); queried.clear();
return false; return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment