CMake: Parent directory and trailing slashes

The task is to get the parent directory of a given directory where the given directory is already known to be a directory.

An example where the input directory is already known to be a directory (and not a file) is a target include directory (properties INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES).

With CMake prior to version 3.20 there is the get_filename_component function:

get_filename_component(filename_component "${directory}" DIRECTORY)

With CMake >= 3.20 get_filename_component is deprecated in favor of cmake_path. A naive way would be to directly call this function:

cmake_path(GET directory PARENT_PATH cmake_path_naive)

But there is a glitch with cmake_path when directory already contains a trailing slash (“/”).

Continue reading “CMake: Parent directory and trailing slashes”

Fun with CMake version ranges

Since release 3.19 CMake allows to specify a range in find_package() calls:

find_package(Dummy minVersion...maxVersion)

Although currently not much find modules support version ranges one might want to set the upper end to a maximum version the code is compatible with. This can be seen as a safeguard against breaking changes in an unknown future major version.

Let say we have a package “Dummy” whose major versions 1 and 2 are known to work with our own code. One might be tempted to specify the version range like the following:

find_package(Dummy 1...2)

This works well with 1.0.0, 1.5.0 or 2.0.0, but will break with 2.0.1 or 2.1.0.

Instead use the following syntax to include major versions 1 and 2:

find_package(Dummy 1...<3)

But why so?

Continue reading “Fun with CMake version ranges”

Wie man http-Server unter Python mockt

Führt der eigene Code http-Calls aus, z.B. um Dateien von einem externen Server runterzuladen stellt sich die Frage nach der Testbarkeit. Idealerweise ist der Code so aufgebaut, daß er nicht direkt von einer http-Library abhängt und man entsprechende Calls mocken kann. Ist dies nicht einfach möglich, kann man den in der Standarlibrary eingebauten http.server als localhost-Gegenstelle für Tests verwenden.

Continue reading “Wie man http-Server unter Python mockt”

Jenkins and case sensitive environment variables

Some tools demand environment variables to be present in a certain case. E.g. some libraries read out the proxy configuration in the environment variable HTTP_PROXY (all uppercase), while some refer to the lower case variant http_proxy. An example of the later is libcurl. So in any case you want to set both variants.

Unfortunately Jenkins has some problems passing all variants from the build host environment and is mixing up things. It doesn’t seem that the problem is fixed anytime soon.

Continue reading “Jenkins and case sensitive environment variables”