CMAKE_TOOLCHAIN_FILE only honored after the project command
Environment:
# uname -a
Linux 6c6a362e2601 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux
# dpkg -l pkg-config
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-===========================================
ii pkg-config 0.29-6 amd64 manage compile and link flags for libraries
ls -lha /usr/bin/aarch64-linux-gnu-pkg-config
lrwxrwxrwx 1 root root 34 Nov 12 09:04 /usr/bin/aarch64-linux-gnu-pkg-config -> /usr/share/pkg-config-crosswrapper
Consider the /toolchain-arm64.cmake
file:
set(ENV{PKG_CONFIG} "/usr/bin/aarch64-linux-gnu-pkg-config")
And the following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.2)
INCLUDE (FindPkgConfig)
project (test)
FindPkgConfig
should use the ENV{PKG_CONFIG}
definition to find the pkg-config binary.
If we run:
# cmake -S . -B . -DCMAKE_TOOLCHAIN_FILE=/toolchain-arm64.cmake
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29")
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/test
Notice that the FindPkgConfig
module has not made use of the ENV{PKG_CONFIG}
defined in the toolchain file.
However, if we use the following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.2)
project (test)
INCLUDE (FindPkgConfig)
Or we just omit the project
command (default project), we get:
# cmake -S . -B . -DCMAKE_TOOLCHAIN_FILE=/toolchain-arm64.cmake
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/aarch64-linux-gnu-pkg-config (found version "0.29")
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/test
And FindPkgConfig
is making use of ENV{PKG_CONFIG}
.
It's counter intuitive that the toolchain file is not used until the project command is invoked.
It feels like it should be taken into account at the top of the file or, at least, its documentation should be greatly improved.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information