Is this a reasonable approach to using cx_11 features on multiple platforms? 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.
#------------------------------------------ project(nullptr) #----------------------------------------------------------------------------- # We will enforce an out of source build. string(COMPARE EQUAL "${${project_name}_source_dir}" "${${PROJECT_NAME}_BINARY_DIR}" INSOURCE) if(INSOURCE) message(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Please create a separate binary directory and run CMake there.") endif(INSOURCE) #----------------------------------------------------------------------------- # Don't build anything unless the version of CMake is high enough. cmake_minimum_required(VERSION 2.8) #----------------------------------------------------------------------------- # Directory where the CMakeFiles are set ( CMAKE_FILE_DIR ${PROJECT_SOURCE_DIR}/CMake ) #----------------------------------------------------------------------------- # Includes. set ( INCS ) #----------------------------------------------------------------------------- # Sources. set ( SRCS main.cpp ) get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES) message(STATUS "This CMake version supports these C++ features:") foreach(i ${cxx_features}) message(STATUS "${i}") endforeach() message(STATUS "Compiler ID/Version: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") #----------------------------------------------------------------------------- # Includes. set ( INCS ) #----------------------------------------------------------------------------- # Sources. set ( SRCS main.cpp ) set(needed_features cxx_lambdas cxx_nullptr) # We may need to define flags based on the needed features. foreach(i ${needed_features}) string(TOUPPER ${i} s) add_definitions("-D${s}") endforeach() if(UNIX) add_executable(${PROJECT_NAME} ${SRCS} ${INCS}) target_compile_features(${PROJECT_NAME} PUBLIC ${needed_features}) elseif (MSVC_VERSION GREATER "1700") # Pick a MSVC version that supports what you need. add_executable(${PROJECT_NAME} ${SRCS} ${INCS}) else() message(FATAL_ERROR "No suitable compiler exists.") endif() #------------------------------------------ -- ___________________________________________ Andrew J. P. Maclean ___________________________________________
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake