[CMake] Is there a way to obtain the current compiler standard flag?

Chris Green greenc at fnal.gov
Fri Jun 1 09:27:31 EDT 2018


Hi,

I'll give this a shot, thank you. Ideally we'd have a generator 
expression pick up ${std} from the relevant target property, but I'll 
have to play with that since I'm not familiar enough with generator 
expressions to know /a priori/ how this will turn out.

Thanks for your help,

Chris.


On 5/30/18 3:12 PM, Chuck Atkins wrote:
> Hi Chris.
>
> Try using the the CMAKE_CXX${std}_STANDARD_COMPILE_OPTION variable.  
> For example, the folowing piece of CMake code:
> cmake_minimum_required(VERSION 3.9)
>
> project(foo CXX)
>
> foreach(std IN ITEMS 98 11 14 17)
>   message("C++${std} std flags: 
> ${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}")
>   message("C++${std} ext flags: 
> ${CMAKE_CXX${std}_EXTENSION_COMPILE_OPTION}")
> endforeach()
>
> Wll generate for GCC on Linux:
> -- The CXX compiler identification is GNU 8.1.1
> -- Check for working CXX compiler: /usr/bin/c++
> -- Check for working CXX compiler: /usr/bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> C++98 std flags: -std=c++98
> C++98 ext flags: -std=gnu++98
> C++11 std flags: -std=c++11
> C++11 ext flags: -std=gnu++11
> C++14 std flags: -std=c++14
> C++14 ext flags: -std=gnu++14
> C++17 std flags: -std=c++1z
> C++17 ext flags: -std=gnu++1z
> -- Configuring done
>
> PGI on Linux:
> -- The CXX compiler identification is PGI 18.4.0
> -- Check for working CXX compiler: /opt/pgi/linux86-64/18.4/bin/pgc++
> -- Check for working CXX compiler: /opt/pgi/linux86-64/18.4/bin/pgc++ 
> -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> C++98 std flags: -A
> C++98 ext flags: --gnu_extensions
> C++11 std flags: --c++11;-A
> C++11 ext flags: --c++11;--gnu_extensions
> C++14 std flags: --c++14;-A
> C++14 ext flags: --c++14;--gnu_extensions
> C++17 std flags: --c++17;-A
> C++17 ext flags: --c++17;--gnu_extensions
> -- Configuring done
>
>
> And for IBM XL on AIX:
> -- The CXX compiler identification is XL 13.1.3
> -- Check for working CXX compiler: /usr/bin/xlC
> -- Check for working CXX compiler: /usr/bin/xlC -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> C++98 std flags: -qlanglvl=strict98
> C++98 ext flags: -qlanglvl=extended
> C++11 std flags: -qlanglvl=extended0x
> C++11 ext flags: -qlanglvl=extended0x
> C++14 std flags:
> C++14 ext flags:
> C++17 std flags:
> C++17 ext flags:
> -- Configuring done
> -- Generating done
>
> - Chuck

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180601/a8124d99/attachment-0001.html>


More information about the CMake mailing list