mirror of https://github.com/CGAL/cgal
C++11: remove the need for Boost.Thread, even with CGAL_Core
This commit is contained in:
parent
f0682d311d
commit
e260ea1dd4
|
|
@ -38,13 +38,6 @@
|
|||
#include <CGAL/config.h>
|
||||
#include <CGAL/tss.h>
|
||||
#include <boost/config.hpp>
|
||||
#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 <boost/thread/tss.hpp>
|
||||
#endif
|
||||
|
||||
#include <new> // for placement new
|
||||
#include <cassert>
|
||||
|
|
@ -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<T,nObjects>& 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<void*> blocks;
|
||||
|
||||
#if CGAL_STATIC_THREAD_LOCAL_USE_BOOST || (defined(CGAL_HAS_THREADS) && BOOST_GCC)
|
||||
static boost::thread_specific_ptr<Self> 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 <class T, int nObjects >
|
||||
boost::thread_specific_ptr<MemoryPool<T, nObjects> >
|
||||
MemoryPool<T, nObjects>::memPool_ptr;
|
||||
#else // use C++11 or without CGAL_HAS_THREADS
|
||||
template <class T, int nObjects >
|
||||
# ifdef CGAL_HAS_THREADS
|
||||
thread_local
|
||||
# endif
|
||||
MemoryPool<T, nObjects> MemoryPool<T, nObjects>::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
|
||||
|
|
|
|||
|
|
@ -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 <A HREF="https://www.boost.org/">`https://www.boost.org/`</A>. For Visual C++ you can download precompiled libraries
|
||||
from <A HREF="https://sourceforge.net/projects/boost/files/boost-binaries/">`https://sourceforge.net/projects/boost/files/boost-binaries/`</A>.
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue