How to format CMakeLists file to configure properly

Hello,

I am new to using geant4 and cmake, and am trying to compile my first program that I have written. I have the source code (geant4-10.7.1) downloaded on linux and have it built too. The problem I am having is with my cmake lists file for my cpp main file, which is in the following format:

Project name and cmake requirement.

project(geant4sim)
cmake_minimum_required(VERSION 2.6)

Find and configure geant4.

option(WITH_GEANT4_UIVIS “Build example with Geant4 UI and Vis drivers” ON)
if(WITH_GEANT4_UIVIS)
find_package(Geant4 REQUIRED ui_all vis_all)
else()
find_package(Geant4 REQUIRED)
endif()

Configure project to use geant4 and project headers.

include({Geant4_USE_FILE}) include_directories({PROJECT_SOURCE_DIR}/include)

List sources to build the project.

file(GLOB sources {PROJECT_SOURCE_DIR}/src/*.cc) file(GLOB headers {PROJECT_SOURCE_DIR}/include/*.hh)

Define and link the executable.

add_executable(geant4sim main.cpp {sources} {headers})
target_link_libraries(main ${Geant4_LIBRARIES})

Copy runtime scripts to the build directory.

set(MAIN_SCRIPTS
main.in
main.out
init_vis.mac
run1.mac
run2.mac
vis.mac
)

foreach(_script {MAIN_SCRIPTS}) configure_file( {PROJECT_SOURCE_DIR}/{_script} {PROJECT_BINARY_DIR}/${_script}
COPYONLY
)
endforeach()

Install executable.

install(TARGETS geant4sim RUNTIME DESTINATION bin)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
This is basically the same format as the example I found under the book for application developers for how to make the cmake file, but I am getting the error from the find and configure geant4 step:

Could not find a package configuration file provided by “Geant4” with any
of the following names:

Geant4Config.cmake
geant4-config.cmake

Add the installation prefix of “Geant4” to CMAKE_PREFIX_PATH or set
“Geant4_DIR” to a directory containing one of the above files. If “Geant4”
provides a separate development package or SDK, be sure it has been
installed.

I don’t know how to make the Geant4_DIR to be where the config file is, which is under the geant4-10.7.1-build. I believe I have to add it to the CMakeLists file, but I am not sure of the syntax, since I am not very familiar with cmake.

Thanks for any help or ideas!

Please see the relevant section of the Application Developer’s Guide