From 78043efab0dc306eacc5b55ddb193ab49eed5823 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Wed, 9 Mar 2022 12:55:09 +0100 Subject: [PATCH 1/8] Added support to build restG4 as standalone package --- CMakeLists.txt | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23159329..42806ddd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -34,15 +44,15 @@ if (NOT DEFINED REST_PATH) endif () endif () -if (NOT DEFINED rest_include_dirs) - set(rest_include_dirs ${REST_PATH}/include) +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 "Using REST_INCLUDE_DIRS: ${REST_INCLUDE_DIRS}") message(STATUS "Package ${PROJECT_NAME} will be installed in ${CMAKE_INSTALL_PREFIX}") if (NOT CMAKE_CXX_FLAGS) @@ -50,7 +60,7 @@ if (NOT CMAKE_CXX_FLAGS) 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) string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES) @@ -77,5 +87,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 () From 77b9081b271046bc0357fe89b67a3ed51c47442c Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Wed, 9 Mar 2022 13:00:05 +0100 Subject: [PATCH 2/8] Added build as standalone package to pipeline --- .gitlab-ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 269d3185..46aeb76c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,6 +49,25 @@ build: - ${CI_PROJECT_DIR}/framework/build expire_in: 1 day +build-standalone: + type: build + script: + - echo "**${CI_PROJECT_DIR}**" + - git clone https://github.com/rest-for-physics/framework.git framework + - cd framework + - ./scripts/checkoutRemoteBranch.sh ${CI_COMMIT_BRANCH} + - git submodule init source/packages/restG4 + - git submodule update source/packages/restG4 + - cd source/packages/restG4/ + - ../../../scripts/checkoutRemoteBranch.sh ${CI_COMMIT_BRANCH} + - git checkout ${CI_COMMIT_BRANCH} + - if [ -d build ]; then rm -rf build; fi + - mkdir build + - cd build + - source ${CI_PROJECT_DIR}/install/thisREST.sh + - cmake ../ + - make -j2 + ### 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 From ad5fd66a005d5274ebf37d7a9d47a0a6686916cd Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Wed, 9 Mar 2022 13:30:04 +0100 Subject: [PATCH 3/8] build-standalone now runs after build to use artifact --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 46aeb76c..b04dd5d2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 @@ -50,7 +51,7 @@ build: expire_in: 1 day build-standalone: - type: build + type: build-standalone script: - echo "**${CI_PROJECT_DIR}**" - git clone https://github.com/rest-for-physics/framework.git framework From 9eb1ac01b2da2819a442e4d29daab098248d7830 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Wed, 9 Mar 2022 15:30:18 +0100 Subject: [PATCH 4/8] fixed compilation problem as a package in framework --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42806ddd..3db52713 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,10 +44,6 @@ if (NOT DEFINED REST_PATH) 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 () @@ -62,6 +58,10 @@ endif () # Set include and lib set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${Geant4_INCLUDE_DIR} ${REST_INCLUDE_DIRS}) +if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) + set(INCLUDE_DIRS ${INCLUDE_DIRS} ${rest_include_dirs}) +endif () + set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestGeant4) string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES) From a6c29035bbb7028b442e480a8d5d1b3b4e28ea4e Mon Sep 17 00:00:00 2001 From: Luis Obis <35803280+lobis@users.noreply.github.com> Date: Wed, 9 Mar 2022 17:19:32 +0100 Subject: [PATCH 5/8] updated pipeline --- .gitlab-ci.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b04dd5d2..fe2b2d4e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,14 +54,7 @@ build-standalone: type: build-standalone script: - echo "**${CI_PROJECT_DIR}**" - - git clone https://github.com/rest-for-physics/framework.git framework - - cd framework - - ./scripts/checkoutRemoteBranch.sh ${CI_COMMIT_BRANCH} - - git submodule init source/packages/restG4 - - git submodule update source/packages/restG4 - - cd source/packages/restG4/ - - ../../../scripts/checkoutRemoteBranch.sh ${CI_COMMIT_BRANCH} - - git checkout ${CI_COMMIT_BRANCH} + - cd ${CI_PROJECT_DIR}/ - if [ -d build ]; then rm -rf build; fi - mkdir build - cd build From 4673538488445e2df593cb85cd7a93b0e02515a4 Mon Sep 17 00:00:00 2001 From: Luis Obis <35803280+lobis@users.noreply.github.com> Date: Wed, 9 Mar 2022 18:28:15 +0100 Subject: [PATCH 6/8] Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3db52713..65faa6c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) set(INCLUDE_DIRS ${INCLUDE_DIRS} ${rest_include_dirs}) endif () -set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestGeant4) +set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestFramework RestGeant4) string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES) file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cxx) From f6f35e655c2e873fe60f8127e5c688dd7761f4ff Mon Sep 17 00:00:00 2001 From: Luis Obis <35803280+lobis@users.noreply.github.com> Date: Wed, 9 Mar 2022 18:48:15 +0100 Subject: [PATCH 7/8] removed unnecessary cmake code --- CMakeLists.txt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65faa6c9..0dfc9c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,21 +34,10 @@ 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 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) From 87caa38e916323a94d2c18ae620bed94eee356bc Mon Sep 17 00:00:00 2001 From: Luis Obis <35803280+lobis@users.noreply.github.com> Date: Wed, 9 Mar 2022 18:53:52 +0100 Subject: [PATCH 8/8] added check usage (--help) to build-standalone pipeline --- .gitlab-ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe2b2d4e..565f34f1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,7 +42,7 @@ 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 @@ -59,8 +59,9 @@ build-standalone: - mkdir build - cd build - source ${CI_PROJECT_DIR}/install/thisREST.sh - - cmake ../ - - make -j2 + - 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: