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 / 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
Created February 1, 2024 20:19
CTest by design combines stdout and stderr. It would be nice if they were separate.
cmake_minimum_required(VERSION 3.19)
project(piper LANGUAGES C)
enable_testing()
add_executable(piper main.c)
add_test(NAME piper COMMAND piper)
@scivision
scivision / sunriseSunset.py
Last active January 31, 2024 20:47 — forked from drhirsch/pyephem_sunrise_sunset.py
Python example of computing sunrise/sunset using PyEphem
import ephem
import datetime
Boston=ephem.Observer()
Boston.lat='42.3462'
Boston.lon='-71.0978'
Boston.date = datetime.datetime.now()
# %% these parameters are for super-precise estimates, not necessary.
Boston.elevation = 3 # meters
Boston.pressure = 1010 # millibar
@scivision
scivision / CMakeLists.txt
Last active January 31, 2024 16:02
CMake force use of presets
# force use of presets via sentinel environment variable set in presets only
cmake_minimum_required(VERSION 3.21)
project(envpre LANGUAGES C)
message(STATUS "sentinel: $ENV{sentinel}")
include(CheckSentinel.cmake)
add_executable(main main.c)
@scivision
scivision / Readme.md
Last active January 24, 2024 22:26
Python print basic version info and hostname

Python Numpy array allocation test

Simple check that a system can allocate a large numpy array.

python array_allocate.py
@scivision
scivision / CMakeLists.txt
Last active January 24, 2024 21:30
GCC static exe linking
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)
if(MINGW AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(static_link_flags -static -static-libgfortran)
# MinGW / MSYS2 special considerations: https://www.msys2.org/news/#2021-01-31-aslr-enabled-by-default
@scivision
scivision / dll_path.cmake
Created January 17, 2024 14:54
way to automatically get DLL paths
function(dll_test_path libs test_names)
# if shared lib on Windows, need DLL on PATH
if(NOT WIN32)
return()
endif()
if(CMAKE_VERSION VERSION_LESS 3.22)
message(VERBOSE " CMake ${CMAKE_VERSION} < 3.22: cannot apply ENVIRONMENT_MODIFICATION to ${test_names}")
return()
@scivision
scivision / CMakeLists.txt
Last active January 11, 2024 20:31
Cyclical Fortran dependencies are not supported: https://gitlab.kitware.com/cmake/cmake/-/issues/25584
cmake_minimum_required(VERSION 3.12...3.29)
project(mods LANGUAGES Fortran)
if(CMAKE_GENERATOR MATCHES "Ninja")
execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
OUTPUT_VARIABLE ninja_version OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
message(STATUS "CMake ${CMAKE_VERSION} CMAKE_GENERATOR ${CMAKE_GENERATOR} ${ninja_version}")
@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 ...)
@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.