Commit 17a7ad5c authored by Lynn Garren's avatar Lynn Garren

add CLHEP_SINGLE_THREAD option to diable threading

parent b4be0ce6
......@@ -5,6 +5,7 @@
# [-DCMAKE_C_COMPILER=...] [-DCMAKE_CXX_COMPILER=...]
# [-DCMAKE_CXX_FLAGS=...]
# [-DCLHEP_BUILD_CXXSTD="-std=c++NN"] (use specified c++ extension)
# [-DCLHEP_SINGLE_THREAD=ON] (disable multi threading)
# [-DCLHEP_DEBUG_MESSAGES=ON] (see more verbose output)
# [-DCLHEP_BUILD_DOCS=ON]
# [-DLIB_SUFFIX=64]
......@@ -121,9 +122,6 @@ clhep_build_libclhep( ${CLHEP_libraries} )
# provide tools for other packages to include CLHEP easily
clhep_toolchain()
# CLHEP_BUILD_DOCS is OFF (false) by default
option(CLHEP_BUILD_DOCS "Build and install CLHEP documentation" OFF)
# - Build docucumentation if required
if(CLHEP_BUILD_DOCS)
message(STATUS "Enabled build and install of documents")
......
......@@ -13,8 +13,7 @@ set( Random_simple_tests testSaveEngineStatus
testBug73093
testEngineCopy
testDistCopy
testRanecuSequence
testThreaded )
testRanecuSequence )
else()
set( Random_simple_tests testSaveEngineStatus
testInstanceRestore
......@@ -27,8 +26,10 @@ set( Random_simple_tests testSaveEngineStatus
testEngineCopy
testDistCopy
testZiggurat
testRanecuSequence
testThreaded )
testRanecuSequence )
endif()
if( NOT CLHEP_SINGLE_THREAD )
set( Random_simple_tests ${Random_simple_tests} testThreaded )
endif()
foreach ( test ${Random_tests} )
......
......@@ -2,10 +2,14 @@
set( pkginclude_HEADERS atomic_int.h
keywords.h
memory.h
noncopyable.h
thread_local.h )
noncopyable.h )
# notice that defs.h is not referenced here
INSTALL (FILES ${pkginclude_HEADERS}
DESTINATION include/CLHEP/Utility )
# thread_local.h is a special case
CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/thread_local.in
${CLHEP_BINARY_DIR}/CLHEP/Utility/thread_local.h @ONLY)
INSTALL ( FILES ${CLHEP_BINARY_DIR}/CLHEP/Utility/thread_local.h
DESTINATION include/CLHEP/Utility/thread_local.h )
......@@ -6,23 +6,26 @@
// Use thread_local when the compiler declares it uses the C++11 standard
//
// ======================================================================
#ifdef CLHEP_SINGLE_THREAD
#define CLHEP_THREAD_LOCAL
#else
#if __cplusplus >= 201103L
#if __cplusplus >= 201103L
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)
#define CLHEP_THREAD_LOCAL thread_local
#elif __clang__
#if __has_feature(cxx_thread_local)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)
#define CLHEP_THREAD_LOCAL thread_local
#elif __clang__
#if __has_feature(cxx_thread_local)
#define CLHEP_THREAD_LOCAL thread_local
#else
#define CLHEP_THREAD_LOCAL
#endif
#else
#define CLHEP_THREAD_LOCAL
#endif
#else
#define CLHEP_THREAD_LOCAL
#endif
#else
#define CLHEP_THREAD_LOCAL
#endif
#endif
#endif // CLHEP_THREAD_LOCAL_H
#ifndef CLHEP_THREAD_LOCAL_H
#define CLHEP_THREAD_LOCAL_H
// ======================================================================
//
// Use thread_local and multithreading are enabled by default
// To disable multithreading compile with -DCLHEP_SINGLE_THREAD=ON
//
// ======================================================================
@CLHEP_THREAD_DEFINITION@
#endif // CLHEP_THREAD_LOCAL_H
......@@ -20,6 +20,12 @@
# check for -DLIB_SUFFIX=xxx and process intelligently
#
# CLHEP_SINGLE_THREAD is OFF (false) by default
option(CLHEP_SINGLE_THREAD "Build without multithreading" OFF)
# CLHEP_BUILD_DOCS is OFF (false) by default
option(CLHEP_BUILD_DOCS "Build and install CLHEP documentation" OFF)
macro( clhep_check_variable_names )
# useful if you need to check a variable
message( STATUS "clhep_check_variable_names: CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}" )
......@@ -223,17 +229,22 @@ macro( clhep_set_compiler_flags )
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "" FORCE)
endif()
# find pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
##message(STATUS "clhep_set_compiler_flags debug: CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "cmake build type is ${CMAKE_BUILD_TYPE}")
_clhep_check_cxxstd()
if(THREADS_HAVE_PTHREAD_ARG)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
elseif(CMAKE_COMPILER_IS_GNUCXX)
# needed when building with gcc on OSX
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
# find pthread
if(CLHEP_SINGLE_THREAD)
set(CLHEP_THREAD_DEFINITION "#define CLHEP_THREAD_LOCAL")
else()
set(CLHEP_THREAD_DEFINITION "#define CLHEP_THREAD_LOCAL thread_local")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
##message(STATUS "clhep_set_compiler_flags debug: CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "cmake build type is ${CMAKE_BUILD_TYPE}")
if(THREADS_HAVE_PTHREAD_ARG)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
elseif(CMAKE_COMPILER_IS_GNUCXX)
# needed when building with gcc on OSX
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
endif()
endif()
if( CLHEP_DEBUG_MESSAGES )
message(STATUS "enable c++11 extensions: ${CMAKE_CXX_FLAGS}")
......
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