The documentation for 3.1 does document this so it should work. * I have not tried this on CMake 3.1, but have verified it works in CMake 3.3. If set (CMAKECXXSTANDARD 14) works for that code (you may check that by inspecting the command line used for compile the code or by using auto in C++ code), then CMake correctly processes your compiler and the problem is somewhere else. Target_compile_features(Hello PRIVATE cxx_auto_type) Note that the CXX_STANDARD_REQUIRED property will prevent the standard from decaying to an earlier version.Īnother proper but not as simple way to specify the CMAKE_CXX_KNOWN_FEATURES that you use, such as cxx_auto_type: cmake_minimum_required(VERSION 3.3) C23 If the value requested does not result in a compile flag being added for the compiler in use, a previous standard flag will be added instead. This will add any flags necessary such as -std=c++11. The following CMakeLists.txt will enable C++11 support: cmake_minimum_required(VERSION 3.3) For example, given this simple example using auto (named main.cpp): #include In CMake 3.1* and newer, the proper, simple way to do this is to use the CXX_STANDARD property for a given target. If you are using CMake 3.8 or newer, you can use the feature cxx_std_11, which requests C++11 or above: target_compile_features(Hello PUBLIC cxx_std_11) Message(FATAL_ERROR "Your C++ compiler does not support C++11.") if(CMAKE_COMPILER_IS_GNUCXX)Įxecute_process(COMMAND $ -stdlib=libc++") It would be nice if there would be a more general solution. Is there something available or do I need to develop this on my own?īelow is some code I use so far, however it works only with GNU'c GCC compilers. However, I have not found any module or function which provides the functionality needed.Īdditional it would be nice to have the feature to detect if the compiler needs the flags std=c++0x or std=c++11. Perfect would be something that works like find_package(). However, if a compiler does not support it the user gets compile errors instead of an error during the CMake run. Is there a way to let CMake detect automatically if a compiler supports C++11 or not?Īs it would be nice to inform the users during the CMake run that the code will not compile as the compiler does not support C++11.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |