Discussion:
[CMake] target_compile_features() uses incorrect C++ version
Kim Walisch
2018-12-05 12:40:04 UTC
Permalink
Hi,

I have realized that my C++ primesieve project (
https://github.com/kimwalisch/primesieve) is
compiled using -std=gnu++11 with GCC 7.3 and CMake 3.10 (on Ubuntu 18.10
x64) even
though the default C++ version used by GCC 7.3 is C++14 as checked below:

$ g++ -dM -E -x c++ /dev/null | grep -F __cplusplus
#define __cplusplus 201402L

Note that I have not set CXX_STANDARD manually in my CMakeLists.txt so I
was expecting
that my project would be compiled either with -std=gnu++14 or without any
C++ version flag.
I spent some time investigating where the -std=gnu++11 flag comes from and
I found that it is
related to the use of target_compile_features():

target_compile_features(primesieve PRIVATE cxx_auto_type)

This code tells the compiler that my program uses features from C++11 and
that the compiler
should enable C++11 if the default C++ version of the compiler is e.g.
C++98. I would
however expect that if the default C++ version of the compiler is > C++11
CMake would not
add -std=gnu++11 to the compiler flags.

For me this is a CMake bug.

Thanks,
Kim Walisch
Deniz Bahadir
2018-12-05 13:17:59 UTC
Permalink
Post by Kim Walisch
Hi,
I have realized that my C++ primesieve project
(https://github.com/kimwalisch/primesieve) is
compiled using -std=gnu++11 with GCC 7.3 and CMake 3.10 (on Ubuntu 18.10
x64) even
$ g++ -dM -E -x c++  /dev/null | grep -F __cplusplus
#define __cplusplus 201402L
Note that I have not set CXX_STANDARD manually in my CMakeLists.txt so I
was expecting
that my project would be compiled either with -std=gnu++14 or without
any C++ version flag.
I spent some time investigating where the -std=gnu++11 flag comes from
and I found that it is
target_compile_features(primesieve PRIVATE cxx_auto_type)
This code tells the compiler that my program uses features from C++11
and that the compiler
should enable C++11 if the default C++ version of the compiler is e.g.
C++98. I would
however expect that if the default C++ version of the compiler is >
C++11 CMake would not
add -std=gnu++11 to the compiler flags.
For me this is a CMake bug.
Thanks,
Kim Walisch
Hi Kim,

this does indeed sound like some unwanted behavior.

I recommend you open an issue in CMake's issue-tracker
(https://gitlab.kitware.com/cmake/cmake/issues) and copy your
email-content there.

Best regards,
Deniz Bahadir
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubs
Deniz Bahadir
2018-12-05 13:49:15 UTC
Permalink
https://gitlab.kitware.com/cmake/cmake/issues/18686
Greetings,
Kim
Thanks, great.

Best regards,
Deniz

PS: Next time better answer to the mailing-list. ;-) This is probably
interesting for others that read your first email on the list, too.
Post by Kim Walisch
Hi,
I have realized that my C++ primesieve project
(https://github.com/kimwalisch/primesieve) is
compiled using -std=gnu++11 with GCC 7.3 and CMake 3.10 (on
Ubuntu 18.10
Post by Kim Walisch
x64) even
though the default C++ version used by GCC 7.3 is C++14 as
$ g++ -dM -E -x c++  /dev/null | grep -F __cplusplus
#define __cplusplus 201402L
Note that I have not set CXX_STANDARD manually in my
CMakeLists.txt so I
Post by Kim Walisch
was expecting
that my project would be compiled either with -std=gnu++14 or
without
Post by Kim Walisch
any C++ version flag.
I spent some time investigating where the -std=gnu++11 flag comes
from
Post by Kim Walisch
and I found that it is
target_compile_features(primesieve PRIVATE cxx_auto_type)
This code tells the compiler that my program uses features from
C++11
Post by Kim Walisch
and that the compiler
should enable C++11 if the default C++ version of the compiler is
e.g.
Post by Kim Walisch
C++98. I would
however expect that if the default C++ version of the compiler is >
C++11 CMake would not
add -std=gnu++11 to the compiler flags.
For me this is a CMake bug.
Thanks,
Kim Walisch
Hi Kim,
this does indeed sound like some unwanted behavior.
I recommend you open an issue in CMake's issue-tracker
(https://gitlab.kitware.com/cmake/cmake/issues) and copy your
email-content there.
Best regards,
Deniz Bahadir
--
Powered by www.kitware.com <http://www.kitware.com>
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
https://cmake.org/mailman/listinfo/cmake
--
BENOCS GmbH
Dipl.-Inform. Deniz Bahadir
Reuchlinstr. 10 D
10553 Berlin
Germany
Phone: +49 - 30 / 577 0004-22
Email: ***@benocs.com
www.benocs.com

Board of Management: Stephan Schröder, Dr.-Ing. Ingmar Poese
Commercial Register: Amtsgericht Bonn HRB 19378
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscrib
Loading...