CMake / Meson temp directory from environment variable

We have found that some CIs and systems do not define the environment variables “TMPDIR” or “TEMP” for temporary directory. Thus we recommend using a known defined location such as the current binary directory.

CMake

set(tmpdir ${CMAKE_CURRENT_BINARY_DIR})

tmpdir variable can be passed as a parameter to user test programs in CMakeLists.txt like:

add_executable(mytest mytest.c)

add_test(NAME MyTest COMMAND $<TARGET_FILE:mytest> ${tmpdir})

where mytest.c accepts command line parameters.

Meson

tmpdir = meson.current_build_dir()

tmpdir variable can be passed as a parameter to user test programs in meson.build like:

mytest = executable('mytest', 'mytest.c')

test('MyTest', mytest,
  args: [tmpdir])