[CMake] Using CMAKE_CXX_KNOWN_FEATURES
Andrew Maclean
andrew.amaclean at gmail.com
Tue Nov 25 02:45:45 EST 2014
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
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141125/4a15cae6/attachment.html>
More information about the CMake
mailing list