Hi!
I'm going to write FinCXX11.cmake that will do the following:
* find compiler flags that enable C++11 functionality, and store them in
CXX11_CXX_FLAGS;
* declare a component for some (each?) new language feature, and test it
using check_cxx_source_compiles().
I have a few questions:
- for each of supported compilers other than gcc and clang, which flags
should I check?
- for each new language feature, do you have a minimal code example that
check if this feature is available?
Current version of FindCXX11.cmake is attached. This version is not ready
for review.
--
Yury G. Kudryashov,
mailto: [email protected]
include(CheckCXXCompilerFlag)
include(CMakePushCheckState)
set(_cxx11_flags_GNU "-std=gnu++11" "-std=gnu++0x")
set(_cxx11_flags_Clang "-std=gnu++11" "-std=gnu++0x")
unset(CXX11_CXX_FLAGS)
if(DEFINED _cxx11_flags_${CMAKE_CXX_COMPILER_ID})
foreach(flag ${_cxx11_flags_${CMAKE_CXX_COMPILER_ID}})
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" _tmp ${flag})
check_cxx_compiler_flag("${flag}" "${_tmp}")
if(${_tmp})
set(CXX11_CXX_FLAGS "${flag}")
break()
endif()
endforeach()
if(NOT DEFINED CXX11_CXX_FLAGS)
set(_cxx11_flags_notfound_reason "compiler ${CMAKE_CXX_COMPILER_ID} accepts none flags of ${_cxx11_flags_${CMAKE_CXX_COMPILER_ID}}")
endif()
else()
set(_cxx11_flags_notfound_reason "don't know how to tell ${CMAKE_CXX_COMPILER_ID} to use C++11")
endif()
if(NOT DEFINED CXX11_CXX_FLAGS)
if(NOT DEFINED _cxx11_flags_notfound_reason) # Should never happen
set(_cxx11_flags_notfound_reason "unknown reason")
endif()
set(_message "Failed to find flags for C++11: ${_cxx11_flags_notfound_reason}")
if(CXX11_FIND_REQUIRED)
message(SEND_ERROR "${_message}")
else()
message(STATUS "${_message}")
endif()
endif()
set(_cxx11_source_ENUM_CLASS "
enum class A { X, Y };
enum class B { X, Y };
int main () {
A x = A::X;
if (x == A::Y)
x = A::Y;
return 0;
}
")
set(_cxx11_source_EXTENDED_SIZEOF "
struct C {
int m;
static int size_of_m() { return sizeof(m); }
};
int main () {
return sizeof(C::m);
}
")
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS ${CXX11_CXX_FLAGS})
foreach(component ${CXX11_FIND_COMPONENTS})
if(DEFINED _cxx11_source_${component})
check_cxx_source_compiles("${_cxx11_source_${component}}" CXX11_${component}_FOUND)
else()
message(AUTHOR_WARNING "Unknown component ${component}, mark as not found")
set(CXX11_${component}_FOUND FALSE)
endif()
endforeach()
cmake_pop_check_state()
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers