Skip to content

Instantly share code, notes, and snippets.

View scivision's full-sized avatar
💭
I will be slow to respond.

scivision

💭
I will be slow to respond.
View GitHub Profile
@scivision
scivision / expanduser.cmake
Last active April 17, 2023 18:56
Expand ~ tilde to home directory in CMake script
# expands ~ to user home directory
#
# usage:
# expanduser("~/code" x)
function(expanduser in outvar)
if(CMAKE_VERSION VERSION_LESS 3.21)
get_filename_component(out ${in} ABSOLUTE)
else()
@scivision
scivision / extract_zst.py
Last active March 9, 2024 13:25
Extract a .zst file in Python
from pathlib import Path
import tempfile
import tarfile
import zstandard
# pip install zstandard
def extract_zst(archive: Path, out_path: Path):
"""extract .zst file
@scivision
scivision / hw.c
Created June 1, 2021 21:20
Detect Mac ARM64 CPUs
// build like:
// clang hw.c -framework Foundation -framework IOKit
// ./a.out then gives with an M1 Apple Silicon CPU:
//
// cpu0@0(E): apple,icestorm
// cpu1@0(E): apple,icestorm
// cpu2@0(E): apple,icestorm
// cpu3@0(E): apple,icestorm
// cpu4@1(P): apple,firestorm
// cpu5@1(P): apple,firestorm
@scivision
scivision / CMakeLists.txt
Last active March 20, 2023 19:31
append to PATH env var on Windows for CTest
# works for Unix, Windows, etc.
cmake_minimum_required(VERSION 3.22)
project(WindowsPath LANGUAGES C)
find_library(ZLIB REQUIRED)
add_executable(hello hello.c)
target_link_libraries(hello PRIVATE ZLIB::ZLIB)
add_test(NAME unit_hello COMMAND hello)
@scivision
scivision / Readme.md
Last active January 8, 2024 04:33
Intel oneAPI GitHub Actions with MKL and MPI (C, C++, Fortran) and CMake

GitHub Actions Intel oneAPI without caching

Unlike cached approach, this is simpler but takes much longer to setup on each run.

@scivision
scivision / meson.build
Created September 10, 2021 00:10
Meson build download and extract file
run_command('python', 'meson_file_download.py', url, zipfn, '-hash', 'md5', md5hash, check: true)
run_command('python', 'meson_file_extract.py', zipfn, outpath, check: true)
@scivision
scivision / mingw_octave_path.m
Created October 22, 2021 00:39
Windows Octave using MinGW executables needs MinGW on PATH
function prepend = mingw_octave_path()
% for Octave on Windows, it's necessary to prepend MinGW path
% when running MinGW-compiled executables
% Also, Matlab with Parallel Toolbox MPIEXEC conflicts with system MPIEXEC,
% so excise from Path
%
% a command is then run like
%
% system([prepend, ' ', 'foo.exe'])
@scivision
scivision / CMakeLists.txt
Created October 24, 2021 20:48
CMake CTest ENVIRONMENT_MODIFICATION test property
cmake_minimum_required(VERSION 3.22)
project(envPrint LANGUAGES NONE)
enable_testing()
add_test(NAME PrintEnv COMMAND ${CMAKE_COMMAND} -E environment)
set_tests_properties(PrintEnv PROPERTIES
ENVIRONMENT_MODIFICATION "NotExistingVar=path_list_prepend:WillSegfault")
@scivision
scivision / user_agent.cmake
Last active February 1, 2024 23:56
Get and set CMake HTTP user agent
cmake_minimum_required(VERSION 3.19)
option(CMAKE_TLS_VERIFY "Check cert" ON)
function(user_agent url fn)
file(DOWNLOAD ${url} ${fn}
STATUS stat
)
@scivision
scivision / CMakeLists.txt
Last active January 11, 2024 02:29
CTest checking that internet works before tests requiring internet
cmake_minimum_required(VERSION 3.19)
project(Connect LANGUAGES NONE)
enable_testing()
add_test(NAME InternetConnection COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/connection.cmake)
set_property(TEST InternetConnection PROPERTY FIXTURES_SETUP InternetOK)
add_test(NAME NeedsInternet COMMAND ...)