From e260ea1dd41aeb02397a49e314a2a2dbcdf5cc89 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 18 Jun 2019 15:06:23 +0200 Subject: [PATCH] C++11: remove the need for Boost.Thread, even with CGAL_Core --- CGAL_Core/include/CGAL/CORE/MemoryPool.h | 35 ++---------------- .../doc/Documentation/Installation.txt | 20 ++--------- Installation/INSTALL.md | 1 - .../cmake/modules/CGALConfig_binary.cmake.in | 9 ----- .../cmake/modules/CGALConfig_install.cmake.in | 9 ----- Installation/cmake/modules/CGAL_Macros.cmake | 7 ---- .../cmake/modules/CGAL_SetupBoost.cmake | 36 +------------------ .../CGAL_SetupCGAL_CoreDependencies.cmake | 24 ------------- 8 files changed, 6 insertions(+), 135 deletions(-) diff --git a/CGAL_Core/include/CGAL/CORE/MemoryPool.h b/CGAL_Core/include/CGAL/CORE/MemoryPool.h index 0f015768f99..64121773f97 100644 --- a/CGAL_Core/include/CGAL/CORE/MemoryPool.h +++ b/CGAL_Core/include/CGAL/CORE/MemoryPool.h @@ -38,13 +38,6 @@ #include #include #include -#if CGAL_STATIC_THREAD_LOCAL_USE_BOOST || (defined(CGAL_HAS_THREADS) && BOOST_GCC) -// Force the use of Boost.Thread with g++ and C++11, because of the PR66944 -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66944 -// See also CGAL PR #1888 -// https://github.com/CGAL/cgal/pull/1888#issuecomment-278284232 -# include -#endif #include // for placement new #include @@ -76,7 +69,7 @@ public: t = t->next; } //); - //CGAL_warning_msg(count == nObjects * blocks.size(), + //Cgal_warning_msg(count == nObjects * blocks.size(), // "Cannot delete memory as there are cyclic references"); if(count == nObjects * blocks.size()){ @@ -92,38 +85,16 @@ public: // Access the corresponding static global allocator. static MemoryPool& global_allocator() { -#if CGAL_STATIC_THREAD_LOCAL_USE_BOOST || (defined(CGAL_HAS_THREADS) && BOOST_GCC) - if(memPool_ptr.get() == nullptr) {memPool_ptr.reset(new Self());} - Self& memPool = * memPool_ptr.get(); -#endif + CGAL_STATIC_THREAD_LOCAL_VARIABLE_0(Self, memPool); return memPool; } private: - Thunk* head; // next available block in the pool + Thunk* head; // next available block in the pool std::vector blocks; -#if CGAL_STATIC_THREAD_LOCAL_USE_BOOST || (defined(CGAL_HAS_THREADS) && BOOST_GCC) - static boost::thread_specific_ptr memPool_ptr; -#elif defined(CGAL_HAS_THREADS) // use the C++11 implementation - static thread_local Self memPool; -#else // not CGAL_HAS_THREADS - static Self memPool; -#endif // not CGAL_HAS_THREADS }; -#if CGAL_STATIC_THREAD_LOCAL_USE_BOOST || (defined(CGAL_HAS_THREADS) && BOOST_GCC) -template -boost::thread_specific_ptr > -MemoryPool::memPool_ptr; -#else // use C++11 or without CGAL_HAS_THREADS -template -# ifdef CGAL_HAS_THREADS -thread_local -# endif -MemoryPool MemoryPool::memPool; -#endif - template< class T, int nObjects > void* MemoryPool< T, nObjects >::allocate(std::size_t) { if ( head == 0 ) { // if no more memory in the pool diff --git a/Documentation/doc/Documentation/Installation.txt b/Documentation/doc/Documentation/Installation.txt index e4615d684fb..e8754dbcdb4 100644 --- a/Documentation/doc/Documentation/Installation.txt +++ b/Documentation/doc/Documentation/Installation.txt @@ -295,7 +295,7 @@ We next list the libraries and essential 3rd party software | Library | CMake Variable | Functionality | Dependencies | | :-------- | :------------- | :------------ | :----------- | -| `%CGAL` | none | Main library | \sc{Gmp}, \sc{Mpfr}, \sc{Boost} (headers), Boost.Thread and Boost.System (library) for compilers not supporting the keywords `thread_local` and the class `std::mutex` | +| `%CGAL` | none | Main library | \sc{Gmp}, \sc{Mpfr}, \sc{Boost} (headers) | | `CGAL_Core` | `WITH_CGAL_Core` | The CORE library for algebraic numbers.\cgalFootnote{CGAL_Core is not part of \cgal, but a custom version of the \sc{Core} library distributed by \cgal for the user convenience and it has it's own license.} | \sc{Gmp} and \sc{Mpfr} | | `CGAL_ImageIO` | `WITH_CGAL_ImageIO` | Utilities to read and write image files | \sc{zlib}, \sc{Vtk}(optional) | | `CGAL_Qt5` | `WITH_CGAL_Qt5` | `QGraphicsView` support for \sc{Qt}5-based demos | \sc{Qt}5 | @@ -388,27 +388,11 @@ The \sc{Boost} libraries are a set of portable C++ source libraries. Most of \sc{Boost} libraries are header-only, but a few of them need to be compiled or installed as binaries. -\cgal requires the \sc{Boost} libraries. In particular the header files -and the threading library (`Boost.Thread` and -`Boost.System` binaries). Version 1.48 (or higher) are needed -for compilers not supporting the keyword `thread_local` and the class `std::mutex` (This is supported for \gcc 4.8 and later when using the \cpp 11 standard, and for Visual C++ starting with 2015, that is VC14). - -As an exception, because of a bug in the \gcc compiler about the \cpp 11 -keyword `thread_local`, the `CGAL_Core` library always requires -`Boost.Thread` if the \gcc compiler is used. - -On Windows, as auto-linking is used, you also need the binaries of -`Boost.Serialization` and `Boost.DateTime`, but the -dependency is artificial and used only at link-time: the \cgal libraries do -not depend on the DLL's of those two libraries. - -In \cgal some demos and examples depend on `Boost.Program_options`. +\cgal only requires the headers of the \sc{Boost} libraries, but some demos and examples depend on the binary library `Boost.Program_options`. In case the \sc{Boost} libraries are not installed on your system already, you can obtain them from `https://www.boost.org/`. For Visual C++ you can download precompiled libraries from `https://sourceforge.net/projects/boost/files/boost-binaries/`. -For Visual C++ versions prior to 2015 `Boost.Thread` is required, so make sure to either install the precompiled -libraries for your compiler or build `libboost-thread` and `libboost-system`. As on Windows there is no canonical directory for where to find \sc{Boost}, we recommend that you define the environment variable diff --git a/Installation/INSTALL.md b/Installation/INSTALL.md index c14c6ec5493..eeefd10cf37 100644 --- a/Installation/INSTALL.md +++ b/Installation/INSTALL.md @@ -31,7 +31,6 @@ CGAL packages, some are only needed for demos. * Boost (>= 1.48) Required for building CGAL and for applications using CGAL - Required compiled Boost library: Boost.Thread, Boost.System Optional compiled Boost library: Boost.Program_options http://www.boost.org/ or http://www.boostpro.com/products/free/ You need the former if you plan to compile the boost libraries yourself, diff --git a/Installation/cmake/modules/CGALConfig_binary.cmake.in b/Installation/cmake/modules/CGALConfig_binary.cmake.in index 23a6399923e..abc58be24ed 100644 --- a/Installation/cmake/modules/CGALConfig_binary.cmake.in +++ b/Installation/cmake/modules/CGALConfig_binary.cmake.in @@ -114,15 +114,6 @@ macro(check_cgal_component COMPONENT) if ( "${CGAL_LIB}" STREQUAL "CGAL" ) set( CGAL_FOUND TRUE ) set( CHECK_CGAL_ERROR_TAIL "" ) - get_property(CGAL_CGAL_is_imported TARGET CGAL::CGAL PROPERTY IMPORTED) - if(CGAL_CGAL_is_imported) - include("${CGAL_MODULES_DIR}/CGAL_SetupBoost.cmake") - get_property(CGAL_requires_Boost_libs - GLOBAL PROPERTY CGAL_requires_Boost_Thread) - if(CGAL_requires_Boost_libs AND TARGET Boost::thread) - set_property(TARGET CGAL::CGAL APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::thread) - endif() - endif() else( "${CGAL_LIB}" STREQUAL "CGAL" ) if ( WITH_${CGAL_LIB} ) if(TARGET CGAL::${CGAL_LIB}) diff --git a/Installation/cmake/modules/CGALConfig_install.cmake.in b/Installation/cmake/modules/CGALConfig_install.cmake.in index a97e23a1a8b..17606ef1ddd 100644 --- a/Installation/cmake/modules/CGALConfig_install.cmake.in +++ b/Installation/cmake/modules/CGALConfig_install.cmake.in @@ -82,15 +82,6 @@ macro(check_cgal_component COMPONENT) # include config file include(${CGAL_CONFIG_DIR}/CGALLibConfig.cmake) set( CHECK_CGAL_ERROR_TAIL "" ) - get_property(CGAL_CGAL_is_imported TARGET CGAL::CGAL PROPERTY IMPORTED) - if(CGAL_CGAL_is_imported) - include("${CGAL_MODULES_DIR}/CGAL_SetupBoost.cmake") - get_property(CGAL_requires_Boost_libs - GLOBAL PROPERTY CGAL_requires_Boost_Thread) - if(CGAL_requires_Boost_libs AND TARGET Boost::thread) - set_property(TARGET CGAL::CGAL APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::thread) - endif() - endif() else() if (EXISTS ${CGAL_CONFIG_DIR}/${CGAL_LIB}Exports.cmake) # include export files for requested component diff --git a/Installation/cmake/modules/CGAL_Macros.cmake b/Installation/cmake/modules/CGAL_Macros.cmake index 23049fbb26e..4d501fa5ce5 100644 --- a/Installation/cmake/modules/CGAL_Macros.cmake +++ b/Installation/cmake/modules/CGAL_Macros.cmake @@ -290,13 +290,6 @@ if( NOT CGAL_MACROS_FILE_INCLUDED ) # To deal with imported targets of Qt5 and Boost, when CGAL # targets are themselves imported by another project. if(NOT CGAL_BUILDING_LIBS) - if (NOT MSVC AND "${component}" STREQUAL "Core") - # See the release notes of CGAL-4.10: CGAL_Core now requires - # Boost.Thread, with all compilers but MSVC. - find_package( Boost 1.48 REQUIRED thread system ) - add_to_list( CGAL_3RD_PARTY_LIBRARIES ${Boost_LIBRARIES} ) - endif() - if (${component} STREQUAL "Qt5") find_package(Qt5 COMPONENTS OpenGL Gui Core Script ScriptTools QUIET) endif() diff --git a/Installation/cmake/modules/CGAL_SetupBoost.cmake b/Installation/cmake/modules/CGAL_SetupBoost.cmake index 758736e3dd0..a1b57c24423 100644 --- a/Installation/cmake/modules/CGAL_SetupBoost.cmake +++ b/Installation/cmake/modules/CGAL_SetupBoost.cmake @@ -17,38 +17,7 @@ set ( CGAL_Boost_Setup TRUE ) include(${CMAKE_CURRENT_LIST_DIR}/CGAL_TweakFindBoost.cmake) -function(CGAL_detect_if_Boost_Thread_is_required) - get_property(PROPERTY_CGAL_requires_Boost_Thread_IS_SET - GLOBAL PROPERTY CGAL_requires_Boost_Thread SET) - if(PROPERTY_CGAL_requires_Boost_Thread_IS_SET) - get_property(CGAL_requires_Boost_libs - GLOBAL PROPERTY CGAL_requires_Boost_Thread) - else() - set ( CGAL_requires_Boost_libs TRUE ) - if ( DEFINED MSVC_VERSION AND "${MSVC_VERSION}" GREATER 1800) - set ( CGAL_requires_Boost_libs FALSE ) - else() - try_run( CGAL_test_cpp_version_RUN_RES CGAL_test_cpp_version_COMPILE_RES - "${CMAKE_BINARY_DIR}" - "${CGAL_MODULES_DIR}/config/support/CGAL_test_cpp_version.cpp" - RUN_OUTPUT_VARIABLE CGAL_cplusplus) - message(STATUS "__cplusplus is ${CGAL_cplusplus}") - if(NOT CGAL_test_cpp_version_RUN_RES) - set ( CGAL_requires_Boost_libs FALSE ) - message(STATUS " --> Do not link with Boost.Thread") - endif() - endif() - endif() - set_property(GLOBAL PROPERTY CGAL_requires_Boost_Thread ${CGAL_requires_Boost_libs}) - set(CGAL_requires_Boost_libs ${CGAL_requires_Boost_libs} PARENT_SCOPE) -endfunction(CGAL_detect_if_Boost_Thread_is_required) - -CGAL_detect_if_Boost_Thread_is_required() -if (CGAL_requires_Boost_libs) - find_package( Boost 1.48 REQUIRED thread system ) -else() - find_package( Boost 1.48 REQUIRED ) -endif() +find_package( Boost 1.48 REQUIRED ) if(Boost_FOUND AND Boost_VERSION VERSION_LESS 1.70) if(DEFINED Boost_DIR AND NOT Boost_DIR) @@ -94,9 +63,6 @@ function(use_CGAL_Boost_support target) endif() if(TARGET Boost::boost) target_link_libraries(${target} ${keyword} Boost::boost) - if (CGAL_requires_Boost_libs) - target_link_libraries(${target} ${keyword} Boost::thread) - endif() else() target_include_directories(${target} SYSTEM ${keyword} ${Boost_INCLUDE_DIRS}) target_link_libraries(${target} ${keyword} ${Boost_LIBRARIES}) diff --git a/Installation/cmake/modules/CGAL_SetupCGAL_CoreDependencies.cmake b/Installation/cmake/modules/CGAL_SetupCGAL_CoreDependencies.cmake index 6c0f2ad214d..609f086694b 100644 --- a/Installation/cmake/modules/CGAL_SetupCGAL_CoreDependencies.cmake +++ b/Installation/cmake/modules/CGAL_SetupCGAL_CoreDependencies.cmake @@ -53,13 +53,6 @@ endif() # keyword, or ``PUBLIC`` otherwise. # -# See the release notes of CGAL-4.10: CGAL_Core now requires -# Boost.Thread, with GNU G++. -if (CMAKE_CXX_COMPILER_ID STREQUAL GNU) - include(${CMAKE_CURRENT_LIST_DIR}/CGAL_TweakFindBoost.cmake) - find_package( Boost 1.48 REQUIRED COMPONENTS thread system ) -endif() - function(CGAL_setup_CGAL_Core_dependencies target) if(ARGV1 STREQUAL INTERFACE) set(keyword INTERFACE) @@ -70,21 +63,4 @@ function(CGAL_setup_CGAL_Core_dependencies target) use_CGAL_GMP_support(CGAL_Core ${keyword}) target_compile_definitions(${target} ${keyword} CGAL_USE_CORE=1) target_link_libraries( CGAL_Core ${keyword} CGAL::CGAL ) - - # See the release notes of CGAL-4.10: CGAL_Core now requires - # Boost.Thread, with GNU G++. - if (CMAKE_CXX_COMPILER_ID STREQUAL GNU) - if(TARGET Boost::thread) - target_link_libraries( CGAL_Core ${keyword} Boost::thread) - else() - # Note that `find_package( Boost...)` must be called in the - # function `CGAL_setup_CGAL_Core_dependencies()` because the - # calling `CMakeLists.txt` may also call `find_package(Boost)` - # between the inclusion of this module, and the call to this - # function. That resets `Boost_LIBRARIES`. - find_package( Boost 1.48 REQUIRED thread system ) - target_link_libraries( CGAL_Core ${keyword} ${Boost_LIBRARIES}) - endif() - endif() - endfunction()