CMAKE_COMMAND
can be used to directly invoke CMake scripts with options.
This is particularly useful to chain CMake scripts during CTest runs with
fixtures.
It’s important to set the minimum CMake version in the CMake script file as otherwise CMake defaults to CMake < 2.6 policies.
That makes current CMake syntax fail in puzzling ways.
Example:
Suppose a test script that reads a file using regex.
This will fail without cmake_minimum_required() or cmake_policy().
I prefer cmake_minimum_required to make the script fail if someone uses the script directly with too-old CMake.
CMake can retrieve and use Git submodules as a regular subdirectory.
This is an alternative to using FetchContent when the project team decides to use Git submodules instead of FetchContent as in this
example:
Some CMake tests need to use shell redirection to input file content.
This is often done on Unix-like systems by invoking sh -c.
Powershell can also work (including on Windows) if proper escaping is used:
CMake
ExternalProject
builds arbitrary projects without interacting with the top level CMake project.
Via ExternalProject, CMake can build child projects for virtually any build system including Make, Autotools, Meson, CMake, etc.
A distinct technique is needed to pass a CMake
list
to ExternalProject.
As a reminder, CMake lists are defined as semicolon-separated strings.
In this example the CMAKE_ARGS are arbitrary, we just put some typical arguments.
The key syntax to observe are that CMAKE_CACHE_ARGS is used to pass any lists.
A reason this is necessary is that CMAKE_ARGS is passed as a command line.
CMAKE_ARGS can also have problems if many long arguments are used, particularly on Windows where the maximum command line length could be exceeded.
We don’t use CMAKE_CACHE_ARGS carte blanche because some arguments may not be intended to be cache variables.
NOTE: the variable type must be passed to CMAKE_CACHE_ARGS, as when setting any cache variable.
Windows computer can securely connect to a VNC server on a remote computer tunneled over SSH.
For software development on a remote computer, it can be easier to use
VSCode over SSH
to the remote computer.
We use SSH tunneling for the insecure protocols like RDP and VNC, which are unencrypted and should not be exposed to the internet directly.
This procedure works from a local Windows PC to a remote VNC server on
Linux,
macOS,
etc.
We assume the remote server computer has an SSH server and VNC server already setup.
On the local Windows computer, add to the ~/.ssh/config for this Host a line like:
LocalForward 5990 localhost:5900
where 5900 is the VNC port on the remote PC, and 5990 is an arbitrary distinct port on the local PC to avoid clashes on 5900.
Note: the VNC server might use port other than 5900.
On Linux a common default VNC port is 5901.
To connect, ssh to the server as usual, then use VNC Viewer to connect to localhost:5990.
When the SSH connection (tunnel) is closed, so is the VNC connection.
Pytest
captures
stdout/stderr and sets stdin to os.devnull.
When a test involves the use of Python subprocess, the “capfd” Pytest fixture is required to capture the subprocess output.
“capsys” fixture only captures native Python prints, without capturing subprocess output.
This is also true when testing a Python script intended to be used from the command line.
importsubprocessimportsysdeftest_script(capfd):
"""test that a particular message is printed to terminal""" ret = subprocess.run([sys.executable, "-m", "mymod"], text=True)
assert ret.returncode == 0 cap = capfd.readouterr()
assert cap.out.strip() == "success"assert cap.err.strip() == ""
The Mac Mini can be considerably cheaper than MacBooks, making the Mac Mini a good value for developers who work at a desk.
Running benchmarks that take about ten minutes, the Mac Mini fan did not come on and the case was still cool to the touch.
If building large projects, consider the amount of RAM to avoid needing to limit build parallelism to avoid running out of RAM on build.
The Mac Mini has a modestly adequate internal speaker suitable for quiet offices.
With macOS, the volume was not controllable in macOS itself with HDMI audio on the same monitor that volume control worked with Raspberry Pi–to be clear, this is an OS setting, not adjusting the monitor itself.
It’s also disappointing that a microphone isn’t built in–this would have been useful for Siri at least.
Perhaps Apple may have felt people would try to use an internal Mac Mini microphone for conferencing, and then get disappointed if they weren’t close enough to it for good sound.
As compared to a cloud physical Mac service, the Mac Mini pays for itself in a year, while adding value as a media center and convenience of having a local physical Mac.
CMake can generate pkg-config .pc files for packages.
The .pc file can be used by many build systems.
While we normally use the .cmake files for packages, we also include the .pc files for non-CMake users.
Meson has a built-in function for generating pkg-config files, but CMake does not yet.
CMake “find_{file,library,package,path,program}” have a NO_DEFAULT_PATH parameter that disables ALL search paths, even the <NAME>_ROOT priority.
The need for this and the workaround is best shown by example with a non-system compiler such as Intel oneAPI.
The reason that we use NO_DEFAULT_PATH for non-system compilers is because CMake will still try to use the system libraries that may not be ABI compatible with the other compiler.
NO_DEFAULT_PATH disables the CMake default PATH_SUFFIXES, so those need to be specified as well.
To make the command line and environment variable hints work again, do like: