Commit c815b4af authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

has_cxx11 flag corrected

parent 7dd92158
...@@ -3,35 +3,23 @@ include(CheckCXXSourceCompiles) ...@@ -3,35 +3,23 @@ include(CheckCXXSourceCompiles)
include(CheckIncludeFileCXX) include(CheckIncludeFileCXX)
if (ENABLE_CXX11) if (ENABLE_CXX11)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11_FLAG)
if (NOT COMPILER_SUPPORTS_CXX11) set(CXX11_CODE "#include <tuple>\\n#include <array>\\ntemplate<class... T> using std::tuple<T...>;int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}")
if (COMPILER_SUPPORTS_CXX11_FLAG)
set(CMAKE_REQUIRED_FLAGS "-std=c++11") set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX11) check_cxx_source_compiles("${CXX11_CODE}" CXX11_COMPILES_WITH_CXX11_FLAG)
set(CMAKE_REQUIRED_FLAGS "") set(CMAKE_REQUIRED_FLAGS "")
endif () endif ()
if (COMPILER_SUPPORTS_CXX11 OR CXX_COMPILES_WITH_CXX11) if (COMPILER_SUPPORTS_CXX11_FLAG AND CXX11_COMPILES_WITH_CXX11_FLAG)
add_definitions("-std=c++11") add_definitions("-std=c++11")
else () else ()
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X) check_cxx_source_compiles("${CXX11_CODE}" CXX11_COMPILES)
if (NOT COMPILER_SUPPORTS_CXX0X)
set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX0X)
set(CMAKE_REQUIRED_FLAGS "")
endif ()
if (COMPILER_SUPPORTS_CXX0X OR CXX_COMPILES_WITH_CXX0X)
add_definitions("-std=c++0x")
else ()
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX11_COMPILES)
check_include_file_cxx("array" CXX11_INCLUDES)
if (CXX11_COMPILES AND CXX11_INCLUDES) if (NOT CXX11_COMPILES)
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features") message (FATAL_ERROR "Compiler does not support C++11.")
else ()
message (FATAL_ERROR "Compiler does not support C++11.")
endif ()
endif () endif ()
endif () endif ()
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
# target_link_libraries(yourTarget AMDiS) # target_link_libraries(yourTarget AMDiS)
# #
if (${CMAKE_VERSION} VERSION_LESS "3.0") if (${CMAKE_VERSION} VERSION_LESS "3.2")
message(FATAL_ERROR "The Configuration file was created for CMake version >= 3.0") message(FATAL_ERROR "The Configuration file was created for CMake version >= 3.2")
endif () endif ()
list(APPEND CMAKE_MODULE_PATH ${AMDIS_DIR}) list(APPEND CMAKE_MODULE_PATH ${AMDIS_DIR})
...@@ -39,13 +39,11 @@ set(CMAKE_BUILD_TYPE @CMAKE_BUILD_TYPE@) ...@@ -39,13 +39,11 @@ set(CMAKE_BUILD_TYPE @CMAKE_BUILD_TYPE@)
add_library(amdis_base INTERFACE) add_library(amdis_base INTERFACE)
add_library(AMDiS ALIAS amdis_base) add_library(AMDiS ALIAS amdis_base)
target_compile_definitions(amdis_base INTERFACE target_compile_definitions(amdis_base INTERFACE)
$<$<CONFIG:Release>:DEBUG=0>
$<$<NOT:$<CONFIG:Release>>:DEBUG=1>)
if (AMDIS_NEED_CXX11) if (AMDIS_NEED_CXX11)
set(CMAKE_CXX_STANDARD 11) include(test_compile_features)
set(CMAKE_CXX_STANDARD_REQUIRED ON) target_enable_cxx11(AMDIS_NEED_CXX11 amdis_base INTERFACE)
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=1) target_compile_definitions(amdis_base INTERFACE HAS_CXX11=1)
else () else ()
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=0) target_compile_definitions(amdis_base INTERFACE HAS_CXX11=0)
...@@ -220,8 +218,11 @@ endif () ...@@ -220,8 +218,11 @@ endif ()
get_target_property(AMDIS_INCLUDE_DIRS AMDiS INTERFACE_INCLUDE_DIRECTORIES) get_target_property(AMDIS_INCLUDE_DIRS AMDiS INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(AMDIS_LIBRARIES AMDiS INTERFACE_LINK_LIBRARIES) get_target_property(AMDIS_LIBRARIES AMDiS INTERFACE_LINK_LIBRARIES)
get_target_property(AMDIS_COMPILEFLAGS AMDiS INTERFACE_COMPILE_OPTIONS) get_target_property(AMDIS_COMPILEFLAGS AMDiS INTERFACE_COMPILE_OPTIONS)
if (NOT AMDIS_COMPILEFLAGS)
set(AMDIS_COMPILEFLAGS "")
endif()
get_target_property(_DEFINITIONS AMDiS INTERFACE_COMPILE_DEFINITIONS) get_target_property(_DEFINITIONS AMDiS INTERFACE_COMPILE_DEFINITIONS)
foreach(defn ${_DEFINITIONS}) foreach(defn ${_DEFINITIONS})
list(APPEND AMDIS_COMPILEFLAGS "-D${defn}") list(APPEND AMDIS_COMPILEFLAGS "-D${defn}")
endforeach(s) endforeach(defn)
...@@ -42,9 +42,7 @@ add_library(amdis_base INTERFACE) ...@@ -42,9 +42,7 @@ add_library(amdis_base INTERFACE)
add_library(AMDiS::base ALIAS amdis_base) add_library(AMDiS::base ALIAS amdis_base)
target_include_directories(amdis_base INTERFACE ${SOURCE_DIR}) target_include_directories(amdis_base INTERFACE ${SOURCE_DIR})
target_compile_definitions(amdis_base INTERFACE target_compile_definitions(amdis_base INTERFACE)
$<$<CONFIG:Release>:DEBUG=0>
$<$<NOT:$<CONFIG:Release>>:DEBUG=1>)
include(test_compile_features) include(test_compile_features)
target_enable_cxx11(ENABLE_CXX11 amdis_base INTERFACE) target_enable_cxx11(ENABLE_CXX11 amdis_base INTERFACE)
......
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
include(CheckIncludeFileCXX)
macro(target_enable_cxx11 RESULT_VAR _TARGET_ _SCOPE_) macro(target_enable_cxx11 RESULT_VAR _TARGET_ _SCOPE_)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11_FLAG)
if (NOT COMPILER_SUPPORTS_CXX11) set(CXX11_CODE "#include <tuple>\\n#include <array>\\ntemplate<class... T> using std::tuple<T...>;int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}")
if (COMPILER_SUPPORTS_CXX11_FLAG)
set(CMAKE_REQUIRED_FLAGS "-std=c++11") set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX11) check_cxx_source_compiles("${CXX11_CODE}" CXX11_COMPILES_WITH_CXX11_FLAG)
set(CMAKE_REQUIRED_FLAGS "") set(CMAKE_REQUIRED_FLAGS "")
endif () endif ()
if (COMPILER_SUPPORTS_CXX11 OR CXX_COMPILES_WITH_CXX11) if (COMPILER_SUPPORTS_CXX11_FLAG AND CXX11_COMPILES_WITH_CXX11_FLAG)
target_compile_options(${_TARGET_} ${_SCOPE_} "-std=c++11") target_compile_options(${_TARGET_} ${_SCOPE_} "-std=c++11")
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features") set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features" FORCE)
else () else ()
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X) check_cxx_source_compiles("${CXX11_CODE}" CXX11_COMPILES)
if (NOT COMPILER_SUPPORTS_CXX0X)
set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX_COMPILES_WITH_CXX0X)
set(CMAKE_REQUIRED_FLAGS "")
endif ()
if (COMPILER_SUPPORTS_CXX0X OR CXX_COMPILES_WITH_CXX0X) if (CXX11_COMPILES)
target_compile_options(${_TARGET_} ${_SCOPE_} "-std=c++0x") set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features" FORCE)
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features")
else () else ()
check_cxx_source_compiles("int main(){decltype(1) vec[]={1,2,3}; for(auto&& x:vec);}" CXX11_COMPILES) set(${RESULT_VAR} false CACHE BOOL "Enable C++11 compiler features" FORCE)
check_include_file_cxx("array" CXX11_INCLUDES)
if (CXX11_COMPILES AND CXX11_INCLUDES)
set(${RESULT_VAR} true CACHE BOOL "Enable C++11 compiler features")
else ()
set(${RESULT_VAR} false CACHE BOOL "Enable C++11 compiler features")
endif ()
endif () endif ()
endif () endif ()
endmacro(target_enable_cxx11) endmacro(target_enable_cxx11)
...@@ -47,7 +47,7 @@ typedef size_t aligned_size_t __attribute__ ((aligned(CACHE_LINE))); ...@@ -47,7 +47,7 @@ typedef size_t aligned_size_t __attribute__ ((aligned(CACHE_LINE)));
// C++11 features // C++11 features
// -------------- // --------------
#ifdef HAS_CXX11 #if HAS_CXX11
// __has_feature(cxx_rvalue_references) // __has_feature(cxx_rvalue_references)
#if CLANG_VERSION >= 20900 && !defined(HAS_VARIADIC_TEMPLATES) #if CLANG_VERSION >= 20900 && !defined(HAS_VARIADIC_TEMPLATES)
......
...@@ -47,7 +47,7 @@ typedef size_t aligned_size_t __attribute__ ((aligned(CACHE_LINE))); ...@@ -47,7 +47,7 @@ typedef size_t aligned_size_t __attribute__ ((aligned(CACHE_LINE)));
// C++11 features // C++11 features
// -------------- // --------------
#ifdef HAS_CXX11 #if HAS_CXX11
#if GCC_VERSION >= 40300 && !defined(HAS_VARIADIC_TEMPLATES) #if GCC_VERSION >= 40300 && !defined(HAS_VARIADIC_TEMPLATES)
#define HAS_VARIADIC_TEMPLATES 1 #define HAS_VARIADIC_TEMPLATES 1
......
...@@ -51,7 +51,7 @@ typedef __declspec(align(CACHE_LINE)) size_t aligned_size_t; ...@@ -51,7 +51,7 @@ typedef __declspec(align(CACHE_LINE)) size_t aligned_size_t;
// C++11 features // C++11 features
// -------------- // --------------
#ifdef HAS_CXX11 #if HAS_CXX11
#if INTEL_VERSION >= 1201 && !defined(HAS_VARIADIC_TEMPLATES) #if INTEL_VERSION >= 1201 && !defined(HAS_VARIADIC_TEMPLATES)
#define HAS_VARIADIC_TEMPLATES 1 #define HAS_VARIADIC_TEMPLATES 1
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
#endif #endif
#ifdef HAS_CXX11 #if HAS_CXX11
#include <type_traits> #include <type_traits>
#endif #endif
...@@ -45,7 +45,7 @@ namespace AMDiS ...@@ -45,7 +45,7 @@ namespace AMDiS
// introduce some shortcuts for boost::mpl // introduce some shortcuts for boost::mpl
// --------------------------------------- // ---------------------------------------
#ifdef HAS_CXX11 #if HAS_CXX11
template <bool B> template <bool B>
using bool_ = std::integral_constant<bool, B>; using bool_ = std::integral_constant<bool, B>;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment