<div dir="ltr">Is this a reasonable approach to using cx_11 features on multiple platforms?<div>The issue is that I think you need to manually select the MSVC compiler version that supports these features target_compile_features only works for gcc.</div><div><br></div><div>#------------------------------------------</div><div><div>project(nullptr)</div><div><br></div><div>#-----------------------------------------------------------------------------</div><div># We will enforce an out of source build.</div><div>string(COMPARE EQUAL "${${project_name}_source_dir}"</div><div>  "${${PROJECT_NAME}_BINARY_DIR}" INSOURCE)</div><div>if(INSOURCE)</div><div>  message(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Please create a separate binary directory and run CMake there.")</div><div>endif(INSOURCE)</div><div><br></div><div>#-----------------------------------------------------------------------------</div><div># Don't build anything unless the version of CMake is high enough.</div><div>cmake_minimum_required(VERSION 2.8)</div><div><br></div><div>#-----------------------------------------------------------------------------</div><div># Directory where the CMakeFiles are</div><div>set ( CMAKE_FILE_DIR</div><div>  ${PROJECT_SOURCE_DIR}/CMake</div><div>)</div><div><br></div><div>#-----------------------------------------------------------------------------</div><div># Includes.</div><div>set ( INCS</div><div>)</div><div><br></div><div>#-----------------------------------------------------------------------------</div><div># Sources.</div><div>set ( SRCS</div><div>  main.cpp</div><div>)</div><div><br></div><div>get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)</div><div>message(STATUS "This CMake version supports these C++ features:")</div><div>foreach(i ${cxx_features})</div><div>  message(STATUS "${i}")</div><div>endforeach()</div><div>message(STATUS "Compiler ID/Version: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")</div><div>#-----------------------------------------------------------------------------</div><div># Includes.</div><div>set ( INCS</div><div>)</div><div><br></div><div>#-----------------------------------------------------------------------------</div><div># Sources.</div><div>set ( SRCS</div><div>  main.cpp</div><div>)</div><div><br></div><div>set(needed_features</div><div>    cxx_lambdas</div><div>    cxx_nullptr)</div><div><br></div><div># We may need to define flags based on the needed features.</div><div>foreach(i ${needed_features})</div><div>  string(TOUPPER ${i} s)</div><div>  add_definitions("-D${s}")</div><div>endforeach()</div><div><br></div><div>if(UNIX)</div><div>  add_executable(${PROJECT_NAME} ${SRCS} ${INCS})</div><div>  target_compile_features(${PROJECT_NAME} PUBLIC ${needed_features})</div><div>elseif (MSVC_VERSION GREATER "1700")</div><div>  # Pick a MSVC version that supports what you need.</div><div>  add_executable(${PROJECT_NAME} ${SRCS} ${INCS})</div><div>else()</div><div>    message(FATAL_ERROR "No suitable compiler exists.")</div><div>endif()</div></div><div><br></div><div>#------------------------------------------<br><div><br clear="all"><div><br></div>-- <br><div class="gmail_signature">___________________________________________<br>Andrew J. P. Maclean<br><br>___________________________________________</div>
</div></div></div>