Macro FindGarfield.cmake was not working properly

I had to introduce few changes in my cmake/FindGarfield.cmake so that cmake is able to find Garfield.

In particular, the latest Garfield in their master branch changes the include/ directory by include/Garfield/.

But also, I was surprised that I need to add ENV statement in GARFIELD_HOME so that it uses the environment external GARFIELD_HOME definition that we have to add to our bashrc together with other HEED path definitions.

set(Garfield_DIR $ENV{GARFIELD_HOME})

My question is, was this working before without ENV under other conditions/system?

I have made the following commit to the development branch

Hello Javier,

I have indeed include/Garfield/ in my distribution. But I also have Include w/ a capital I, which
has the same contents. FindGarfield.cmake retrieves the latter.

But I have another problem,viz. cmake does not find heed++, so that I have to edit
FindGarfield.cmake to get it:

sphnpc122:~/REST/REST_v2.2.11_dev> git diff -U0 cmake/FindGarfield.cmake
diff --git a/cmake/FindGarfield.cmake b/cmake/FindGarfield.cmake
index 68aa5aa6..83f1ac2a 100644
--- a/cmake/FindGarfield.cmake
+++ b/cmake/FindGarfield.cmake
@@ -19,0 +20,4 @@ find_path(Garfield_INCLUDE_DIRS Sensor.hh
+find_path(Heed_DIR heed++
+    HINTS ${Garfield_DIR}/Heed ${Garfield_INC_DIR}/../Heed
+    $ENV{GARFIELD_HOME}/Heed)
+set(Garfield_INCLUDE_DIRS ${Garfield_INCLUDE_DIRS} ${Heed_DIR})

Which poses a problem in thisREST.[c]sh, now that the REST_GARFIELD_INCLUDE contains two paths.

Hoping this helps…
Yann

Ok, I don’t see why you need to add Heed/heed++ directory to FindGarfield.cmake.

Perhaps is to avoid defining HEED_DATABASE environment variable in your bash?

You get into errors at compilation time?

This is how my bashrc looks like

  8 export GARFIELD_HOME=~/git/garfieldpp/Install/
  9 export HEED_DATABASE=$GARFIELD_HOME/Heed/heed++/database
 10 export LD_LIBRARY_PATH=$GARFIELD_HOME/lib:$LD_LIBRARY_PATH

W/o the patch that adds garfield/Heed to ${external_include_dirs}, I get the following fatal
error at compilation time:

[ 29%] Building CXX object source/metadata/CMakeFiles/RestMetadata.dir/general/src/TRestGas.cxx.o
In file included from /local/home/ybedfer/REST/REST_v2.2.11_dev/source/metadata/general/inc/TRestGas.h:49:0,
                 from /local/home/ybedfer/REST/REST_v2.2.11_dev/source/metadata/general/src/TRestGas.cxx:216:
/local/home/ybedfer/software/garfield/Include/TrackHeed.hh:10:42: fatal error: heed++/code/HeedCondElectron.h: No such file or directory
compilation terminated.
source/metadata/CMakeFiles/RestMetadata.dir/build.make:381: recipe for target 'source/metadata/CMakeFiles/RestMetadata.dir/general/src/TRestGas.cxx.o' failed
make[2]: *** [source/metadata/CMakeFiles/RestMetadata.dir/general/src/TRestGas.cxx.o] Error 1
CMakeFiles/Makefile2:237: recipe for target 'source/metadata/CMakeFiles/RestMetadata.dir/all' failed

The price to pay being the following bad statement in thisREST.sh:

export REST_GARFIELD_INCLUDE=/local/home/ybedfer/software/garfield/Include;/local/home/ybedfer/software/garfield/Heed

Which I am correcting manually.

Since others do not observed the same, I haven’t try to also fix the writing of the thisREST
script, and then commit.

Strange that you yourself (and others) get no compilation error: how does gcc find the header
file HeedCondElectron.h?

Yann

Perhaps it is a problem with a different Garfield version? In my TrackHeed.hh I don’t have an #include "HeedCondElectron.h" sentence.

Recently, 2-3 days ago, I tested with the master branch located at

and everything went smooth.

I have been recently trying to install Garfield and I detected another problem in FindGarfield.cmake. It was not finding the Garfield_INCLUDE_DIRS path i.e. this part of the code was not working:

find_path(Garfield_INCLUDE_DIRS Sensor.hh
HINTS ${Garfield_DIR}/include/ ${Garfield_DIR}/include/Garfield ${Garfield_INC_DIR}
${Garfield_DIR}/Include/)

What I did was to set it manually:

set(Garfield_INCLUDE_DIRS ${Garfield_DIR}/Include/)

and now it finds it perfectly. I don’t know if you encountered this problem before…

Yes, I remember experiencing this problem before, specially when Garfield source directories changed between one Garfield version and another, that’s why there are so many HINTS.

But It is strange it does not find it. Because ${Garfield_DIR}/Include/ is present on the HINTS.

I imagine you have GARFIELD_HOME defined?

It found it for me without problems when running cmake ../.

I imagine you were getting errors already during cmake execution?

It is weird because I encountered this problem when installing REST in my own computer. When I installed it at another machine however, there was no problem at all. So maybe is something related to my local computer… sorry!

Installation should work in any computer anyhow.