]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Bugfix: Properly shell-escape -Xcudafe and -Xlinker
authorMatthias Maier <tamiko@43-1.org>
Mon, 6 Mar 2023 20:28:26 +0000 (14:28 -0600)
committerMatthias Maier <tamiko@43-1.org>
Fri, 17 Mar 2023 12:44:54 +0000 (07:44 -0500)
cmake/config/CMakeLists.txt
cmake/macros/macro_deal_ii_setup_target.cmake
cmake/macros/macro_define_interface_target.cmake
cmake/macros/macro_insource_setup_target.cmake
cmake/macros/macro_populate_target_properties.cmake
cmake/macros/macro_print_target_properties.cmake
cmake/macros/macro_shell_escape_option_groups.cmake [new file with mode: 0644]

index aaa53f90e17aa75c7e4dec462f25fb4f0c1a4c05..7fb02f104f2921157d501610ee292de0d1689824 100644 (file)
@@ -42,12 +42,13 @@ configure_file( # for binary dir:
 ########################################################################
 
 set(_macros
+  ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_add_test.cmake
   ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_initialize_cached_variables.cmake
   ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_invoke_autopilot.cmake
-  ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_setup_target.cmake
-  ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_query_git_information.cmake
-  ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_add_test.cmake
   ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_pickup_tests.cmake
+  ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_query_git_information.cmake
+  ${CMAKE_SOURCE_DIR}/cmake/macros/macro_deal_ii_setup_target.cmake
+  ${CMAKE_SOURCE_DIR}/cmake/macros/macro_shell_escape_option_groups.cmake
   )
 file(COPY ${_macros}
   DESTINATION ${CMAKE_BINARY_DIR}/${DEAL_II_SHARE_RELDIR}/macros
index f3304453179038217c4ac9964a62b265bedf2b81..3c41999f09ffefdc2d004061dbf54d9d6ab52821 100644 (file)
@@ -93,6 +93,7 @@ macro(deal_ii_setup_target _target)
   separate_arguments(_compile_options UNIX_COMMAND
     "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}"
     )
+  shell_escape_option_groups(_compile_options)
   target_compile_options(${_target} PRIVATE
     $<$<COMPILE_LANGUAGE:CXX>:${_compile_options}>
     )
@@ -102,6 +103,7 @@ macro(deal_ii_setup_target _target)
     separate_arguments(_link_options UNIX_COMMAND
       "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}"
       )
+    shell_escape_option_groups(_link_options)
     target_link_options(${_target} PRIVATE
       $<$<COMPILE_LANGUAGE:CXX>:${_link_options}>
       )
index b63ab415348b320743385d2548d04a504d02c0ae..f0444761b82b8e891c27f38385a5d1b7285de42c 100644 (file)
@@ -114,6 +114,7 @@ function(define_interface_target _feature)
     separate_arguments(_compile_options UNIX_COMMAND
       "${${_feature}_CXX_FLAGS} ${${_feature}_CXX_FLAGS_${_build}}"
       )
+    shell_escape_option_groups(_compile_options)
     if(NOT "${_compile_options}" STREQUAL "")
       message(STATUS "    COMPILE_OPTIONS:     ${_compile_options}")
       target_compile_options(${_interface_target} INTERFACE $<$<COMPILE_LANGUAGE:CXX>:${_compile_options}>)
@@ -122,6 +123,7 @@ function(define_interface_target _feature)
     separate_arguments(_link_options UNIX_COMMAND
       "${${_feature}_LINKER_FLAGS} ${${_feature}_LINKER_FLAGS_${_build}}"
       )
+    shell_escape_option_groups(_link_options)
     if(NOT "${_link_options}" STREQUAL "")
       message(STATUS "    LINK_OPTIONS:        ${_link_options}")
       target_link_options(${_interface_target} INTERFACE $<$<COMPILE_LANGUAGE:CXX>:${_link_options}>)
index c67e83e747537c0ddc8dd4257cd1174caba66a83..fb67006e382ae1bffe1f5a9e5965ff73f40a2859 100644 (file)
@@ -34,6 +34,7 @@ function(insource_setup_target _target _build)
   separate_arguments(_compile_options UNIX_COMMAND
     "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}"
     )
+  shell_escape_option_groups(_compile_options)
   target_compile_options(${_target} PRIVATE
     $<$<COMPILE_LANGUAGE:CXX>:${_compile_options}>
     )
@@ -43,6 +44,7 @@ function(insource_setup_target _target _build)
     separate_arguments(_link_options UNIX_COMMAND
       "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}"
       )
+    shell_escape_option_groups(_link_options)
     target_link_options(${_target} PRIVATE
       $<$<COMPILE_LANGUAGE:CXX>:${_link_options}>
       )
index 8363484ea7b11843b9c1bb90d73860b9a86c5759..9cb79f18b64f7fdf57305fbee8ca1dfb9450f1bd 100644 (file)
@@ -97,6 +97,7 @@ function(populate_target_properties _target _build)
   separate_arguments(_compile_options UNIX_COMMAND
     "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}"
     )
+  shell_escape_option_groups(_compile_options)
   target_compile_options(${_target} PRIVATE
     $<$<COMPILE_LANGUAGE:CXX>:${_compile_options}>
     )
@@ -106,6 +107,7 @@ function(populate_target_properties _target _build)
     separate_arguments(_link_options UNIX_COMMAND
       "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}"
       )
+    shell_escape_option_groups(_link_options)
     target_link_options(${_target} PRIVATE
       $<$<COMPILE_LANGUAGE:CXX>:${_link_options}>
       )
index d6f9b9b5ff12d4339da4a0b4acda472db233cf68..daaea35267554b7d7beff66cb76dc124c4fc8237 100644 (file)
@@ -44,7 +44,7 @@ function(print_target_properties _target)
   foreach(_property ${_properties})
     get_target_property(_value ${_target} ${_property})
     if(NOT "${_value}" MATCHES "-NOTFOUND" AND NOT "${_value}" STREQUAL "")
-      string(REPLACE ";" " " _value "${_value}")
+      string(REPLACE ";" "," _value "${_value}") # workaround: we cannot use ";"
       list(APPEND _messages "    ${_property}: ${_value}")
     endif()
   endforeach()
diff --git a/cmake/macros/macro_shell_escape_option_groups.cmake b/cmake/macros/macro_shell_escape_option_groups.cmake
new file mode 100644 (file)
index 0000000..5c04853
--- /dev/null
@@ -0,0 +1,53 @@
+## ---------------------------------------------------------------------
+##
+## Copyright (C) 2023 - 2023 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.
+##
+## ---------------------------------------------------------------------
+
+#
+# Shell escape known option groups such as -Xlinker [...], or
+# -Xcudafe [...] so that the toggle parameter (-Xlinker) does not get
+# deduplicated by CMake.
+#
+# Prerequisite: variable must be the name of a _list_ variable containing
+# compile or link options.
+#
+# Usage:
+#     shell_escape_option_groups(variable)
+#
+
+macro(shell_escape_option_groups _variable)
+  #
+  # We have to capture simple option groups of the form
+  #   "-Xlinker --as-needed"
+  # but also multiple escape sequences such as
+  #   "-Xlinker -rpath -Xlinker /path".
+  # If we happen to escape the latter in the following form:
+  # "SHELL:-Xlinker -rpath" "SHELL:-Xlinker /path" then the first statement
+  # "SHELL:-Xlinker -rpath" might still get deduplicated...
+  #
+  # Let's play this game only over the two options groups above in order to
+  # keep the regex sane.
+  #
+
+  # Matches: "-Xlinker;[option]" and replaces it with "SHELL:-Xlinker [option]"
+  string(REGEX REPLACE
+    "(-Xcudafe|-Xlinker);([^;]+)"
+    "SHELL:\\1 \\2" ${_variable} "${${_variable}}"
+    )
+  # Matches: "SHELL:-Xlinker [option1];SHELL:-Xlinker [option2]" and replaces
+  # it with "SHELL:-Xlinker [option1] -Xlinker [option2]"
+  string(REGEX REPLACE
+    "SHELL:(-Xcudafe [^;]+|-Xlinker [^;]+);SHELL:(-Xcudafe [^;]+|-Xlinker [^;]+)"
+    "SHELL:\\1 \\2" ${_variable} "${${_variable}}"
+    )
+endmacro()

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.