Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael scivision

View GitHub Profile
@scivision
scivision / find_compiler.cmake
Created Jun 13, 2022
CMake compiler hinting--not normally needed
View find_compiler.cmake
# this must be include() before CMakeLists.txt project()
# --- Help CMake find matching compilers
function(find_fortran)
if(NOT DEFINED FC AND DEFINED ENV{FC})
set(FC $ENV{FC})
endif()
@scivision
scivision / CMakeLists.txt
Last active Apr 4, 2022
CTest checking that internet works before tests requiring internet
View CMakeLists.txt
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_tests_properties(InternetConnection PROPERTIES FIXTURES_SETUP InternetOK)
add_test(NAME NeedsInternet COMMAND ...)
@scivision
scivision / ua.cmake
Last active Apr 1, 2022
Get CMake user agent
View ua.cmake
cmake_minimum_required(VERSION 3.19)
set(CMAKE_TLS_VERIFY ON)
file(DOWNLOAD https://www.whatsmyua.info/api/v1/ua ua.json)
file(READ ua.json meta)
string(JSON ua GET ${meta} 0 ua rawUa)
@scivision
scivision / CMakeLists.txt
Created Oct 24, 2021
CMake CTest ENVIRONMENT_MODIFICATION test property
View CMakeLists.txt
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 / mingw_octave_path.m
Created Oct 22, 2021
Windows Octave using MinGW executables needs MinGW on PATH
View mingw_octave_path.m
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 / meson.build
Created Sep 10, 2021
Meson build download and extract file
View meson.build
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 / github-actions-oneapi.yml
Last active Jun 27, 2022
Intel oneAPI GitHub Actions with MKL and MPI (C, C++, Fortran) and CMake
View github-actions-oneapi.yml
jobs:
linux-intel-oneapi:
runs-on: ubuntu-latest
env:
CC: icx
CXX: icpx
FC: ifort
steps:
@scivision
scivision / CMakeLists.txt
Last active Oct 25, 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)
include(dll_path.cmake)
add_executable(hello hello.c)
target_link_libraries(hello PRIVATE ZLIB::ZLIB)
@scivision
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
scivision / CheckTLS.cmake
Last active Jul 30, 2021
Check if CMake TLS is working
View CheckTLS.cmake
# curl -O https://gist.github.com/scivision/704fd0c7600266317748e473f7e47062/raw/3bd1a8375e107db9f14660165e107ecd7b27ab42/CheckTLS.cmake
# cmake -P CheckTLS.cmake
cmake_minimum_required(VERSION 3.20)
function(check_tls)
# 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(url https://www.howsmyssl.com/a/check)