[CMake] check_cxx_compiler_flag fails silently for complex compiler paths
Gregor Jasny
gjasny at googlemail.com
Fri Feb 26 14:57:06 EST 2016
Hello,
On 26/02/16 00:00, Andrew Hundt wrote:
> I believe check_cxx_compiler_flags is failing due to a long/complicated
> compiler path.
>
> Specifically my compiler is set to:
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
>
> CMake version: 3.4.3
>
> Full trace output in gist where you can see lines warning of regex failure:
> https://gist.github.com/ahundt/88ce65bcc3c268acdd94
>
>
> Here is the code snippet that fails:
>
> include(CheckCXXCompilerFlag)
>> check_cxx_compiler_flag(-std=c++11 COMPILER_SUPPORTS_CXX11)
>> check_cxx_compiler_flag(-std=c++0x COMPILER_SUPPORTS_CXX0X)
>> message(STATUS <<<<<<<<COMPILER_SUPPORTS_CXX11:${COMPILER_SUPPORTS_CXX11})
The problem is not compiler path related but related to the additional
warnings that are enabled:
https://github.com/code-iai/iai_kinect2/blob/master/kinect2_calibration/CMakeLists.txt#L4
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBT_USE_DOUBLE_PRECISION -Wall")
> # Unused warnings
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized -Winit-self -Wunused-function -Wunused-label -Wunused-variable -Wunused-but-set-variable -Wunused-but-set-parameter")
> # Additional warnings
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Warray-bounds -Wtype-limits -Wreturn-type -Wsequence-point -Wparentheses -Wmissing-braces -Wchar-subscripts -Wswitch -Wwrite-strings -Wenum-compare -Wempty-body -Wlogical-op")
Those cause clang to emit a warning about unknown warnings:
> clang -c -DBT_USE_DOUBLE_PRECISION -Wall -Wuninitialized -Winit-self -Wunused-function -Wunused-label -Wunused-variable -Wunused-but-set-variable -Wunused-but-set-parameter -Warray-bounds -Wtype-limits -Wreturn-type -Wsequence-point -Wparentheses -Wmissing-braces -Wchar-subscripts -Wswitch -Wwrite-strings -Wenum-compare -Wempty-body foo.cpp
> warning: unknown warning option '-Wunused-but-set-variable'; did you mean
> '-Wunused-const-variable'? [-Wunknown-warning-option]
> warning: unknown warning option '-Wunused-but-set-parameter'; did you mean
> '-Wunused-parameter'? [-Wunknown-warning-option]
> 2 warnings generated.
Those warnings are interpreted by check_cxx_compiler_flag as failure
(this is the regex you observed [1]) which leads to a negative setting
of the variable.
I see three possible solutions:
1) Move the check before touching the CMAKE_CXX_FLAGS.
2) Require a more modern CMake (3.3) and set
CMAKE_CXX_STANDARD to 11
CMAKE_CXX_STANDARD_REQUIRED to TRUE
3) Use modern CMake with target compile features:
https://cmake.org/cmake/help/v3.3/manual/cmake-compile-features.7.html
Thanks,
Gregor
[1]
https://github.com/Kitware/CMake/blob/master/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake#L25
More information about the CMake
mailing list