Skip to content

Commit 6109d7c

Browse files
authored
Merge pull request #33 from rest-for-physics/lobis-patch-cmake_find_package
Support Building restG4 as a standalone package via CMake
2 parents 88ce626 + 87caa38 commit 6109d7c

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

.gitlab-ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ image: ghcr.io/lobis/root-geant4-garfield:cpp17_ROOT-v6-26-00_Geant4-v10.4.3_Gar
33

44
stages:
55
- build
6+
- build-standalone
67
- loadRESTLibs
78
- examples
89

@@ -41,14 +42,27 @@ build:
4142
- mkdir build
4243
- cd build
4344
- cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install
44-
- make install -j2
45+
- make -j2 install
4546
artifacts:
4647
paths:
4748
- ${CI_PROJECT_DIR}/install
4849
- ${CI_PROJECT_DIR}/framework
4950
- ${CI_PROJECT_DIR}/framework/build
5051
expire_in: 1 day
5152

53+
build-standalone:
54+
type: build-standalone
55+
script:
56+
- echo "**${CI_PROJECT_DIR}**"
57+
- cd ${CI_PROJECT_DIR}/
58+
- if [ -d build ]; then rm -rf build; fi
59+
- mkdir build
60+
- cd build
61+
- source ${CI_PROJECT_DIR}/install/thisREST.sh
62+
- cmake ../ -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install
63+
- make -j2 install
64+
- ${CI_PROJECT_DIR}/install/bin/restG4 --help
65+
5266
### We make sure the build and install directories are different
5367
##build_root_6.25_Geant4_10.7.1:
5468
## image: lobis/root-geant4-garfieldpp:cxx14_ROOTv6-25-01_Geant4v10.7.1

CMakeLists.txt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ project(restG4)
44
message("=============== ${PROJECT_NAME} ==============")
55
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake ${CMAKE_MODULE_PATH})
66

7+
if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
8+
# this will only be accessed when build restG4 as a standalone package, not when building the framework
9+
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
10+
find_package(REST REQUIRED)
11+
string(FIND ${REST_LIBRARIES} "RestGeant4" REST_GEANT4_FOUND)
12+
If (${REST_GEANT4_FOUND} EQUAL -1)
13+
message(SEND_ERROR "REST found but 'RestGeant4' library is not present. Please install REST with Geant4Lib")
14+
endif ()
15+
endif ()
16+
717
# Find ROOT
818
find_package(ROOT REQUIRED COMPONENTS RIO Geom)
919
execute_process(COMMAND root-config --cflags OUTPUT_VARIABLE ROOT_CFLAGS)
@@ -24,35 +34,24 @@ if (NOT EXISTS "${Geant4_INCLUDE_DIRS}/G4RunManagerFactory.hh")
2434
add_definitions(-DWITHOUT_G4RunManagerFactory)
2535
endif ()
2636

27-
# Find REST
28-
if (NOT DEFINED REST_PATH)
29-
if (DEFINED ENV{REST_PATH})
30-
set(REST_PATH $ENV{REST_PATH})
31-
else ()
32-
message(FATAL_ERROR "ERROR ::: REST_PATH must be defined as an environment variable and point to REST install directory")
33-
return()
34-
endif ()
35-
endif ()
36-
37-
if (NOT DEFINED rest_include_dirs)
38-
set(rest_include_dirs ${REST_PATH}/include)
39-
endif ()
40-
4137
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
4238
set(CMAKE_INSTALL_PREFIX ${REST_PATH})
4339
endif ()
44-
message(STATUS "Using REST_PATH: ${REST_PATH}")
45-
message(STATUS "Using rest_include_dirs: ${rest_include_dirs}")
40+
4641
message(STATUS "Package ${PROJECT_NAME} will be installed in ${CMAKE_INSTALL_PREFIX}")
4742

4843
if (NOT CMAKE_CXX_FLAGS)
4944
set(CMAKE_CXX_FLAGS " -std=c++1y")
5045
endif ()
5146

5247
# Set include and lib
53-
set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${rest_include_dirs} ${Geant4_INCLUDE_DIR})
48+
set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${Geant4_INCLUDE_DIR} ${REST_INCLUDE_DIRS})
5449

55-
set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestGeant4)
50+
if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
51+
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${rest_include_dirs})
52+
endif ()
53+
54+
set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestFramework RestGeant4)
5655
string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES)
5756

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

80-
set(package_added "${PROJECT_NAME} ")
81-
set(package_added ${package_added} PARENT_SCOPE)
79+
if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
80+
set(package_added "${PROJECT_NAME} ")
81+
set(package_added ${package_added} PARENT_SCOPE)
82+
endif ()

0 commit comments

Comments
 (0)