ref!(cmake): use pkg template rather than exe template

This commit is contained in:
AJ ONeal
2023-07-03 22:36:22 +00:00
parent d00bf9eb12
commit 27030f28d2
3 changed files with 78 additions and 74 deletions

View File

@@ -2,11 +2,10 @@
title: CMake
homepage: https://github.com/Kitware/CMake
tagline: |
cmake: CMake is a cross-platform, open-source build system generator
CMake is a cross-platform, open-source build system generator
---
To update or switch versions, run `webi cmake@stable` (or `@v2`, `@beta`,
etc).
To update or switch versions, run `webi cmake@stable` (or `@v2`, `@beta`, etc).
### Files
@@ -18,54 +17,67 @@ install:
~/.local/bin/cmake
~/.local/opt/cmake
```
To get the cmake version:
## Cheat Sheet
> CMake is a cross-platform alternative to autoconf that works on Windows, Mac,
> and Linux
A project structure looks like this:
```text
my-project/
├── build/
├── CMakeLists.txt
├── hello-world*
└── hello-world.cpp
```
And can be built my running `cmake` from the `build` directory:
```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 ..
pushd ./build/
cmake ../
make
```
- Once we build the binary we can execute it via:
### How to create a Hello World with CMake
```sh
./hello-world
```
Lets create a hello world program in C++ and build it with CMake.
1. Create a project directory
```sh
mkdir ./my-project/
pushd ./my-project/
```
2. Create a Hello World C++ file named `hello-world.cpp` `hello-world.cpp`:
```cpp
#include <iostream>
int main(int argc, char** argv) {
std::cout << "Hello World!" << std::endl;
return 0;
}
```
3. Create a `CMakeLists.txt` to compile our code `CMakeLists.txt`:
```cmake
project{hello-world}
cmake_minimum_required(VERSION 3.10)
add_executable(hello-world hello-world.cpp)
```
4. Create a build directory and build the binary
```sh
mkdir ./build/
pushd ./build/
cmake ../
make
```
5. Test the built binary:
```sh
./hello-world
```

View File

@@ -1,18 +1,18 @@
#!/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_cmd = "$Env:USERPROFILE\.local\opt\cmake\bin\cmake.exe"
$pkg_dst_dir = "$Env:USERPROFILE\.local\opt\cmake"
$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"
@@ -27,7 +27,7 @@ IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"))
& move "$pkg_download.part" "$pkg_download"
}
IF (!(Test-Path -Path "$pkg_src_cmd"))
IF (!(Test-Path -Path "$pkg_src_dir"))
{
echo "Installing cmake"
@@ -36,12 +36,7 @@ IF (!(Test-Path -Path "$pkg_src_cmd"))
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"
Remove-Item -Path ".\cmake*" -Recurse -ErrorAction Ignore
# Unpack archive file into this temporary directory
# Windows BSD-tar handles zip. Imagine that.
@@ -50,9 +45,7 @@ IF (!(Test-Path -Path "$pkg_src_cmd"))
# 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"
Move-Item -Path ".\cmake*" -Destination "$pkg_src_dir"
# Exit tmp
popd

View File

@@ -14,33 +14,32 @@ __init_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_dst_cmd="$HOME/.local/opt/cmake/bin/cmake"
pkg_dst_dir="$HOME/.local/opt/cmake"
pkg_dst="$pkg_dst_dir"
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_src="$pkg_src_dir"
# pkg_install must be defined by every package
pkg_install() {
# ~/.local/opt/cmake-v0.99.9/bin
mkdir -p "$(dirname "${pkg_src_cmd}")"
# ~/.local/opt/cmake-v3.27.0/
mkdir -p "$(dirname "${pkg_src_dir}")"
# mv ./cmake-*/cmake ~/.local/opt/cmake-v0.99.9/bin/cmake
mv ./cmake-*/bin/cmake "${pkg_src_cmd}"
mv ./cmake-*/share "${pkg_share_cmd}"
# mv ./cmake-*/ ~/.local/opt/cmake-v3.27.0/
mv ./cmake-*/ "${pkg_src_dir}"
}
# 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)
# cmake 3.27.0 (rev abcdef0123)
# This trims it down to just the version number:
# 0.99.9
# 3.27.0
cmake --version 2> /dev/null |
head -n 1 |
cut -d ' ' -f 2
cut -d ' ' -f 3
}
}