CMakeList.txt - extra include directories

Sorry for a basic question.

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version: geant4-v11.2.2
_Operating System:_Mac OS
_Compiler/Version:_Apple clang version 15.0.0 (clang-1500.3.9.4)
_CMake Version:_cmake version 3.21.4

I am trying to build a new application based on the G01 example.

I have copied the directory and have made changes to the CMakeList.txt for the change of name.

When I run cmake it runs okay

cmake -DCMAKE_PREFIX_PATH=$G4INSTALL .
– Configuring done
– Generating done
– Build files have been written to: /Users/keithsloan/geant4-v11.2.2-Examples/KS_LGC01/build

But on subsequent make i get

keithsloan@Keiths-iMac-2 build % make
[ 25%] Building CXX object CMakeFiles/load_gdml_color.dir/load_gdml_color.cc.o
/Users/keithsloan/geant4-v11.2.2-Examples/KS_LGC01/load_gdml_color.cc:71:10: fatal error: ‘GeometryMoments.hh’ file not found
#include “GeometryMoments.hh”
^~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/load_gdml_color.dir/load_gdml_color.cc.o] Error 1
make[1]: *** [CMakeFiles/load_gdml_color.dir/all] Error 2

So it looks like the CMakeList.txt needs extra info on where to find various include directories

Hi Keith,

In my experience you probably only need to change the final name at the bottom of the cmakelists file. You would probably have to share the rest of the changes you made but geant4 invludes are inherited from the main cmake file under the directory you installed the toolkit. Ie installDir/lib/cmake/Geant4

So you wouldnt have to add anything else.

Ps thanks for the gdml workbench.

The files it is failing to find are in the include of the directory I have created.

CMakeLists.txt has

#----------------------------------------------------------------------------

Locate sources and headers for this project

include_directories(${PROJECT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIR})
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/
.hh)

So I don;t see why it is not picking up from include_directories(${PROJECT_SOURCE_DIR}/include

My understanding is that CMake does not export stuff to Env, so how do I debug?

Okay.

I create build under KS_LGC01
cd to build
Then do cmake -DGeant4_DIR=$G4DIR … -DCMAKE_PREFIX_PATH=$G4INSTALL .
and then make from there but the includes are in KS_LGC01/include
but not in KS_LGC01/build/include

Header files can just be added to the include dir.

If you are trying to copy another file or directory into the build directory for example a macro dir you need to have it as following.

foreach(_file ${someDir}
    configure_file(
    ${_file}
    ${PROJECT_BINARY_DIR}/${_file}
    COPYONLY
    )
endforeach()

Something like this. You can look under various examples how macros are copied over.

If you move the bin dir after using cmake generate then it wont work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.