From 027dac0358de7d07f772c32cbdf2306dfeae714b Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 6 Jun 2018 22:00:46 +0000 Subject: Merge of branch thread_local_optional_vincent to take into account XCode < v.8 as thread local is not available git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@3554 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9dcf072a4606d1131a925bca4571f0f1b5547d14 --- src/cmake/modules/GUDHI_compilation_flags.cmake | 49 ++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'src/cmake/modules') diff --git a/src/cmake/modules/GUDHI_compilation_flags.cmake b/src/cmake/modules/GUDHI_compilation_flags.cmake index 394f1f42..a01d6e13 100644 --- a/src/cmake/modules/GUDHI_compilation_flags.cmake +++ b/src/cmake/modules/GUDHI_compilation_flags.cmake @@ -1,6 +1,7 @@ # This files manage compilation flags required by GUDHI include(TestCXXAcceptsFlag) +include(CheckCXXSourceCompiles) # add a compiler flag only if it is accepted macro(add_cxx_compiler_flag _flag) @@ -11,6 +12,32 @@ macro(add_cxx_compiler_flag _flag) endif() endmacro() +function(can_cgal_use_cxx11_thread_local) + # This is because of https://github.com/CGAL/cgal/blob/master/Installation/include/CGAL/tss.h + # CGAL is using boost thread if thread_local is not ready (requires XCode 8 for Mac). + # The test in https://github.com/CGAL/cgal/blob/master/Installation/include/CGAL/config.h + # #if __has_feature(cxx_thread_local) || \ + # ( (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L ) || \ + # ( _MSC_VER >= 1900 ) + # #define CGAL_CAN_USE_CXX11_THREAD_LOCAL + # #endif + set(CGAL_CAN_USE_CXX11_THREAD_LOCAL " + int main() { + #ifndef __has_feature + #define __has_feature(x) 0 // Compatibility with non-clang compilers. + #endif + #if __has_feature(cxx_thread_local) || \ + ( (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 && __cplusplus >= 201103L ) || \ + ( _MSC_VER >= 1900 ) + bool has_feature_thread_local = true; + #else + // Explicit error of compilation for CMake test purpose - has_feature_thread_local is not defined + #endif + bool result = has_feature_thread_local; + } ") + check_cxx_source_compiles("${CGAL_CAN_USE_CXX11_THREAD_LOCAL}" CGAL_CAN_USE_CXX11_THREAD_LOCAL_RESULT) +endfunction() + set (CMAKE_CXX_STANDARD 11) enable_testing() @@ -22,14 +49,24 @@ endif() add_cxx_compiler_flag("-Wall") -if(CMAKE_BUILD_TYPE MATCHES Debug) - message("++ Debug compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") -else() - message("++ Release compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") -endif() - if (DEBUG_TRACES) # For programs to be more verbose message(STATUS "DEBUG_TRACES are activated") add_definitions(-DDEBUG_TRACES) endif() + +set(GUDHI_CAN_USE_CXX11_THREAD_LOCAL " + int main() { + thread_local int result = 0; + return result; + } ") +check_cxx_source_compiles("${GUDHI_CAN_USE_CXX11_THREAD_LOCAL}" GUDHI_CAN_USE_CXX11_THREAD_LOCAL_RESULT) +if (GUDHI_CAN_USE_CXX11_THREAD_LOCAL_RESULT) + add_definitions(-DGUDHI_CAN_USE_CXX11_THREAD_LOCAL) +endif() + +if(CMAKE_BUILD_TYPE MATCHES Debug) + message("++ Debug compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") +else() + message("++ Release compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") +endif() -- cgit v1.2.3