Like with
shell scripts,
standalone CMake
scripts
can have a first-line shebang that tells the shell what program should execute the script.
#!/usr/bin/env -S cmake -P
While there’s no harm in adding this shebang to CMake scripts, is there a way to pass dynamic “-Dvar=value” to the script when using the shebang like “./myscript.cmake”?
If the script is OK without such parameters, then the shebang can be useful.
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.
Securely connect to a
VNC server
tunneled over SSH from Windows with this procedure.
We use SSH tunneling for the insecure VNC protocol as for other insecure protocols like RDP.
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 client 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.
While CMake binaries can be downloaded for most platforms, there are certain cases where one wishes to build CMake from source.
For example, when preparing a merge request to fix or enhance CMake.
Usually the computer will have at least an older version of CMake that can be used.
If so, we recommend using CMake to build the newer CMake, from the CMake source directory.
We recommend using
Ninja
in general for faster build and rebuild for any CMake project.
If an old CMake isn’t available on the computer, then use CMake bootstrap:
./bootstrap --prefix=$HOME/local/cmake-dev --parallel=4 -- -DBUILD_TESTING:BOOL=OFF -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_USE_OPENSSL:BOOL=ON
make -j4
make install
The OpenSSL flag is particularly important for CMake use connecting to the internet.
This puts the compiled CMake under ~/local/cmake-dev, without disturbing the primary CMake install.
Upon making any CMake code changes, simply recompile the minimum needed bits by:
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.