From f164b98a1432a944412c54011a68443c3afe19b9 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Sat, 23 May 2020 00:25:47 -0500 Subject: [PATCH] CMake: Remove obsolete threading setup --- bundled/tbb-2018_U2/src/CMakeLists.txt | 2 +- cmake/configure/configure_0_threads.cmake | 37 ++++ cmake/configure/configure_1_lapack.cmake | 2 - cmake/configure/configure_1_tbb.cmake | 87 ++++++++ cmake/configure/configure_1_threads.cmake | 203 ------------------ .../macros/macro_deal_ii_package_handle.cmake | 11 + cmake/macros/macro_find_system_library.cmake | 1 + cmake/modules/FindBOOST.cmake | 6 - cmake/modules/FindUMFPACK.cmake | 1 - 9 files changed, 137 insertions(+), 213 deletions(-) create mode 100644 cmake/configure/configure_0_threads.cmake create mode 100644 cmake/configure/configure_1_tbb.cmake delete mode 100644 cmake/configure/configure_1_threads.cmake diff --git a/bundled/tbb-2018_U2/src/CMakeLists.txt b/bundled/tbb-2018_U2/src/CMakeLists.txt index f9c0692922..4129306816 100644 --- a/bundled/tbb-2018_U2/src/CMakeLists.txt +++ b/bundled/tbb-2018_U2/src/CMakeLists.txt @@ -45,7 +45,7 @@ ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wtautological-overlap-compare=0") SET(CMAKE_INCLUDE_CURRENT_DIR TRUE) INCLUDE_DIRECTORIES( - ${THREADS_BUNDLED_INCLUDE_DIRS} + ${TBB_BUNDLED_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/rml/include ) diff --git a/cmake/configure/configure_0_threads.cmake b/cmake/configure/configure_0_threads.cmake new file mode 100644 index 0000000000..33ae7145c6 --- /dev/null +++ b/cmake/configure/configure_0_threads.cmake @@ -0,0 +1,37 @@ +## --------------------------------------------------------------------- +## +## Copyright (C) 2012 - 2020 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE.md at +## the top level directory of deal.II. +## +## --------------------------------------------------------------------- + + +# +# Set up threading: +# + +# Clear the test flags because FindThreads.cmake will use a C compiler: +CLEAR_CMAKE_REQUIRED() + +SWITCH_LIBRARY_PREFERENCE() +FIND_PACKAGE(Threads) +SWITCH_LIBRARY_PREFERENCE() + +RESET_CMAKE_REQUIRED() + +ADD_FLAGS(DEAL_II_LINKER_FLAGS "${CMAKE_THREAD_LIBS_INIT}") + +IF(NOT Threads_FOUND) + MESSAGE(FATAL_ERROR + "\nFatal configuration error: CMake was unable to detect any threading " + "support offered by the current compiler. Configuration cannot continue.\n\n" + ) +ENDIF() diff --git a/cmake/configure/configure_1_lapack.cmake b/cmake/configure/configure_1_lapack.cmake index 87729c9ef8..30204fbb59 100644 --- a/cmake/configure/configure_1_lapack.cmake +++ b/cmake/configure/configure_1_lapack.cmake @@ -34,8 +34,6 @@ MACRO(FEATURE_LAPACK_FIND_EXTERNAL var) SET(CMAKE_REQUIRED_LIBRARIES ${DEAL_II_LINKER_FLAGS_SAVED} ${LAPACK_LINKER_FLAGS} ${LAPACK_LIBRARIES} ) - # Push -pthread as well: - ENABLE_IF_SUPPORTED(CMAKE_REQUIRED_FLAGS "-pthread") CHECK_C_SOURCE_COMPILES(" char daxpy_(); char dgeev_(); char dgeevx_(); char dgelsd_(); char diff --git a/cmake/configure/configure_1_tbb.cmake b/cmake/configure/configure_1_tbb.cmake new file mode 100644 index 0000000000..be585ac5dc --- /dev/null +++ b/cmake/configure/configure_1_tbb.cmake @@ -0,0 +1,87 @@ +## --------------------------------------------------------------------- +## +## Copyright (C) 2012 - 2020 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE.md at +## the top level directory of deal.II. +## +## --------------------------------------------------------------------- + +# +# Configuration for thread support in deal.II with the help of the tbb +# library: +# + +MACRO(FEATURE_TBB_FIND_EXTERNAL var) + FIND_PACKAGE(TBB) + + IF(TBB_FOUND) + SET(${var} TRUE) + ENDIF() + + # + # TBB currently uses the version numbering scheme + # + # YYYY.X + # + # (e.g., 2018.0) where YYYY is the year of the release and X is the yearly + # release number. Older versions use + # + # X.Y.Z + # + # (e.g., 4.2.1). Since we are compatible with all versions that use the new + # numbering scheme we only check for very old versions here. + # + # TBB versions before 4.2 are missing some explicit calls to std::atomic::load + # in ternary expressions; these cause compilation errors in some compilers + # (such as GCC 8.1 and newer). To fix this we simply blacklist all older + # versions: + # + IF(TBB_VERSION VERSION_LESS "4.2") + # Clear the previously determined version numbers to avoid confusion + SET(TBB_VERSION "bundled") + SET(TBB_VERSION_MAJOR "") + SET(TBB_VERSION_MINOR "") + + MESSAGE(STATUS + "The externally provided TBB library is older than version 4.2.0, which " + "cannot be used with deal.II." + ) + SET(TBB_ADDITIONAL_ERROR_STRING + "The externally provided TBB library is older than version\n" + "4.2.0, which is the oldest version compatible with deal.II and its\n" + "supported compilers." + ) + SET(${var} FALSE) + ENDIF() +ENDMACRO() + + +MACRO(FEATURE_TBB_CONFIGURE_EXTERNAL) +ENDMACRO() + + +MACRO(FEATURE_TBB_CONFIGURE_BUNDLED) + # + # We have to disable a bunch of warnings: + # + ENABLE_IF_SUPPORTED(TBB_CXX_FLAGS "-Wno-parentheses") + + # + # tbb uses dlopen/dlclose, so link against libdl.so as well: + # + LIST(APPEND TBB_LIBRARIES ${CMAKE_DL_LIBS}) + + LIST(APPEND TBB_BUNDLED_INCLUDE_DIRS ${TBB_FOLDER}/include) +ENDMACRO() + + +CONFIGURE_FEATURE(TBB) +SET(DEAL_II_WITH_THREADS ${DEAL_II_WITH_TBB}) + diff --git a/cmake/configure/configure_1_threads.cmake b/cmake/configure/configure_1_threads.cmake deleted file mode 100644 index c15b94b78c..0000000000 --- a/cmake/configure/configure_1_threads.cmake +++ /dev/null @@ -1,203 +0,0 @@ -## --------------------------------------------------------------------- -## -## Copyright (C) 2012 - 2020 by the deal.II authors -## -## This file is part of the deal.II library. -## -## The deal.II library is free software; you can use it, redistribute -## it, and/or modify it under the terms of the GNU Lesser General -## Public License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## The full text of the license can be found in the file LICENSE.md at -## the top level directory of deal.II. -## -## --------------------------------------------------------------------- - -# -# Configuration for thread support in deal.II with the help of the tbb -# library: -# - -# -# Set up general threading: -# The macro will be included in CONFIGURE_FEATURE_THREADS_EXTERNAL/BUNDLED. -# -MACRO(SETUP_THREADING) - # - # Unfortunately the FindThreads macro needs a working C compiler - # - IF(CMAKE_C_COMPILER_WORKS) - # - # Clear the test flags because FindThreads.cmake will use a C compiler: - # - CLEAR_CMAKE_REQUIRED() - - SWITCH_LIBRARY_PREFERENCE() - FIND_PACKAGE(Threads) - SWITCH_LIBRARY_PREFERENCE() - - RESET_CMAKE_REQUIRED() - - # - # The FindThreads macro returned a linker option instead of the actual - # library name in earlier versions. We still require the linker option, - # so we fix the corresponding variable. - # - See: https://gitlab.kitware.com/cmake/cmake/issues/19747 - # - IF(CMAKE_THREAD_LIBS_INIT AND NOT "${CMAKE_THREAD_LIBS_INIT}" MATCHES "^-l") - STRING(PREPEND CMAKE_THREAD_LIBS_INIT "-l") - ENDIF() - - ELSE() - - # - # We have no way to query for thread support. Just assume that it is - # provided by Pthreads... - # - MESSAGE(STATUS - "No suitable C compiler was found! Assuming threading is provided by Pthreads." - ) - SET_IF_EMPTY(Threads_FOUND TRUE) - SET_IF_EMPTY(CMAKE_THREAD_LIBS_INIT "-lpthread") - SET_IF_EMPTY(CMAKE_USE_PTHREADS_INIT TRUE) - ENDIF() - - IF(NOT Threads_FOUND) - # - # TODO: This is a dead end. Threading might be set up with internal TBB - # so we have no way of returning unsuccessfully... - # - MESSAGE(FATAL_ERROR - "\nInternal configuration error: No Threading support found\n\n" - ) - ENDIF() - - MARK_AS_ADVANCED(pthread_LIBRARY) - - # - # Change -lpthread to -pthread for better compatibility on non linux - # platforms: - # - IF("${CMAKE_THREAD_LIBS_INIT}" MATCHES "-lpthread") - CHECK_CXX_COMPILER_FLAG("-pthread" - DEAL_II_HAVE_FLAG_pthread - ) - IF(DEAL_II_HAVE_FLAG_pthread) - STRING(REPLACE "-lpthread" "-pthread" CMAKE_THREAD_LIBS_INIT - "${CMAKE_THREAD_LIBS_INIT}" - ) - ENDIF() - ENDIF() - - ADD_FLAGS(THREADS_LINKER_FLAGS "${CMAKE_THREAD_LIBS_INIT}") -ENDMACRO() - - -# -# Set up the tbb library: -# - -MACRO(FEATURE_THREADS_FIND_EXTERNAL var) - FIND_PACKAGE(TBB) - - IF(TBB_FOUND) - SET(${var} TRUE) - ENDIF() - - # - # TBB currently uses the version numbering scheme - # - # YYYY.X - # - # (e.g., 2018.0) where YYYY is the year of the release and X is the yearly - # release number. Older versions use - # - # X.Y.Z - # - # (e.g., 4.2.1). Since we are compatible with all versions that use the new - # numbering scheme we only check for very old versions here. - # - # TBB versions before 4.2 are missing some explicit calls to std::atomic::load - # in ternary expressions; these cause compilation errors in some compilers - # (such as GCC 8.1 and newer). To fix this we simply blacklist all older - # versions: - # - IF(TBB_VERSION VERSION_LESS "4.2") - # Clear the previously determined version numbers to avoid confusion - SET(TBB_VERSION "bundled") - SET(TBB_VERSION_MAJOR "") - SET(TBB_VERSION_MINOR "") - - MESSAGE(STATUS - "The externally provided TBB library is older than version 4.2.0, which " - "cannot be used with deal.II." - ) - SET(THREADS_ADDITIONAL_ERROR_STRING - "The externally provided TBB library is older than version\n" - "4.2.0, which is the oldest version compatible with deal.II and its\n" - "supported compilers." - ) - SET(${var} FALSE) - ENDIF() -ENDMACRO() - - -MACRO(FEATURE_THREADS_CONFIGURE_EXTERNAL) - - IF(CMAKE_BUILD_TYPE MATCHES "Debug") - IF(TBB_WITH_DEBUG_LIB) - LIST(APPEND THREADS_DEFINITIONS_DEBUG "TBB_USE_DEBUG" "TBB_DO_ASSERT=1") - LIST(APPEND THREADS_USER_DEFINITIONS_DEBUG "TBB_USE_DEBUG" "TBB_DO_ASSERT=1") - ENDIF() - ENDIF() - - SETUP_THREADING() - - LIST(APPEND THREADS_LIBRARIES ${TBB_LIBRARIES}) - LIST(APPEND THREADS_INCLUDE_DIRS ${TBB_INCLUDE_DIRS}) - LIST(APPEND THREADS_USER_INCLUDE_DIRS ${TBB_USER_INCLUDE_DIRS}) - -ENDMACRO() - - -MACRO(FEATURE_THREADS_CONFIGURE_BUNDLED) - # - # Setup threading (before configuring our build...) - # - SETUP_THREADING() - - # - # We have to disable a bunch of warnings: - # - ENABLE_IF_SUPPORTED(THREADS_CXX_FLAGS "-Wno-parentheses") - - # - # Add some definitions to use the header files in debug mode: - # - IF (CMAKE_BUILD_TYPE MATCHES "Debug") - LIST(APPEND THREADS_DEFINITIONS_DEBUG "TBB_USE_DEBUG" "TBB_DO_ASSERT=1") - LIST(APPEND THREADS_USER_DEFINITIONS_DEBUG "TBB_USE_DEBUG" "TBB_DO_ASSERT=1") - ENDIF() - - # - # Workaround for an issue with C++11 mode, non gcc-compilers and missing - # template std::is_trivially_copyable - # - IF( NOT DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE AND - NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU" ) - LIST(APPEND THREADS_DEFINITIONS "TBB_IMPLEMENT_CPP0X=1") - LIST(APPEND THREADS_USER_DEFINITIONS "TBB_IMPLEMENT_CPP0X=1") - ENDIF() - - # - # tbb uses dlopen/dlclose, so link against libdl.so as well: - # - # TODO: Also necessary for external lib, use preference toggle - # - LIST(APPEND THREADS_LIBRARIES ${CMAKE_DL_LIBS}) - - LIST(APPEND THREADS_BUNDLED_INCLUDE_DIRS ${TBB_FOLDER}/include) -ENDMACRO() - - -CONFIGURE_FEATURE(THREADS) diff --git a/cmake/macros/macro_deal_ii_package_handle.cmake b/cmake/macros/macro_deal_ii_package_handle.cmake index 6f12ffda23..d7c8ce851d 100644 --- a/cmake/macros/macro_deal_ii_package_handle.cmake +++ b/cmake/macros/macro_deal_ii_package_handle.cmake @@ -153,6 +153,17 @@ MACRO(DEAL_II_PACKAGE_HANDLE _feature _var) ENDIF() ENDFOREACH() + # + # Remove certain system libraries from the link interface + # + FOREACH(_suffix LIBRARIES LIBRARIES_DEBUG LIBRARIES_RELEASE) + IF(NOT "${${_feature}_${_suffix}}" STREQUAL "") + LIST(REMOVE_ITEM ${_feature}_${_suffix} + "pthread" "-pthread" "-lpthread" "c" "-lc" + ) + ENDIF() + ENDFOREACH() + MESSAGE(STATUS "Found ${_feature}") MARK_AS_ADVANCED(${_feature}_DIR ${_feature}_ARCH) diff --git a/cmake/macros/macro_find_system_library.cmake b/cmake/macros/macro_find_system_library.cmake index 5ec62800ab..945edda850 100644 --- a/cmake/macros/macro_find_system_library.cmake +++ b/cmake/macros/macro_find_system_library.cmake @@ -36,6 +36,7 @@ MACRO(FIND_SYSTEM_LIBRARY) UNSET(${_variable} CACHE) SET(${_variable} ${_arg} CACHE STRING "A system library.") SET(${_variable} ${_arg}) + MARK_AS_ADVANCED(${_variable}) BREAK() ELSE() UNSET(${_variable} CACHE) diff --git a/cmake/modules/FindBOOST.cmake b/cmake/modules/FindBOOST.cmake index 6e26fbd51e..02790e4691 100644 --- a/cmake/modules/FindBOOST.cmake +++ b/cmake/modules/FindBOOST.cmake @@ -86,12 +86,6 @@ ENDIF() UNSET(Boost_NO_BOOST_CMAKE) IF(Boost_FOUND) - # - # Remove "pthread" from Boost_LIBRARIES. Threading, if necessary, is - # already set up via configure_1_threads.cmake. - # - LIST(REMOVE_ITEM Boost_LIBRARIES "pthread") - SET(BOOST_VERSION_MAJOR "${Boost_MAJOR_VERSION}") SET(BOOST_VERSION_MINOR "${Boost_MINOR_VERSION}") SET(BOOST_VERSION_SUBMINOR "${Boost_SUBMINOR_VERSION}") diff --git a/cmake/modules/FindUMFPACK.cmake b/cmake/modules/FindUMFPACK.cmake index 1d00591c71..a50b879345 100644 --- a/cmake/modules/FindUMFPACK.cmake +++ b/cmake/modules/FindUMFPACK.cmake @@ -125,7 +125,6 @@ FIND_UMFPACK_LIBRARY(SuiteSparse_config suitesparseconfig) # by ldd :-( ): # FIND_SYSTEM_LIBRARY(rt_LIBRARY NAMES rt) -MARK_AS_ADVANCED(rt_LIBRARY) DEAL_II_PACKAGE_HANDLE(UMFPACK LIBRARIES -- 2.39.5