Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: relocation of the installation directory #23

Open
Fravadona opened this issue Dec 11, 2019 · 0 comments
Open

Enhancement: relocation of the installation directory #23

Fravadona opened this issue Dec 11, 2019 · 0 comments

Comments

@Fravadona
Copy link

Fravadona commented Dec 11, 2019

Hi Inniag,

As I didn't find a way of relocating CHAP after compilation, I added a basic one that may prove useful for other people. It enables a user to compile CHAP and install it wherever he wants (that's he normal workflow) and then move the install directory to another place.

--- chap-version_0_9_1/include/config/config.hpp.orig	2018-05-02 13:22:36.000000000 +0200
+++ chap-version_0_9_1/include/config/config.hpp	2019-12-09 12:20:15.276330444 +0100
@@ -25,6 +25,7 @@
 #ifndef CONFIG_HPP
 #define CONFIG_HPP
 
+#include <cstdlib>
 #include <string>
 
 #include <gromacs/utility/programcontext.h>
@@ -38,7 +39,12 @@
 extern "C" inline std::string
 chapInstallBase()
 {
-    return std::string(g_CHAP_INSTALL_BASE);
+    const char* e_CHAP_INSTALL_BASE = std::getenv("CHAP_INSTALL_BASE");
+    if ( e_CHAP_INSTALL_BASE != NULL) {
+        return std::string(e_CHAP_INSTALL_BASE);
+    } else {
+        return std::string(g_CHAP_INSTALL_BASE);
+    }
 }
 
 
--- chap-version_0_9_1/src/main.cpp.orig	2018-05-02 13:22:36.000000000 +0200
+++ chap-version_0_9_1/src/main.cpp	2019-12-11 20:41:44.217021435 +0100
@@ -21,6 +21,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+#include <limits.h>
 
 #include <vector>
 
@@ -33,6 +34,20 @@
 
 int main(int argc, char **argv)
 {
+    char buf[PATH_MAX];
+    readlink("/proc/self/exe", buf, PATH_MAX - 1);
+
+    // CHAP full binary path
+    std::string fbp(buf);
+    // CHAP install base path
+    std::string ibp = fbp.substr(0, fbp.rfind("/bin/"));
+    // GROMACS GMXLIB path
+    std::string ggp = ibp + "/share/gromacs/top";
+
+    // set environement variables
+    setenv("CHAP_INSTALL_BASE", ibp.c_str(), 0);
+    setenv("GMXLIB", ggp.c_str(), 0);
+
     // print front matter:
     FrontMatter::print();
 

Incidentally, I also removed the hardcoded '/chap/' sub-directory because it is more usefull to install a program directly in the prefix provided by the user instead of adding a sub-directory inside that prefix.

--- chap-version_0_9_1/CMakeLists.txt.orig	2018-05-02 13:22:36.000000000 +0200
+++ chap-version_0_9_1/CMakeLists.txt	2019-12-06 21:41:00.975176714 +0100
@@ -175,9 +175,9 @@
 #------------------------------------------------------------------------------
 
 # where to install executable on the system:
-install(TARGETS chap DESTINATION ${CMAKE_INSTALL_PREFIX}/chap/bin)
+install(TARGETS chap DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
 
 # also install data and scripts:
-install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share DESTINATION ${CMAKE_INSTALL_PREFIX}/chap)
-install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts DESTINATION ${CMAKE_INSTALL_PREFIX}/chap USE_SOURCE_PERMISSIONS)
+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share DESTINATION ${CMAKE_INSTALL_PREFIX})
+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts DESTINATION ${CMAKE_INSTALL_PREFIX} USE_SOURCE_PERMISSIONS)
 
--- chap-version_0_9_1/src/trajectory-analysis/chap_trajectory_analysis.cpp.orig	2018-05-02 13:22:36.000000000 +0200
+++ chap-version_0_9_1/src/trajectory-analysis/chap_trajectory_analysis.cpp	2019-12-09 13:52:36.745685228 +0100
@@ -708,7 +708,7 @@
 
     // base path to location of van-der-Waals radius databases:
     std::string radiusFilePath = chapInstallBase() +
-            std::string("/chap/share/data/vdwradii/");
+            std::string("/share/data/vdwradii/");
 
     // select appropriate database file:
     if( pfVdwRadiusDatabase_ == eVdwRadiusDatabaseHoleAmberuni )
@@ -779,7 +779,7 @@
 
     // base path to location of hydrophobicity databases:
     std::string hydrophobicityFilePath = chapInstallBase() + 
-            std::string("/chap/share/data/hydrophobicity/");
+            std::string("/share/data/hydrophobicity/");
     
     // select appropriate database file:
     if( hydrophobicityDatabase_ == eHydrophobicityDatabaseHessa2005 )
@@ -1921,7 +1921,7 @@
 
     // load colour palettes from JSON file:
     std::string paletteFilePath = chapInstallBase() + 
-            std::string("/chap/share/data/palettes/");
+            std::string("/share/data/palettes/");
     std::string paletteFileName = paletteFilePath + "default.json";
     auto palettes = ColourPaletteProvider::fromJsonFile(paletteFileName);
 

I hope that will prove usefull,
Cheers.

PS: Patch file with all the previous code :
version_0_9_1_relocation.patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant