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)
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.
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.
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)
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.
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) ```
> 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.
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.