Skip to content

Commit

Permalink
Merge pull request #33 from rest-for-physics/lobis-patch-cmake_find_p…
Browse files Browse the repository at this point in the history
…ackage

Support Building restG4 as a standalone package via CMake
  • Loading branch information
lobis authored Mar 10, 2022
2 parents 88ce626 + 87caa38 commit 6109d7c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
16 changes: 15 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ image: ghcr.io/lobis/root-geant4-garfield:cpp17_ROOT-v6-26-00_Geant4-v10.4.3_Gar

stages:
- build
- build-standalone
- loadRESTLibs
- examples

Expand Down Expand Up @@ -41,14 +42,27 @@ build:
- mkdir build
- cd build
- cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install
- make install -j2
- make -j2 install
artifacts:
paths:
- ${CI_PROJECT_DIR}/install
- ${CI_PROJECT_DIR}/framework
- ${CI_PROJECT_DIR}/framework/build
expire_in: 1 day

build-standalone:
type: build-standalone
script:
- echo "**${CI_PROJECT_DIR}**"
- cd ${CI_PROJECT_DIR}/
- if [ -d build ]; then rm -rf build; fi
- mkdir build
- cd build
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cmake ../ -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install
- make -j2 install
- ${CI_PROJECT_DIR}/install/bin/restG4 --help

### We make sure the build and install directories are different
##build_root_6.25_Geant4_10.7.1:
## image: lobis/root-geant4-garfieldpp:cxx14_ROOTv6-25-01_Geant4v10.7.1
Expand Down
41 changes: 21 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ project(restG4)
message("=============== ${PROJECT_NAME} ==============")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake ${CMAKE_MODULE_PATH})

if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
# this will only be accessed when build restG4 as a standalone package, not when building the framework
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
find_package(REST REQUIRED)
string(FIND ${REST_LIBRARIES} "RestGeant4" REST_GEANT4_FOUND)
If (${REST_GEANT4_FOUND} EQUAL -1)
message(SEND_ERROR "REST found but 'RestGeant4' library is not present. Please install REST with Geant4Lib")
endif ()
endif ()

# Find ROOT
find_package(ROOT REQUIRED COMPONENTS RIO Geom)
execute_process(COMMAND root-config --cflags OUTPUT_VARIABLE ROOT_CFLAGS)
Expand All @@ -24,35 +34,24 @@ if (NOT EXISTS "${Geant4_INCLUDE_DIRS}/G4RunManagerFactory.hh")
add_definitions(-DWITHOUT_G4RunManagerFactory)
endif ()

# Find REST
if (NOT DEFINED REST_PATH)
if (DEFINED ENV{REST_PATH})
set(REST_PATH $ENV{REST_PATH})
else ()
message(FATAL_ERROR "ERROR ::: REST_PATH must be defined as an environment variable and point to REST install directory")
return()
endif ()
endif ()

if (NOT DEFINED rest_include_dirs)
set(rest_include_dirs ${REST_PATH}/include)
endif ()

if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${REST_PATH})
endif ()
message(STATUS "Using REST_PATH: ${REST_PATH}")
message(STATUS "Using rest_include_dirs: ${rest_include_dirs}")

message(STATUS "Package ${PROJECT_NAME} will be installed in ${CMAKE_INSTALL_PREFIX}")

if (NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS " -std=c++1y")
endif ()

# Set include and lib
set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${rest_include_dirs} ${Geant4_INCLUDE_DIR})
set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${Geant4_INCLUDE_DIR} ${REST_INCLUDE_DIRS})

set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestGeant4)
if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${rest_include_dirs})
endif ()

set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestFramework RestGeant4)
string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES)

file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cxx)
Expand All @@ -77,5 +76,7 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mac
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

set(package_added "${PROJECT_NAME} ")
set(package_added ${package_added} PARENT_SCOPE)
if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(package_added "${PROJECT_NAME} ")
set(package_added ${package_added} PARENT_SCOPE)
endif ()

0 comments on commit 6109d7c

Please sign in to comment.