Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Michael Hirsch scivision

I may be slow to respond.
View GitHub Profile
scivision / CMakeLists.txt
Last active Jun 9, 2021
append to PATH env var on Windows for CTest
View CMakeLists.txt
# works for Unix, Windows, etc.
cmake_minimum_required(VERSION 3.20)
project(WindowsPath LANGUAGES C)
find_library(ZLIB REQUIRED)
add_executable(hello hello.c)
target_link_libraries(hello PRIVATE ZLIB::ZLIB)
scivision / hw.c
Created Jun 1, 2021
Detect Mac ARM64 CPUs
View hw.c
// 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 / CheckTLS.cmake
Last active Jun 1, 2021
Check if CMake TLS is working
View CheckTLS.cmake
cmake_minimum_required(VERSION 3.19)
# some CMake may not have SSL/TLS enabled, or may have missing/broken system certificates.
# this is a publicly-usable service (as per their TOS)
set(temp ${PROJECT_BINARY_DIR}/check_tls.json)
if(NOT EXISTS ${temp})
scivision /
Last active Apr 26, 2021
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 / TestAll.m
Created Apr 19, 2021
Matlab with GitHub Actions CI
View TestAll.m
import matlab.unittest.TestRunner
import matlab.unittest.Verbosity
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.XMLPlugin
import matlab.unittest.plugins.codecoverage.CoberturaFormat
name = "MyProject";
suite = testsuite(name);
runner = TestRunner.withTextOutput('OutputDetail', Verbosity.Detailed);
scivision / expanduser.cmake
Last active Mar 31, 2021
Expand ~ tilde to home directory in CMake script
View expanduser.cmake
function(expanduser in outvar)
# expands ~ to user home directory
# cmake_path and file do not expand ~
# get_filename_component expands ~ in C++ similar to above
# usage:
# expanduser("~/code" x)
string(SUBSTRING ${in} 0 1 first)
scivision / extract_zstd.m
Last active Apr 20, 2021
Matlab extract .zst Zstd compressed files
View extract_zstd.m
function extract_zstd(archive, out_dir)
% extract a zstd file "archive" to "out_dir"
if ~isfile(archive)
error("%s is not a file", archive)
[ret, ~] = system("zstd -h");
if ret ~= 0
if ismac
scivision / AddGitSubmodule.cmake
Last active Mar 7, 2021
CMake: init/update a Git submodule and add_subdirectory()
View AddGitSubmodule.cmake
function(add_git_submodule dir)
# add a Git submodule directory to CMake, assuming the
# Git submodule directory is a CMake project.
# Usage: in CMakeLists.txt
# include(AddGitSubmodule.cmake)
# add_git_submodule(mysubmod_dir)
find_package(Git REQUIRED)
View .cpack_ignore
scivision / CMakeLists.txt
Last active Feb 26, 2021
GCC static exe linking
View CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(demo Fortran)
# --- static flags avoid users needing libgfortran etc. on their Windows system
# MacOS and Linux needs more caution as true static linking is an advanced topic.
# this does not guarantee a portable executable, careful testing is needed and possibly further options
set(static_link_flags -static -static-libgfortran)
# MinGW / MSYS2 special considerations: