stages:
  - build_debug
  - run_unit_tests
  - build_release
  - trigger

cache:
    paths:
    - ${BUILD_DIR}
  
before_script:
  - mkdir -p ${DEBUG_DIR}
  - mkdir -p ${RELEASE_SHARED_DIR}
  - mkdir -p ${RELEASE_STATIC_DIR}
  - export OMP_NUM_THREADS=${CPU_SIM}

build_debug:
  stage: build_debug
  script:
    - cd ${DEBUG_DIR}
    - cmake ../.. -DCMAKE_CXX_FLAGS="-g -O1 -Wall -Wpedantic -pedantic-errors -Wextra --coverage" -DTADAH_ENABLE_OPENMP=ON -DTADAH_BUILD_TESTS=ON
    - make -j ${CPU_BUILD}

run_unit_tests:
  stage: run_unit_tests
  script:
    - cd ${DEBUG_DIR}
    - make test
    - cd ..; gcovr -e '.*tests.*|.*lib.*|.*utils.*|build' -r .
  coverage: /^TOTAL.*\s+(\d+\%)$/

build_release_shared:
  stage: build_release
  script:
    - cd ${RELEASE_SHARED_DIR}
    - cmake ../.. -DCMAKE_BUILD_TYPE=Release -DTADAH_ENABLE_OPENMP=ON -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH}
    - make -j ${CPU_BUILD}

build_release_static:
  stage: build_release
  script:
    - cd ${RELEASE_STATIC_DIR}
    - cmake ../.. -DCMAKE_BUILD_TYPE=Release -DTADAH_ENABLE_OPENMP=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH}
    - make -j ${CPU_BUILD}

trigger_job:
  stage: trigger
  trigger:
    project: tadah/tadah.mlip
    branch: $CI_COMMIT_REF_NAME