From a1f841f8b1bc93d41f78a918bb0e98d871e2cca2 Mon Sep 17 00:00:00 2001 From: maier Date: Tue, 30 Jul 2013 08:58:51 +0000 Subject: [PATCH] CMake: Bugfix, use use supplied cxx flags throughout the configure phase, clean up CMAKE_REQUIRED_* setup and update documentation git-svn-id: https://svn.dealii.org/trunk@30182 0785d39b-7218-0410-832d-ea1e28bc413d --- .../cmake/checks/check_01_cpu_features.cmake | 12 +------- .../checks/check_02_system_features.cmake | 4 +-- .../cmake/configure/configure_1_lapack.cmake | 6 ++-- .../cmake/configure/configure_1_threads.cmake | 2 +- .../configure/configure_2_trilinos.cmake | 5 ++-- .../cmake/macros/macro_enable_if_links.cmake | 2 +- .../macros/macro_reset_cmake_required.cmake | 30 +++++++++++++++++++ deal.II/cmake/setup_compiler_flags.cmake | 9 ++++-- deal.II/doc/development/cmake-internals.html | 15 ++++++---- 9 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 deal.II/cmake/macros/macro_reset_cmake_required.cmake diff --git a/deal.II/cmake/checks/check_01_cpu_features.cmake b/deal.II/cmake/checks/check_01_cpu_features.cmake index 90b1e1a93d..79a5a661b7 100644 --- a/deal.II/cmake/checks/check_01_cpu_features.cmake +++ b/deal.II/cmake/checks/check_01_cpu_features.cmake @@ -51,14 +51,6 @@ ENDIF() IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) - - # - # These tests depend on certain cpu instruction sets being enabled, so - # use the user supplied compiler flags for the tests as well: - # - SET(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS_SAVED}") - - # # Take care that the following tests are rerun if CMAKE_REQUIRED_FLAGS # changes.. @@ -144,10 +136,9 @@ IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) } " DEAL_II_HAVE_AVX) - - SET(CMAKE_REQUIRED_FLAGS "") ENDIF() + IF(DEAL_II_HAVE_SSE2) IF(DEAL_II_HAVE_AVX) SET(DEAL_II_COMPILER_VECTORIZATION_LEVEL 2) @@ -157,4 +148,3 @@ IF(DEAL_II_HAVE_SSE2) ELSE() SET(DEAL_II_COMPILER_VECTORIZATION_LEVEL 0) ENDIF() - diff --git a/deal.II/cmake/checks/check_02_system_features.cmake b/deal.II/cmake/checks/check_02_system_features.cmake index 25d54167f5..8492325344 100644 --- a/deal.II/cmake/checks/check_02_system_features.cmake +++ b/deal.II/cmake/checks/check_02_system_features.cmake @@ -68,9 +68,9 @@ SWITCH_LIBRARY_PREFERENCE() MARK_AS_ADVANCED(m_LIBRARY) IF(NOT m_LIBRARY MATCHES "-NOTFOUND") - SET(CMAKE_REQUIRED_LIBRARIES ${m_LIBRARY}) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES ${m_LIBRARY}) CHECK_CXX_SYMBOL_EXISTS("jn" "math.h" HAVE_JN) - SET(CMAKE_REQUIRED_LIBRARIES) + RESET_CMAKE_REQUIRED() IF(HAVE_JN) LIST(APPEND DEAL_II_EXTERNAL_LIBRARIES ${m_LIBRARY}) ENDIF() diff --git a/deal.II/cmake/configure/configure_1_lapack.cmake b/deal.II/cmake/configure/configure_1_lapack.cmake index a319fe155b..85e063eae0 100644 --- a/deal.II/cmake/configure/configure_1_lapack.cmake +++ b/deal.II/cmake/configure/configure_1_lapack.cmake @@ -97,7 +97,7 @@ SET(DEAL_II_LAPACK_FUNCTIONS ) MACRO(CHECK_FOR_LAPACK_FUNCTIONS) - SET(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES}) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES}) ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${LAPACK_LINKER_FLAGS}") # # Push -pthread as well: @@ -118,9 +118,7 @@ MACRO(CHECK_FOR_LAPACK_FUNCTIONS) ENDFOREACH() ENDIF() - SET(CMAKE_REQUIRED_LIBRARIES) - STRIP_FLAG(CMAKE_REQUIRED_FLAGS "${LAPACK_LINKER_FLAGS}") - STRIP_FLAG(CMAKE_REQUIRED_FLAGS "-pthread") + RESET_CMAKE_REQUIRED() ENDMACRO() diff --git a/deal.II/cmake/configure/configure_1_threads.cmake b/deal.II/cmake/configure/configure_1_threads.cmake index 8525ad770e..a21ed1eeb1 100644 --- a/deal.II/cmake/configure/configure_1_threads.cmake +++ b/deal.II/cmake/configure/configure_1_threads.cmake @@ -112,7 +112,7 @@ MACRO(SETUP_THREADING) } " DEAL_II_HAVE_MT_POSIX_BARRIERS) - STRIP_FLAG(CMAKE_REQUIRED_FLAGS "${CMAKE_THREAD_LIBS_INIT}") + RESET_CMAKE_REQUIRED() IF(NOT DEAL_II_HAVE_MT_POSIX_BARRIERS) SET(DEAL_II_USE_MT_POSIX_NO_BARRIERS TRUE) ENDIF() diff --git a/deal.II/cmake/configure/configure_2_trilinos.cmake b/deal.II/cmake/configure/configure_2_trilinos.cmake index 41a5f93bf5..10cbe49551 100644 --- a/deal.II/cmake/configure/configure_2_trilinos.cmake +++ b/deal.II/cmake/configure/configure_2_trilinos.cmake @@ -162,7 +162,7 @@ MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var) # Test whether that is indeed the case # IF(${var}) - SET(CMAKE_REQUIRED_INCLUDES ${TRILINOS_INCLUDE_DIRS}) + LIST(APPEND CMAKE_REQUIRED_INCLUDES ${TRILINOS_INCLUDE_DIRS}) PUSH_TEST_FLAG("${DEAL_II_CXX11_FLAG}") CHECK_CXX_SOURCE_COMPILES( @@ -203,8 +203,7 @@ MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var) ENDIF() ENDIF() - POP_TEST_FLAG() - SET(CMAKE_REQUIRED_INCLUDES) + RESET_CMAKE_REQUIRED() # # Remove the following variables from the cache to force a recheck: diff --git a/deal.II/cmake/macros/macro_enable_if_links.cmake b/deal.II/cmake/macros/macro_enable_if_links.cmake index 0f4ef07e96..6c2bfeb6d1 100644 --- a/deal.II/cmake/macros/macro_enable_if_links.cmake +++ b/deal.II/cmake/macros/macro_enable_if_links.cmake @@ -30,7 +30,7 @@ MACRO(ENABLE_IF_LINKS _variable _flag) STRING(REPLACE "," "" _flag_name "${_flag_name}") STRING(REPLACE "--" "__" _flag_name "${_flag_name}") SET(_backup ${CMAKE_REQUIRED_LIBRARIES}) - SET(CMAKE_REQUIRED_LIBRARIES "${_flag_stripped}") + LIST(APPEND CMAKE_REQUIRED_LIBRARIES "${_flag_stripped}") CHECK_CXX_COMPILER_FLAG( "" DEAL_II_HAVE_FLAG_${_flag_name} diff --git a/deal.II/cmake/macros/macro_reset_cmake_required.cmake b/deal.II/cmake/macros/macro_reset_cmake_required.cmake new file mode 100644 index 0000000000..0f2865a3d7 --- /dev/null +++ b/deal.II/cmake/macros/macro_reset_cmake_required.cmake @@ -0,0 +1,30 @@ +## --------------------------------------------------------------------- +## $Id$ +## +## Copyright (C) 2013 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 at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# A small macro to reset the CMAKE_REQUIRED_* variables to its default +# values +# +# Usage: +# RESET_CMAKE_REQUIRED_FLAGS +# + +MACRO(RESET_CMAKE_REQUIRED) + SET(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS_SAVED}) + SET(CMAKE_REQUIRED_INCLUDES) + SET(CMAKE_REQUIRED_LIBRARIES) +ENDMACRO() + diff --git a/deal.II/cmake/setup_compiler_flags.cmake b/deal.II/cmake/setup_compiler_flags.cmake index 4815abf65f..f82147f9e8 100644 --- a/deal.II/cmake/setup_compiler_flags.cmake +++ b/deal.II/cmake/setup_compiler_flags.cmake @@ -65,22 +65,25 @@ # # Check the user provided CXX flags: # + MESSAGE(STATUS "") IF(NOT "${CMAKE_CXX_FLAGS_SAVED}" STREQUAL "${DEAL_II_CXX_FLAGS_SAVED}") + # Rerun this test if cxx flags changed: UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE) ENDIF() SET(DEAL_II_CXX_FLAGS_SAVED "${CMAKE_CXX_FLAGS_SAVED}" CACHE INTERNAL "" FORCE) -SET(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS_SAVED}") +# Initialize all CMAKE_REQUIRED_* variables a this point: +RESET_CMAKE_REQUIRED() + CHECK_CXX_SOURCE_COMPILES( "int main(){ return 0; }" DEAL_II_HAVE_USABLE_CXX_FLAGS) -SET(CMAKE_REQUIRED_FLAGS "") IF(NOT DEAL_II_HAVE_USABLE_CXX_FLAGS) UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE) MESSAGE(FATAL_ERROR "\n" - "Configuration error: Cannot compile with the specified CXX flags: " + "Configuration error: Cannot compile with the user supplied CXX flags:\n" "${CMAKE_CXX_FLAGS_SAVED}\n" ) ENDIF() diff --git a/deal.II/doc/development/cmake-internals.html b/deal.II/doc/development/cmake-internals.html index e889a4ea82..1822169adb 100644 --- a/deal.II/doc/development/cmake-internals.html +++ b/deal.II/doc/development/cmake-internals.html @@ -303,15 +303,18 @@ POP_TEST_FLAG() -
  • Libraries necessary for linkage can be set in the list variable - CMAKE_REQUIRED_LIBRARIES. It is best two hard set - this variable to a specific value and later on cleaning it, - instead of appending/removing: +
  • Necessary include directories and libraries necessary for + linkage can be set in the list variables + CMAKE_REQUIRED_INCLUDES and + CMAKE_REQUIRED_LIBRARIES. It is best ot append these + lists and later on reset CMAKE_REQUIRED_* (including + CMAKE_REQUIRED_FLAGS) to their default values:
     
    -    SET(CMAKE_REQUIRED_LIBRARIES <a list of libraries>
    +    LIST(APPEND CMAKE_REQUIRED_INCLUDES <a list of includes>)
    +    LIST(APPEND CMAKE_REQUIRED_LIBRARIES <a list of libraries>)
         CHECK_CXX_SOURCE_COMPILES(...)
    -    SET(CMAKE_REQUIRED_LIBRARIES)
    +    RESET_CMAKE_REQUIRED()
     	  

    -- 2.39.5