Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Misleading error message in C only projects trying to find Boost #76

Open
LeSpocky opened this issue Sep 9, 2024 · 3 comments · May be fixed by #75
Open

CMake: Misleading error message in C only projects trying to find Boost #76

LeSpocky opened this issue Sep 9, 2024 · 3 comments · May be fixed by #75

Comments

@LeSpocky
Copy link

LeSpocky commented Sep 9, 2024

I have multiple CMake library projects here, one of them using Boost threads. One library project ("A") exports its own config together with a find_dependency(Boost COMPONENTS thread) call.

Another library project ("B") uses find_package(A) and this way the find_dependency is executed which calls find_package(Boost COMPONENTS thread) internally. That is then used by a third library ("C"), so you a have a chain of dependencies here.

Problem: library C currently has its LANGUAGES set to C in the project() call. Linking libB in libC is possible, but since the switch from CMake FindBoost module to cmake package config coming with Boost I get a build error, which I could track down to Boost.

Minimal example requires a short CMakeLists.txt only:

cmake_minimum_required(VERSION 3.5)
project(bt
    VERSION 0.1
    LANGUAGES C
)

find_package(Boost REQUIRED CONFIG
    COMPONENTS
        thread
)

The error message is like this:

CMake Error at /usr/lib/x86_64-linux-gnu/cmake/BoostDetectToolset-1.74.0.cmake:5 (string):
  string sub-command REGEX, mode MATCHALL needs at least 5 arguments total to
  command.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.74.0/boost_thread-config.cmake:27 (include)
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:141 (find_package)
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:258 (boost_find_component)
  CMakeLists.txt:7 (find_package)


Boost toolset is unknown (compiler  )
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/BoostDetectToolset-1.74.0.cmake:5 (string):
  string sub-command REGEX, mode MATCHALL needs at least 5 arguments total to
  command.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/boost_atomic-1.74.0/boost_atomic-config.cmake:27 (include)
  /usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.74.0/boost_thread-config.cmake:100 (find_package)
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:141 (find_package)
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:258 (boost_find_component)
  CMakeLists.txt:7 (find_package)


Boost toolset is unknown (compiler  )
Performing Test CMAKE_HAVE_LIBC_PTHREAD
Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
Found Threads: TRUE  
Configuring incomplete, errors occurred!
See also "/home/adahl/build/tmp/bt/CMakeFiles/CMakeOutput.log".

Note: this still happens with most recent Boost, it was just easier to reproduce on my host machine like this.

Note: this only happens if COMPONENTS are involved.

Analysis: the problem is in tools/boost_install/BoostDetectToolset.cmake right in the first line:

string(REGEX MATCHALL "[0-9]+" _BOOST_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION})

In my case ${CMAKE_CXX_COMPILER_VERSION} is empty here (C only project), leading to that error message. I would propose to check for that variable before using it and bailout with a meaningful error message if it is found to be empty.

LeSpocky referenced this issue in LeSpocky/boost_install Sep 9, 2024
CMake bails out with an error message giving no clue what's going on, if
variable CMAKE_CXX_COMPILER_VERSION is not set:

    CMake Error at /usr/lib/x86_64-linux-gnu/cmake/BoostDetectToolset-1.74.0.cmake:9 (string):
      string sub-command REGEX, mode MATCHALL needs at least 5 arguments total to
      command.
    Call Stack (most recent call first):
      /usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.74.0/boost_thread-config.cmake:27 (include)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:141 (find_package)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:258 (boost_find_component)
      CMakeLists.txt:7 (find_package)

    -- Boost toolset is unknown (compiler  )

The added message still leads to a CMake error, but gives the user a
better clue where to look for in her own project trying to find Boost.

Fixes: #74
LeSpocky referenced this issue in LeSpocky/boost_install Sep 9, 2024
CMake bails out with an error message giving no clue what's going on, if
variable CMAKE_CXX_COMPILER_VERSION is not set:

    CMake Error at /usr/lib/x86_64-linux-gnu/cmake/BoostDetectToolset-1.74.0.cmake:9 (string):
      string sub-command REGEX, mode MATCHALL needs at least 5 arguments total to
      command.
    Call Stack (most recent call first):
      /usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.74.0/boost_thread-config.cmake:27 (include)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:141 (find_package)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:258 (boost_find_component)
      CMakeLists.txt:7 (find_package)

    -- Boost toolset is unknown (compiler  )

The added message still leads to a CMake error, but gives the user a
better clue where to look for in her own project trying to find Boost.

Output afterwards:

    CMake Error at /usr/lib/x86_64-linux-gnu/cmake/BoostDetectToolset-1.74.0.cmake:6 (message):
      CMAKE_CXX_COMPILER_VERSION is not set!
    Call Stack (most recent call first):
      /usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.74.0/boost_thread-config.cmake:27 (include)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:141 (find_package)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:258 (boost_find_component)
      CMakeLists.txt:7 (find_package)

    CMake Error at /usr/lib/x86_64-linux-gnu/cmake/BoostDetectToolset-1.74.0.cmake:8 (string):
      string sub-command REGEX, mode MATCHALL needs at least 5 arguments total to
      command.
    Call Stack (most recent call first):
      /usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.74.0/boost_thread-config.cmake:27 (include)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:141 (find_package)
      /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake:258 (boost_find_component)
      CMakeLists.txt:7 (find_package)

    -- Boost toolset is unknown (compiler  )

Fixes: #74
@pdimov
Copy link
Member

pdimov commented Sep 9, 2024

Something like this: d85e1b5?

@LeSpocky
Copy link
Author

LeSpocky commented Sep 9, 2024

Something like this: d85e1b5?

Wow you are really quick. I could go with that. Opened my own PR meanwhile (#75), lunch break was between issue and pull request. Sorry for the redundancy.

@mclow mclow transferred this issue from boostorg/boost_install Sep 9, 2024
@pdimov
Copy link
Member

pdimov commented Sep 9, 2024

Please don't move my issues around, @mclow ; it was in the right place.

@pdimov pdimov transferred this issue from boostorg/cmake Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants