Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,289
    • Issues 3,289
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 11
    • Merge Requests 11
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #21430

Closed
Open
Created Nov 12, 2020 by Andres Gomez@tanty

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
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None