]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Make ENABLE_IF_LINKS macro more robust 11384/head
authorMatthias Maier <tamiko@43-1.org>
Thu, 17 Dec 2020 02:19:44 +0000 (20:19 -0600)
committerMatthias Maier <tamiko@43-1.org>
Thu, 17 Dec 2020 02:29:14 +0000 (20:29 -0600)
cmake/macros/macro_enable_if_links.cmake

index bfcbe31a968d57d7f260d35e016ae73564088ac8..860a0291c684cd99086dc3b7a22ba51d1fcea153 100644 (file)
 #
 
 MACRO(ENABLE_IF_LINKS _variable _flag)
-  STRING(STRIP "${_flag}" _flag_stripped)
+  # keep on top to avoid cluttering the _flag and _flag_stripped variables
+  ENABLE_IF_SUPPORTED(CMAKE_REQUIRED_FLAGS "-Werror")
 
+  STRING(STRIP "${_flag}" _flag_stripped)
   IF(NOT "${_flag_stripped}" STREQUAL "")
     STRING(REGEX REPLACE "^-" "" _flag_name "${_flag_stripped}")
     STRING(REGEX REPLACE "\[-+,\]" "_" _flag_name "${_flag_name}")
 
-    SET(_backup ${CMAKE_REQUIRED_LIBRARIES})
     LIST(APPEND CMAKE_REQUIRED_LIBRARIES "${_flag_stripped}")
     CHECK_CXX_SOURCE_COMPILES("int main(){}" DEAL_II_HAVE_LINKER_FLAG_${_flag_name})
-    SET(CMAKE_REQUIRED_LIBRARIES ${_backup})
+    RESET_CMAKE_REQUIRED()
 
     IF(DEAL_II_HAVE_LINKER_FLAG_${_flag_name})
       SET(${_variable} "${${_variable}} ${_flag_stripped}")

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.