distributable:
  url: https://github.com/Kitware/CMake/releases/download/v{{ version }}/cmake-{{ version }}.tar.gz
  strip-components: 1

versions:
  github: Kitware/CMake/releases/tags
  ignore: /-rc\d/

detect:
  cmd: cmake --version
  regex: cmake version \v

dependencies:
  curl.se: '>=5'
  zlib.net: 1
  sourceware.org/bzip2: 1

provides:
  darwin:
    - bin/cmake
    - bin/ccmake
    - bin/cpack
    - bin/ctest
  linux:
    - bin/cmake
    - bin/cpack
    - bin/ctest

build:
  script: |-
    ./bootstrap $ARGS
    make --jobs {{ hw.concurrency }} install
    rm -rf {{prefix}}/share/doc  # docs are online
  env:
    V: 1
    ARGS:
      - --prefix={{ prefix }}
      - --parallel={{ hw.concurrency }}
      - --datadir=/var
      - --docdir=/share/doc
      - --mandir=/share/man
      - --system-zlib
      - --system-bzip2
      - --system-curl
      - --
      - -DCMake_BUILD_LTO=ON
      - -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
    darwin:
      ARGS:
        - -DZLIB_LIBRARY={{deps.zlib.net.prefix}}/lib/libz.dylib
        - -DZLIB_INCLUDE_DIR={{deps.zlib.net.prefix}}/include
        - -DCURL_LIBRARY={{deps.curl.se.prefix}}/lib/libcurl.dylib
        - -DCURL_INCLUDE_DIR={{deps.curl.se.prefix}}/include
        - -DBZIP2_LIBRARIES={{deps.sourceware.org/bzip2.prefix}}/lib/libbz2.a
        - -DBZIP2_INCLUDE_DIR={{deps.sourceware.org/bzip2.prefix}}/include
    linux:
      ARGS:
        - -DZLIB_LIBRARY={{deps.zlib.net.prefix}}/lib/libz.so
        - -DZLIB_INCLUDE_DIR={{deps.zlib.net.prefix}}/include
        - -DCURL_LIBRARY={{deps.curl.se.prefix}}/lib/libcurl.so
        - -DCURL_INCLUDE_DIR={{deps.curl.se.prefix}}/include
        - -DBZIP2_LIBRARIES={{deps.sourceware.org/bzip2.prefix}}/lib/libbz2.so
        - -DBZIP2_INCLUDE_DIR={{deps.sourceware.org/bzip2.prefix}}/include

  error-log: Bootstrap.cmk/cmake_bootstrap.log

test: cmake --version
