<div dir="ltr">Hi,<div><br></div><div>I've been using the new compile features functionality for working with C++11 and beyond (very useful!!). However, I've run into issues (probably misunderstandings) trying to extend it to compilers for which CMake doesn't currently provide a <COMPILERID>-CXX-FeatureTests.cmake file. Of course long term, these will be added (and I'm happy to contribute here), but on shorter timescales and to potentially support older CMake 3 series I wanted to see if I could provide files/settings in my own project to do this.</div><div><br></div><div>Initially I thought about providing the file as a module in my project (e.g. for Intel)</div><div>and then prepending the directory holding it to CMAKE_MODULE_PATH. However, all the files using the feature testing system appear to use absolute paths (via CMAKE_ROOT) to load the relevant file, so this appears to be a no-go.</div><div><br></div><div>I then looked at setting the CMAKE_CXX11_COMPILE_FEATURES and CMAKE_CXX11_{STANDARD,EXTENSION}_COMPILE_OPTION variables directly after the initial project call. This appears to work for compile features, but not for compile options. Here's my simple test case (NB no version checking of Intel yet...)</div><div><br></div><div><p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">cmake_minimum_required(VERSION 3.1)</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">project(IntelCompileFeatures CXX)</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35);min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  message(STATUS "CMAKE_COMPILER_ID matches 'Intel'")</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  set(CMAKE_CXX11_COMPILE_FEATURES cxx_auto_type cxx_range_for)</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES})</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++11")</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">endif()</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35);min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">file(WRITE "testIntel.cpp" "</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">#include <iostream></p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35);min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">int main() {</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">std::string foo(\"helloworld\");</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">for (auto& i : foo) {</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">std::cout << i << std::endl;</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">}</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">}</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">")</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35);min-height:17px"><br></p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">add_executable(testIntel testIntel.cpp)</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">target_compile_features(testIntel PRIVATE</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  cxx_auto_type</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  cxx_range_for</p>
<p style="margin:0px;font-size:13px;font-family:Monaco;color:rgb(245,245,246);background-color:rgb(32,34,35)">  )</p></div><div><br></div><div>This will pass the configure/generate stage fine, as CMake configures and generates recognising the features set on `testIntel`, but the compile option  -std=c++11 isn't added to the compile flags. I've cross-checked on the usage of CMAKE_CXX11_{STANDARD,EXTENSION}_COMPILE_OPTION and here I've been able to modify it after project has been called and see the modified version</div><div>appear in the build time flags. </div><div><br></div><div>I'm therefore not sure if I've misunderstood how CMAKE_CXX11_{STANDARD,EXTENSION}_COMPILE_OPTION is supposed to work, or if there's some other setting I'm missing. Any help or suggestions gratefully received!!</div><div><br></div><div>Thanks,</div><div><br></div><div>Ben Morgan</div></div>