Skip to content
Snippets Groups Projects
Commit 892b6cc4 authored by Markus Blatt's avatar Markus Blatt
Browse files

[Merge][CMake] Merged revisions : 6578

Revision  r6578
.----------------------
[CMake] Added test for shared_ptr.
[CMake] Added test for C++11 features.

.----------------------


[[Imported from SVN: r7134]]
parents 936893b4 27979406
No related branches found
No related tags found
No related merge requests found
......@@ -12,17 +12,22 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
# include dune-common to include pathtest
include_directories("${CMAKE_SOURCE_DIR}")
# set required compiler flags for C++11 (former C++0x)
find_package(CXX11Features)
# search for headers
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
check_include_file("malloc.h" HAVE_MALLOC_H)
check_include_file_cxx("memory" HAVE_MEMORY)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -DHAVE_MEMORY=${HAVE_MEMORY}")
# search for packages
find_package(MPI)
set(HAVE_MPI MPI_FOUND)
set(HAVE_MPI MPI_CXX_FOUND)
find_package(Boost)
set(HAVE_BOOST BOOST_FOUND)
find_package(SharedPtr)
# actually write the config.h file to disk
configure_file(dune-common-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/dune-common-config.h)
......
# find supported C++11 (former C++0x) features
# test for C++11 flags
include(TestCXXAcceptsFlag)
# try to use compiler flag -std=c++11
CHECK_CXX_ACCEPTS_FLAG("-std=c++11" CXX_FLAG_CXX11)
if(CXX_FLAG_CXX11)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
add_definitions("-std=c++11")
else()
CHECK_CXX_ACCEPTS_FLAG("-std=c++0x" CXX_FLAG_CXX0X)
if(CXX_FLAG_CXX0X)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x")
add_definitions("-std=c++0x")
endif(CXX_FLAG_CXX0X)
endif(CXX_FLAG_CXX11)
# perform tests
include(CheckCXXSourceCompiles)
# nullptr
CHECK_CXX_SOURCE_COMPILES("
int main(void)
{
char* ch = nullptr;
return 0;
}
" HAVE_NULLPTR
)
# array and fill
CHECK_CXX_SOURCE_COMPILES("
#include <array>
int main(void)
{
std::array<int,2> a;
a.fill(9);
return 0;
}
" HAVE_ARRAY
)
# __attribute__((always_inline))
CHECK_CXX_SOURCE_COMPILES("
void __attribute__((always_inline)) foo(void) {}
int main(void)
{
foo();
return 0;
};
" HAVE_ATTRIBUTE_ALWAYS_INLINE
)
# __attribute__((unused))
CHECK_CXX_SOURCE_COMPILES("
int main(void)
{
int __attribute__((unused)) foo;
return 0;
};
" HAVE_ATTRIBUTE_UNUSED
)
# __attribute__((deprecated))
CHECK_CXX_SOURCE_COMPILES("
#define DEP __attribute__((deprecated))
class bar
{
bar() DEP;
};
class peng { } DEP;
template <class T>
class t_bar
{
t_bar() DEP;
};
template <class T>
class t_peng {
t_peng() {};
} DEP;
void foo() DEP;
void foo() {};
int main(void)
{
return 0;
};
" HAVE_ATTRIBUTE_DEPRECATED
)
# __attribute__((deprecated("msg")))
CHECK_CXX_SOURCE_COMPILES("
#define DEP __attribute__((deprecated(\"message\")))
class bar {
bar() DEP;
};
class peng { } DEP;
template <class T>
class t_bar
{
t_bar() DEP;
};
template <class T>
class t_peng
{
t_peng() {};
} DEP;
void foo() DEP;
void foo() {};
int main(void)
{
return 0;
};
" HAVE_ATTRIBUTE_DEPRECATED_MSG
)
# static assert
CHECK_CXX_SOURCE_COMPILES("
int main(void)
{
static_assert(true,\"MSG\");
return 0;
}
" HAVE_STATIC_ASSERT
)
# variadic template support
CHECK_CXX_SOURCE_COMPILES("
#include <cassert>
template<typename... T>
int addints(T... x);
int add_ints()
{
return 0;
}
template<typename T1, typename... T>
int add_ints(T1 t1, T... t)
{
return t1 + add_ints(t...);
}
int main(void)
{
assert( 5 == add_ints(9,3,-5,-2) );
return 0;
}
" HAVE_VARIADIC_TEMPLATES
)
# SFINAE on variadic template constructors within template classes
CHECK_CXX_SOURCE_COMPILES("
#include <functional>
template<typename... U>
struct A
{
template<typename... T,
typename = typename std::enable_if<(sizeof...(T) < 2)>::type
>
A(T... t)
: i(1)
{}
template<typename... T,
typename = typename std::enable_if<(sizeof...(T) >= 2)>::type,
typename = void
>
A(T... t)
: i(-1)
{}
A()
: i(1)
{}
int i;
};
int main(void)
{
return (A<int>().i + A<int>(2).i + A<int>(\"foo\",3.4).i + A<int>(8,'a',A<int>()).i == 0 ? 0 : 1);
}
" HAVE_VARIADIC_CONSTRUCTOR_SFINAE
)
# rvalue references
CHECK_CXX_SOURCE_COMPILES("
#include <cassert>
#include <utility>
int foo(int&& x) { return 1; }
int foo(const int& x) { return -1; }
template<typename T>
int forward(T&& x)
{
return foo(std::forward<T>(x));
}
int main(void)
{
int i = 0;
assert( forward(i) + forward(int(2)) == 0);
return 0;
}
" HAVE_RVALUE_REFERENCES
)
# check if make_shared works
macro(CHECK_MAKE_SHARED)
include(CheckIncludeFileCXX)
if(SHARED_PTR_NAMESPACE EQUAL "boost")
CHECK_INCLUDE_FILE_CXX("boost/make_shared.hpp" HAVE_BOOST_MAKE_SHARED_HPP)
endif(SHARED_PTR_NAMESPACE EQUAL "boost")
CHECK_CXX_SOURCE_COMPILES("
#if defined(HAVE_MEMORY)
# include <memory>
#endif
#if defined(HAVE_TR1_MEMORY)
# include <tr1/memory>
#endif
#if defined(HAVE_BOOST_SHARED_PTR_HPP) && defined(HAVE_BOOST_MAKE_SHARED_HPP)
# include <boost/shared_ptr.hpp>
# include <boost/make_shared.hpp>
#endif
int main(void)
{
${SHARED_PTR_NAMESPACE}::make_shared<int>(3);
return 0;
}
" HAVE_MAKE_SHARED)
endmacro(CHECK_MAKE_SHARED)
# check location of shared_ptr header file and the necessary namespace
include(CheckCXXSourceCompiles)
# search namespace
foreach(SHARED_PTR_NAMESPACE_ "std" "tr1" "std::tr1" "boost")
CHECK_CXX_SOURCE_COMPILES("
#include <memory>
#include <string>
using ${SHARED_PTR_NAMESPACE_}::shared_ptr;
using namespace std;
int main(void)
{
shared_ptr<string> test_ptr(new string(\"test string\"));
return 0;
}"
SHARED_PTR_NAMESPACE_FOUND)
if(SHARED_PTR_NAMESPACE_FOUND)
#search header name
foreach(SHARED_PTR_HEADER_ "<memory>" "<tr1/memory>" "<boost/shared_ptr.hpp>")
CHECK_CXX_SOURCE_COMPILES("
# include ${SHARED_PTR_HEADER_}
#include <string>
using ${SHARED_PTR_NAMESPACE_}::shared_ptr;
using namespace std;
int main(void)
{
shared_ptr<string> test_ptr(new string(\"test string\"));
return 0;
}"
SHARED_PTR_HEADER_FOUND)
if(SHARED_PTR_HEADER_FOUND)
# save result
set(SHARED_PTR_NAMESPACE ${SHARED_PTR_NAMESPACE_})
set(SHARED_PTR_HEADER ${SHARED_PTR_HEADER_})
CHECK_MAKE_SHARED()
return()
endif(SHARED_PTR_HEADER_FOUND)
endif(SHARED_PTR_NAMESPACE_FOUND)
endforeach(SHARED_PTR_HEADER_ "memory" "tr1/memory" "boost/shared_ptr.hpp")
endforeach(SHARED_PTR_NAMESPACE_ "std" "tr1" "std::tr1" "boost")
......@@ -3,3 +3,35 @@
#cmakedefine01 HAVE_MEMORY
#cmakedefine01 HAVE_MALLOC_H
#cmakedefine01 HAVE_BOOST
/* If this is set, the member 'size' of FieldVector is a method rather than an
enum */
#define DUNE_COMMON_FIELDVECTOR_SIZE_IS_METHOD
/* Define to 1 if the <array> C++11 is available and support array::fill */
#cmakedefine HAVE_ARRAY
/* Define to 1 if you have the <memory> header file. */
#cmakedefine HAVE_MEMORY
/* The namespace in which SHARED_PTR can be found */
#cmakedefine SHARED_PTR_NAMESPACE ${SHARED_PTR_NAMESPACE}
/* The header in which SHARED_PTR can be found */
#cmakedefine SHARED_PTR_HEADER ${SHARED_PTR_HEADER}
/* Define to 1 if SHARED_PTR_NAMESPACE::make_shared is usable */
#cmakedefine HAVE_MAKE_SHARED
/* Define to 1 if you have <boost/make_shared.hpp> */
#cmakedefine HAVE_BOOST_MAKE_SHARED_HPP
#cmakedefine01 HAVE_NULLPTR
#cmakedefine01 HAVE_STATIC_ASSERT
#cmakedefine01 HAVE_VARIADIC_TEMPLATES
#cmakedefine01 HAVE_VARIADIC_CONSTRUCTOR_SFINAE
#cmakedefine01 HAVE_RVALUE_REFERENCES
/* Include allways usefull headers */
#include <dune/common/deprecated.hh>
#include <dune/common/unused.hh>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment