#5503·poco

CMake: cross builds silently use the host OpenSSL when the toolchain file names no target root

Author: matejkCreated Sep 25, 2026Updated Sep 25, 2026
Labelsenhancementdocumentationcmake

Reported in discussion #5431 (aarch64, crosstool-NG toolchain); #3829 was the same situation with the GNU make build.

Problem

A toolchain file that sets the CMAKE_FIND_ROOT_PATH_MODE_* ONLY modes but neither CMAKE_SYSROOT nor CMAKE_FIND_ROOT_PATH gives CMake nothing to re-root, so find_package(OpenSSL) finds the host's OpenSSL in /usr/include and /usr/lib64. Crypto, NetSSL and JWT are then enabled, and the build fails far from the cause, in Crypto, with openssl/opensslv.h: No such file or directory: CMake omits /usr/include from the compile line when the compiler's implicit include path already ends in usr/include, which holds for a cross toolchain's sysroot. Nothing at configure time indicates that the wrong OpenSSL was picked.

Proposed changes

  • Configure-time check in the top-level CMakeLists.txt: when CMAKE_CROSSCOMPILING is set and OPENSSL_INCLUDE_DIR is not below CMAKE_SYSROOT, CMAKE_FIND_ROOT_PATH or CMAKE_STAGING_PREFIX, emit message(WARNING ...) naming the directory and pointing to CMAKE_FIND_ROOT_PATH / OPENSSL_ROOT_DIR and to ENABLE_CRYPTO, ENABLE_NETSSL and ENABLE_JWT. Written as a helper so that MySQL, PostgreSQL, ODBC and APR can get the same check.
  • Documentation (README.md, section "Cross-Compiling", and doc/00200-GettingStarted.page): the toolchain file must name the target root with CMAKE_SYSROOT or CMAKE_FIND_ROOT_PATH; external dependencies must be built for the target and installed below that root; the ENABLE_* options turn them off; a minimal toolchain file example.

Acceptance

  • Configuring with the toolchain file from #5431 prints the warning naming the host directory.
  • Configuring with CMAKE_FIND_ROOT_PATH set to a root that contains an OpenSSL for the target prints no warning.
  • Native builds are unchanged.