Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I will be slow to respond.

scivision

💭
I will be slow to respond.
View GitHub Profile
@scivision
scivision / output_macos.txt
Last active March 17, 2023 13:20
Shows distinct "REAL_PATH" behavior of get_filename_component(REALPATH) and file(REAL_PATH)
View output_macos.txt
-- CMake 3.26.0 Darwin
-- source directory: /tmp
uppercase: /tmp/cmake_9X4EF26O4A20GGJB
lowercase: /tmp/cmake_9x4ef26o4a20ggjb
-- touch file /tmp/cmake_9x4ef26o4a20ggjb
-- Case-insensitive filesystem detected:
get_filename_component(REALPATH): /private/tmp/cmake_9x4ef26o4a20ggjb
get_filename_component(ABSOLUTE): /tmp/cmake_9X4EF26O4A20GGJB
file(REAL_PATH): /private/tmp/cmake_9x4ef26o4a20ggjb
cmake_path(ABSOLUTE_PATH): /tmp/cmake_9X4EF26O4A20GGJB
@scivision
scivision / CheckStdFlag.cmake
Created March 16, 2023 01:08
Check highest language standard supported by compiler
View CheckStdFlag.cmake
# NOTE: for check_*() functions, CMAKE_CXX_STANDARD and CMAKE_C_STANDARD are automatically applied
# if the standard requested is higher than the compiler default.
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
function(check_std_flag lang std_flag)
set(CMAKE_REQUIRED_FLAGS)
@scivision
scivision / CMakeLists.txt
Last active March 16, 2023 14:25
CMake execute_process() doesn't print till program ends or stdout is flushed
View CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(stdout_buffering LANGUAGES CXX)
enable_testing()
set(CMAKE_CXX_STANDARD 11)
add_executable(print_flush print_flush.cpp)
add_test(NAME print_flush COMMAND print_flush)
@scivision
scivision / CMakeLists.txt
Created March 9, 2023 22:23
MUMPS FetchContent CMake use example
View CMakeLists.txt
cmake_minimum_required(VERSION 3.14...3.26)
project(MUMPS_example
LANGUAGES C Fortran
)
enable_testing()
include(FetchContent)
@scivision
scivision / TestExample.m
Last active June 3, 2023 21:30
Pytest with Matlab and GNU Octave
View TestExample.m
classdef TestExample < matlab.unittest.TestCase
methods (Test)
function testExample(testCase)
testCase.verifyEqual(1, 1);
end
end
@scivision
scivision / git_no_credential_prompt.cmake
Last active March 7, 2023 05:03
Git clone without prompting for HTTPS or SSH password (print message instead)
View git_no_credential_prompt.cmake
cmake_minimum_required(VERSION 3.5)
set(urls
"https://github.com/scivision/not-a-repo.git"
"ssh://github.com/scivision/not-a-repo.git"
)
find_package(Git REQUIRED)
set(ENV{GIT_TERMINAL_PROMPT} 0)
@scivision
scivision / CMakeLists.txt
Last active May 5, 2023 19:15
Use fortran-filesystem via CMake FetchContent
View CMakeLists.txt
cmake_minimum_required(VERSION 3.14...3.26)
project(EPretryDownload LANGUAGES C CXX)
include(FetchContent)
set(url https://github.com/scivision/fortran-filesystem)
set(tag v4.4.0)
@scivision
scivision / CMakeLists.txt
Last active March 5, 2023 06:05
Use h5fortran via ExternalProject
View CMakeLists.txt
cmake_minimum_required(VERSION 3.19...3.26)
project(H5fortran_example LANGUAGES C Fortran)
enable_testing()
include(GNUInstallDirs)
option(h5fortran_BUILD_TESTING "h5fortran internal tests")
set(h5fortran_VERSION "v4.10.2")
@scivision
scivision / CMakeLists.txt
Last active March 5, 2023 06:07
Use h5fortran via FetchContent
View CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(H5fortran_example LANGUAGES C Fortran)
enable_testing()
include(FetchContent)
option(h5fortran_BUILD_TESTING "h5fortran internal tests")
@scivision
scivision / CMakeLists.txt
Last active March 5, 2023 05:40
CMake matlab_add_mex() example
View CMakeLists.txt
cmake_minimum_required(VERSION 3.19)
project(mexDemo LANGUAGES C)
enable_testing()
find_package(Matlab REQUIRED COMPONENTS MAIN_PROGRAM)
matlab_get_release_name_from_version(${Matlab_VERSION_STRING} release)
message(STATUS "Matlab release: ${release}")
find_file(matmul_src