Bug 254138 - devel/cmake: aborts if CMAKE_CXX_STANDARD is set to empty
Summary: devel/cmake: aborts if CMAKE_CXX_STANDARD is set to empty
Status: Closed Not Accepted
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-kde (group)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-08 18:16 UTC by Ed Maste
Modified: 2021-03-30 19:47 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (kde)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2021-03-08 18:16:31 UTC
While trying to convert a CI config for some 3rd party software I ended up accidentally setting -DCMAKE_CXX_STANDARD= (i.e., nothing).

cmake ought to emit a useful error message for this case, but instead just aborts:

$ cmake -GNinja -DCMAKE_CXX_STANDARD= ..
-- The CXX compiler identification is Clang 11.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Abort trap (core dumped)
Comment 1 Adriaan de Groot freebsd_committer freebsd_triage 2021-03-20 17:32:13 UTC
Can you give a complete example? I wrote this:

```
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(derp LANGUAGES C CXX)

add_executable(derp main.c)
```

(and some variations) and could not reproduce the problem.
Comment 2 Adriaan de Groot freebsd_committer freebsd_triage 2021-03-29 20:37:23 UTC
After some more experimentation, including switching main.c to main.cc to exercise C++ standard detection, it still doesn't crash; closest I can get is 

-- The CXX compiler identification is Clang 11.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:4 (add_executable):
  CXX_STANDARD is set to invalid value ''

So needs more specifics if it can be reproduced.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2021-03-29 20:50:35 UTC
I observed this with catch2:

$ git clone https://github.com/catchorg/Catch2
$ cd Catch2
$ mkdir build
$ cd build
$ cmake -GNinja -DCMAKE_CXX_STANDARD= ..
-- The CXX compiler identification is Clang 11.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Abort trap (core dumped)
Comment 4 Adriaan de Groot freebsd_committer freebsd_triage 2021-03-30 12:13:17 UTC
Confirmed, thanks for the straightforward scenario to reproduce the problem. I can also reproduce on Linux with CMake 3.19.4, using Make as a generator. I get a more convenient error message there, which will help me chase it here and upstream.
Comment 5 Adriaan de Groot freebsd_committer freebsd_triage 2021-03-30 13:11:23 UTC
Fixed upstream already with https://gitlab.kitware.com/cmake/cmake/-/commit/533386ca2961060b81fce2f0532a55ed76b1b53d . I'm going to close this again with "Don't DO THAT then", the workaround is to not send an invalid empty value for CMAKE_CXX_STANDARD. I don't think it's worth the effort to try to backport the fix to current FreeBSD ports when it will show up in a future CMake release soon-ish.

For the record cmake git does this:

```
[adridg@beastie ~/Catch2/build]$ /usr/home/adridg/src/git/cmake-adridg/bin/cmake -GNinja -DCMAKE_CXX_STANDARD= ..
-- The CXX compiler identification is Clang 11.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at src/CMakeLists.txt:250 (target_compile_features):
  target_compile_features The CXX_STANDARD property on target "Catch2"
  contained an invalid value: "".


-- Configuring incomplete, errors occurred!
```

Which is the right thing to do, compared to

```
Abort trap (core dumped)
```
Comment 6 Ed Maste freebsd_committer freebsd_triage 2021-03-30 14:05:38 UTC
> Don't DO THAT then

Indeed. It's fine that it doesn't work with invalid input, but my concern was that there's no obvious way to debug what's wrong. (The original issue that caused me to find this was a -DCMAKE_CXX_STANDARD=${something} in a build script, with ${something} unset, and it wasn't obvious what was happening.)

> I get a more convenient error message there, which will help me chase it here and upstream.

Is the error message on Linux from CMake, or from the runtime? If the latter I'd be interested in seeing what it is, so that we could report the error in the same way on FreeBSD.
Comment 7 Adriaan de Groot freebsd_committer freebsd_triage 2021-03-30 19:47:01 UTC
The error on Linux is from CMake; the difference is that it prints abort() bla-di-bla something about stoi(), which gave me something to go on. Anyway, it's fixed upstream but CMake 3.20 seems a bit wonky so far, so it might take some time before it lands.