CMAKE_PROGRAM_PATH, CMAKE_SYSTEM_PROGRAM_PATH and toolchain files
When writing a toolchain file for cross-compiling using a sysroot provided by OpenEmbedded, I run into an issue where CMake would use my host protoc
to generate protobuf files, which lead to incompatibilities.
After some looking around I found a pair of variables: CMAKE_PROGRAM_PATH
and CMAKE_SYSTEM_PROGRAM_PATH
, both of which do pretty much what I wanted.
After some testing, I've determined that, in the toolchain file:
# this works
set(CMAKE_PROGRAM_PATH "${HOST_SYSROOT}/usr/bin" CACHE STRING "" FORCE)
# this doesn't work
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH TRUE CACHE STRING "" FORCE)
set(CMAKE_SYSTEM_PROGRAM_PATH "${HOST_SYSROOT}/usr/bin" CACHE STRING "" FORCE)
Which seems kind of strange. I don't feel good about setting CMAKE_PROGRAM_PATH
in the toolchain file, since I do not consider it a part of the project (rather part of build host configuration), so this runs counter to the intent stated in the documentation: "it is intended to be set by the project".
Looking through the documentation for cmake-toolchains(7), there is no clear indication how to set search paths for extra tools and programs.
To better explain my situation: OpenEmbedded provieds two sysroots: one for target (headers and libraries) and one for build host (compilers, linker, cmake, other utilities). In my case I want to use the protobuf compiler (protoc
) provided in build host sysroot without modifying the project. It is conceivable there would be other tools which would require similar treatment. As of now the only solution I found is setting a variable against the convention outlined in documentation.
This behavior is consistent in both 3.19.3 (Manjaro package) and 3.16.5 (provided by OpenEmbedded 3.1).