Skip to content

Commit

Permalink
Merge branch 'fix.compileOutsideRepo' into 'master.dev'
Browse files Browse the repository at this point in the history
[fix.compileOutsideRepo] Test and fix to build piclas outside of the repository

See merge request piclas/piclas!949
  • Loading branch information
pnizenkov committed Jun 11, 2024
2 parents f7b9cc9 + b8a9118 commit f5ddae4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
16 changes: 16 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,22 @@ build_no_git:
rules:
- if: '$DO_WEEKLY'

build_outside_repository:
tags: [withmodules-concurrent]
stage: build
cache:
<<: *reggie_cache
script:
- echo " Installing branch $CI_COMMIT_REF_NAME outside the piclas directory/repository"
- REPOPATH=$(echo `pwd`)
- cd .. ;
- mkdir -p build-piclas-outside ; cd build-piclas-outside ;
- cmake ${REPOPATH} -DLIBS_BUILD_HDF5=OFF
- $GENERATOR -j $NCORES all
- cd .. ; rm -r build-piclas-outside ;
rules:
- if: '$DO_WEEKLY'

build_no_git_libs:
tags: [withmodules-concurrent]
stage: build
Expand Down
44 changes: 22 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ ENDIF()
# Git configuration
# =========================================================================
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
# Setup git hooks
SET(PRECOMMIT_FILE ".githooks/pre-commit")
# Check if the pre-commit hooks exits
IF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
# Create otherwise
EXECUTE_PROCESS(COMMAND mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks)
EXECUTE_PROCESS(COMMAND ln -s ${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMMIT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
ELSE()
# Check if the hook is the correct symlink and warn otherwise
EXECUTE_PROCESS(COMMAND readlink ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit OUTPUT_VARIABLE PRECOMMIT_LINK OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (NOT ${PRECOMMIT_LINK} MATCHES "${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMMIT_FILE}")
MESSAGE (WARNING "Custom git pre-commit hook detected. Please ensure to call ${PRECOMMIT_FILE} manually.")
# Setup git hooks
SET(PRECOMMIT_FILE ".githooks/pre-commit")
# Check if the pre-commit hooks exits
IF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
# Create otherwise
EXECUTE_PROCESS(COMMAND mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks)
EXECUTE_PROCESS(COMMAND ln -s ${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMMIT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
ELSE()
# Check if the hook is the correct symlink and warn otherwise
EXECUTE_PROCESS(COMMAND readlink ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit OUTPUT_VARIABLE PRECOMMIT_LINK OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (NOT ${PRECOMMIT_LINK} MATCHES "${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMMIT_FILE}")
MESSAGE (WARNING "Custom git pre-commit hook detected. Please ensure to call ${PRECOMMIT_FILE} manually.")
ENDIF()
ENDIF()
ENDIF()

# Check if the hook actually gets loaded
EXECUTE_PROCESS(COMMAND git config --get core.hooksPath OUTPUT_VARIABLE HOOKSPATH OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (DEFINED HOOKSPATH AND NOT "${HOOKSPATH}" STREQUAL "" AND NOT "${HOOKSPATH}" STREQUAL ".git/hooks")
# STRING(ASCII 27 ESCAPE)
# MESSAGE (STATUS "${ESCAPE}[34mCustom hooks path detected. Please ensure to call ${PRECOMMIT_FILE} manually.${ESCAPE}[0m")
MESSAGE (WARNING "Custom git hooks path detected. Please ensure to call ${PRECOMMIT_FILE} manually.")
ENDIF()
# Check if the hook actually gets loaded
EXECUTE_PROCESS(COMMAND git config --get core.hooksPath OUTPUT_VARIABLE HOOKSPATH OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
IF (DEFINED HOOKSPATH AND NOT "${HOOKSPATH}" STREQUAL "" AND NOT "${HOOKSPATH}" STREQUAL ".git/hooks")
# STRING(ASCII 27 ESCAPE)
# MESSAGE (STATUS "${ESCAPE}[34mCustom hooks path detected. Please ensure to call ${PRECOMMIT_FILE} manually.${ESCAPE}[0m")
MESSAGE (WARNING "Custom git hooks path detected. Please ensure to call ${PRECOMMIT_FILE} manually.")
ENDIF()
ELSE()
MESSAGE(STATUS "git not found")
ENDIF()
Expand Down Expand Up @@ -158,9 +158,9 @@ PROJECT(PICLas)
SET(commit ${CMAKE_CURRENT_SOURCE_DIR}/src/commit.h)
FILE(WRITE ${commit} "! Define the current commit hash. The default must remain empty, i.e., ''. Do not commit the changed file!\n#define GIT_CURRENT_COMMIT ''\n")
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
EXECUTE_PROCESS(COMMAND git rev-parse HEAD OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
EXECUTE_PROCESS(COMMAND git rev-parse HEAD OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
MESSAGE(STATUS "Current git commit ${GIT_COMMIT} will be written to ${commit}")
EXECUTE_PROCESS(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/setCommitHash.sh ${commit})
EXECUTE_PROCESS(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/setCommitHash.sh ${commit} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
ENDIF()
# Make sure that the script is executed even though cmake is not explicitly executed after the commit is changed in git
ADD_CUSTOM_TARGET(UpdateGitCommitHash COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/setCommitHash.sh ${commit})
Expand Down
2 changes: 1 addition & 1 deletion CMakeListsLib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MARK_AS_ADVANCED(FORCE LIBS_EXTERNAL_LIB_DIR)
# Check where the code originates
# =========================================================================
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
EXECUTE_PROCESS(COMMAND git ls-remote --get-url OUTPUT_VARIABLE GIT_ORIGIN)
EXECUTE_PROCESS(COMMAND git ls-remote --get-url OUTPUT_VARIABLE GIT_ORIGIN WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

# Strip lead and trailing white space
string(STRIP ${GIT_ORIGIN} GIT_ORIGIN)
Expand Down

0 comments on commit f5ddae4

Please sign in to comment.