mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-08-19 03:56:16 +00:00
feat(cmake): Added CMake package
Addon changes: - Added share directory to install script to fix CMAKE_ROOT not found issue. - Added a simple CPP Hello World program for CMake usage. Caution: - Need to test Powershell script.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
---
|
||||
title: CMake
|
||||
homepage: https://github.com/Kitware/CMake
|
||||
tagline: |
|
||||
cmake: CMake is a cross-platform, open-source build system generator
|
||||
---
|
||||
|
||||
To update or switch versions, run `webi cmake@stable` (or `@v2`, `@beta`,
|
||||
etc).
|
||||
|
||||
### Files
|
||||
|
||||
These are the files / directories that are created and/or modified with this
|
||||
install:
|
||||
|
||||
```text
|
||||
~/.config/envman/PATH.env
|
||||
~/.local/bin/cmake
|
||||
~/.local/opt/cmake
|
||||
```
|
||||
To get the cmake version:
|
||||
|
||||
```sh
|
||||
cmake --version
|
||||
```
|
||||
|
||||
### Hello World with CMake:
|
||||
|
||||
Lets create a hello world program in C++ and build it with CMake.
|
||||
|
||||
- Start by creating a project directory
|
||||
|
||||
```sh
|
||||
mkdir my-project && cd my-project
|
||||
```
|
||||
|
||||
- Create a Hello World C++ file named hello-world.cpp
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << "Hello World!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
- Now we create a CMakeLists.txt to compile our cpp file.
|
||||
|
||||
```cmake
|
||||
project{hello-world}
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
add_executable(hello-world hello-world.cpp)
|
||||
|
||||
```
|
||||
|
||||
- Lets create a build directory and build the binary
|
||||
|
||||
```sh
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
- Once we build the binary we can execute it via:
|
||||
|
||||
```sh
|
||||
./hello-world
|
||||
```
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
##################
|
||||
# Install cmake #
|
||||
##################
|
||||
|
||||
# Every package should define these variables
|
||||
$pkg_cmd_name = "cmake"
|
||||
|
||||
$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\cmake.exe"
|
||||
$pkg_dst = "$pkg_dst_cmd"
|
||||
|
||||
$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\cmake-v$Env:WEBI_VERSION\bin\cmake.exe"
|
||||
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\cmake-v$Env:WEBI_VERSION\bin"
|
||||
$pkg_src_share = "$Env:USERPROFILE\.local\opt\cmake-v$Env:WEBI_VERSION\share"
|
||||
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\cmake-v$Env:WEBI_VERSION"
|
||||
$pkg_src = "$pkg_src_cmd"
|
||||
|
||||
New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | out-null
|
||||
$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"
|
||||
|
||||
# Fetch archive
|
||||
IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"))
|
||||
{
|
||||
echo "Downloading cmake from $Env:WEBI_PKG_URL to $pkg_download"
|
||||
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
|
||||
& move "$pkg_download.part" "$pkg_download"
|
||||
}
|
||||
|
||||
IF (!(Test-Path -Path "$pkg_src_cmd"))
|
||||
{
|
||||
echo "Installing cmake"
|
||||
|
||||
# TODO: create package-specific temp directory
|
||||
# Enter tmp
|
||||
pushd .local\tmp
|
||||
|
||||
# Remove any leftover tmp cruft
|
||||
Remove-Item -Path ".\cmake-v*" -Recurse -ErrorAction Ignore
|
||||
Remove-Item -Path ".\cmake.exe" -Recurse -ErrorAction Ignore
|
||||
|
||||
# NOTE: DELETE THIS COMMENT IF NOT USED
|
||||
# Move single binary into root of temporary folder
|
||||
#& move "$pkg_download" "cmake.exe"
|
||||
|
||||
# Unpack archive file into this temporary directory
|
||||
# Windows BSD-tar handles zip. Imagine that.
|
||||
echo "Unpacking $pkg_download"
|
||||
& tar xf "$pkg_download"
|
||||
|
||||
# Settle unpacked archive into place
|
||||
echo "Install Location: $pkg_src_cmd"
|
||||
New-Item "$pkg_src_bin" -ItemType Directory -Force | out-null
|
||||
Move-Item -Path ".\cmake-*\bin\cmake.exe" -Destination "$pkg_src_bin"
|
||||
Move-Item -Path ".\cmake-*\share" -Destination "$pkg_src_share"
|
||||
|
||||
# Exit tmp
|
||||
popd
|
||||
}
|
||||
|
||||
echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
|
||||
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | out-null
|
||||
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
# "'pkg_cmd_name' appears unused. Verify it or export it."
|
||||
|
||||
__init_cmake() {
|
||||
set -e
|
||||
set -u
|
||||
|
||||
##################
|
||||
# Install cmake #
|
||||
##################
|
||||
|
||||
# Every package should define these 6 variables
|
||||
pkg_cmd_name="cmake"
|
||||
|
||||
pkg_dst_cmd="$HOME/.local/bin/cmake"
|
||||
pkg_dst="$pkg_dst_cmd"
|
||||
|
||||
pkg_src_cmd="$HOME/.local/opt/cmake-v$WEBI_VERSION/bin/cmake"
|
||||
pkg_share_cmd="$HOME/.local/opt/cmake-v$WEBI_VERSION/share"
|
||||
pkg_src_dir="$HOME/.local/opt/cmake-v$WEBI_VERSION"
|
||||
pkg_src="$pkg_src_cmd"
|
||||
|
||||
# pkg_install must be defined by every package
|
||||
pkg_install() {
|
||||
# ~/.local/opt/cmake-v0.99.9/bin
|
||||
mkdir -p "$(dirname "${pkg_src_cmd}")"
|
||||
|
||||
# mv ./cmake-*/cmake ~/.local/opt/cmake-v0.99.9/bin/cmake
|
||||
mv ./cmake-*/bin/cmake "${pkg_src_cmd}"
|
||||
mv ./cmake-*/share "${pkg_share_cmd}"
|
||||
}
|
||||
|
||||
# pkg_get_current_version is recommended, but not required
|
||||
pkg_get_current_version() {
|
||||
# 'cmake --version' has output in this format:
|
||||
# cmake 0.99.9 (rev abcdef0123)
|
||||
# This trims it down to just the version number:
|
||||
# 0.99.9
|
||||
cmake --version 2> /dev/null |
|
||||
head -n 1 |
|
||||
cut -d ' ' -f 2
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
__init_cmake
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var github = require('../_common/github.js');
|
||||
var owner = 'Kitware';
|
||||
var repo = 'CMake';
|
||||
|
||||
module.exports = function (request) {
|
||||
return github(request, owner, repo).then(function (all) {
|
||||
return all;
|
||||
});
|
||||
};
|
||||
|
||||
if (module === require.main) {
|
||||
module.exports(require('@root/request')).then(function (all) {
|
||||
all = require('../_webi/normalize.js')(all);
|
||||
// just select the first 5 for demonstration
|
||||
all.releases = all.releases.slice(0, 5);
|
||||
console.info(JSON.stringify(all, null, 2));
|
||||
});
|
||||
}
|
||||
@@ -13,6 +13,7 @@ __rmrf_local() {
|
||||
bat \
|
||||
caddy \
|
||||
chromedriver \
|
||||
cmake \
|
||||
comrak \
|
||||
curlie \
|
||||
delta \
|
||||
@@ -106,6 +107,7 @@ __rmrf_local() {
|
||||
bat \
|
||||
caddy \
|
||||
chromedriver \
|
||||
cmake \
|
||||
comrak \
|
||||
curlie \
|
||||
delta \
|
||||
@@ -202,6 +204,7 @@ __test() {
|
||||
bat \
|
||||
caddy \
|
||||
chromedriver \
|
||||
cmake \
|
||||
comrak \
|
||||
curlie \
|
||||
delta \
|
||||
|
||||
Reference in New Issue
Block a user