diff options
-rw-r--r-- | Auxiliary/vim/syntax/cmake.vim | 2 | ||||
-rw-r--r-- | Help/command/separate_arguments.rst | 9 | ||||
-rw-r--r-- | Help/release/dev/separgs-native.rst | 5 | ||||
-rw-r--r-- | Modules/CMakeParseImplicitLinkInfo.cmake | 6 | ||||
-rw-r--r-- | Modules/FindHDF5.cmake | 6 | ||||
-rw-r--r-- | Modules/FindMPI.cmake | 3 | ||||
-rw-r--r-- | Modules/FindOpenMP.cmake | 6 | ||||
-rw-r--r-- | Source/cmSeparateArgumentsCommand.cxx | 7 | ||||
-rw-r--r-- | Tests/CMakeTests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/CMakeTests/SeparateArgumentsTest.cmake.in | 25 | ||||
-rw-r--r-- | Tests/FindOpenMP/Test/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/separate_arguments/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/separate_arguments/EmptyCommand.cmake | 6 | ||||
-rw-r--r-- | Tests/RunCMake/separate_arguments/NativeCommand.cmake | 19 | ||||
-rw-r--r-- | Tests/RunCMake/separate_arguments/PlainCommand.cmake | 8 | ||||
-rw-r--r-- | Tests/RunCMake/separate_arguments/RunCMakeTest.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/separate_arguments/UnixCommand.cmake | 8 | ||||
-rw-r--r-- | Tests/RunCMake/separate_arguments/WindowsCommand.cmake | 8 |
19 files changed, 84 insertions, 52 deletions
diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index 1f19cb7..aca7c41 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/Auxiliary/vim/syntax/cmake.vim @@ -320,7 +320,7 @@ syn keyword cmakeKWremove \ contained syn keyword cmakeKWseparate_arguments - \ MSDN UNIX_COMMAND VARIABLE WINDOWS WINDOWS_COMMAND _COMMAND + \ MSDN NATIVE_COMMAND UNIX_COMMAND VARIABLE WINDOWS WINDOWS_COMMAND _COMMAND \ contained syn keyword cmakeKWset diff --git a/Help/command/separate_arguments.rst b/Help/command/separate_arguments.rst index 1fd3cd1..47982a5 100644 --- a/Help/command/separate_arguments.rst +++ b/Help/command/separate_arguments.rst @@ -5,9 +5,9 @@ Parse space-separated arguments into a semicolon-separated list. :: - separate_arguments(<var> <UNIX|WINDOWS>_COMMAND "<args>") + separate_arguments(<var> <NATIVE|UNIX|WINDOWS>_COMMAND "<args>") -Parses a unix- or windows-style command-line string "<args>" and +Parses a UNIX- or Windows-style command-line string "<args>" and stores a semicolon-separated list of the arguments in ``<var>``. The entire command line must be given in one "<args>" argument. @@ -16,12 +16,15 @@ recognizes both single-quote and double-quote pairs. A backslash escapes the next literal character (``\"`` is ``"``); there are no special escapes (``\n`` is just ``n``). -The ``WINDOWS_COMMAND`` mode parses a windows command-line using the same +The ``WINDOWS_COMMAND`` mode parses a Windows command-line using the same syntax the runtime library uses to construct argv at startup. It separates arguments by whitespace that is not double-quoted. Backslashes are literal unless they precede double-quotes. See the MSDN article `Parsing C Command-Line Arguments`_ for details. +The ``NATIVE_COMMAND`` mode parses a Windows command-line if the host +system is Windows, and a UNIX command-line otherwise. + .. _`Parsing C Command-Line Arguments`: https://msdn.microsoft.com/library/a1y7w461.aspx :: diff --git a/Help/release/dev/separgs-native.rst b/Help/release/dev/separgs-native.rst new file mode 100644 index 0000000..943f08e --- /dev/null +++ b/Help/release/dev/separgs-native.rst @@ -0,0 +1,5 @@ +separgs-native +------------------- + +* A ``NATIVE_COMMAND`` mode was added to :command:`separate_arguments` + performing argument separation depening on the host operating system. diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake index 3273443..ad3c00f 100644 --- a/Modules/CMakeParseImplicitLinkInfo.cmake +++ b/Modules/CMakeParseImplicitLinkInfo.cmake @@ -38,11 +38,7 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj set(line "${xline}") endif() endif() - if(UNIX) - separate_arguments(args UNIX_COMMAND "${line}") - else() - separate_arguments(args WINDOWS_COMMAND "${line}") - endif() + separate_arguments(args NATIVE_COMMAND "${line}") list(GET args 0 cmd) endif() set(is_msvc 0) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index 1e2ea69..5962c5b 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -354,11 +354,7 @@ macro( _HDF5_parse_compile_line libraries libraries_hl) - if(UNIX) - separate_arguments(_HDF5_COMPILE_ARGS UNIX_COMMAND "${${compile_line_var}}") - else() - separate_arguments(_HDF5_COMPILE_ARGS WINDOWS_COMMAND "${${compile_line_var}}") - endif() + separate_arguments(_HDF5_COMPILE_ARGS NATIVE_COMMAND "${${compile_line_var}}") foreach(arg IN LISTS _HDF5_COMPILE_ARGS) if("${arg}" MATCHES "^-I(.*)$") diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index fab53cb..37f3255 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -645,8 +645,7 @@ foreach (lang C CXX Fortran) add_library(MPI::MPI_${lang} INTERFACE IMPORTED) endif() if(MPI_${lang}_COMPILE_FLAGS) - set(_MPI_${lang}_COMPILE_OPTIONS "${MPI_${lang}_COMPILE_FLAGS}") - separate_arguments(_MPI_${lang}_COMPILE_OPTIONS) + separate_arguments(_MPI_${lang}_COMPILE_OPTIONS NATIVE_COMMAND "${MPI_${lang}_COMPILE_FLAGS}") set_property(TARGET MPI::MPI_${lang} PROPERTY INTERFACE_COMPILE_OPTIONS "${_MPI_${lang}_COMPILE_OPTIONS}") endif() diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index 8c1b018..e7d9d5f 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -411,11 +411,7 @@ foreach(LANG IN ITEMS C CXX Fortran) add_library(OpenMP::OpenMP_${LANG} INTERFACE IMPORTED) endif() if(OpenMP_${LANG}_FLAGS) - if(CMAKE_HOST_WIN32) - separate_arguments(_OpenMP_${LANG}_OPTIONS WINDOWS_COMMAND "${OpenMP_${LANG}_FLAGS}") - else() - separate_arguments(_OpenMP_${LANG}_OPTIONS UNIX_COMMAND "${OpenMP_${LANG}_FLAGS}") - endif() + separate_arguments(_OpenMP_${LANG}_OPTIONS NATIVE_COMMAND "${OpenMP_${LANG}_FLAGS}") set_property(TARGET OpenMP::OpenMP_${LANG} PROPERTY INTERFACE_COMPILE_OPTIONS "${_OpenMP_${LANG}_OPTIONS}") unset(_OpenMP_${LANG}_OPTIONS) diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx index b27d227..7b222a0 100644 --- a/Source/cmSeparateArgumentsCommand.cxx +++ b/Source/cmSeparateArgumentsCommand.cxx @@ -40,6 +40,13 @@ bool cmSeparateArgumentsCommand::InitialPass( if (doing == DoingVariable) { var = args[i]; doing = DoingMode; + } else if (doing == DoingMode && args[i] == "NATIVE_COMMAND") { +#ifdef _WIN32 + mode = ModeWindows; +#else + mode = ModeUnix; +#endif + doing = DoingCommand; } else if (doing == DoingMode && args[i] == "UNIX_COMMAND") { mode = ModeUnix; doing = DoingCommand; diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt index 1cca35d..1619081 100644 --- a/Tests/CMakeTests/CMakeLists.txt +++ b/Tests/CMakeTests/CMakeLists.txt @@ -19,7 +19,6 @@ AddCMakeTest(GetFilenameComponentRealpath "") AddCMakeTest(Version "") AddCMakeTest(Message "") AddCMakeTest(File "") -AddCMakeTest(SeparateArguments "") AddCMakeTest(ImplicitLinkInfo "") AddCMakeTest(ModuleNotices "") AddCMakeTest(GetProperty "") diff --git a/Tests/CMakeTests/SeparateArgumentsTest.cmake.in b/Tests/CMakeTests/SeparateArgumentsTest.cmake.in deleted file mode 100644 index 48964b8..0000000 --- a/Tests/CMakeTests/SeparateArgumentsTest.cmake.in +++ /dev/null @@ -1,25 +0,0 @@ -set(old_out "a b c") -separate_arguments(old_out) -set(old_exp "a;b;;c") - -set(unix_cmd "a \"b c\" 'd e' \";\" \\ \\'\\\" '\\'' \"\\\"\"") -set(unix_exp "a;b c;d e;\;; '\";';\"") -separate_arguments(unix_out UNIX_COMMAND "${unix_cmd}") - -set(windows_cmd "a \"b c\" 'd e' \";\" \\ \"c:\\windows\\path\\\\\" \\\"") -set(windows_exp "a;b c;'d;e';\;;\\;c:\\windows\\path\\;\"") -separate_arguments(windows_out WINDOWS_COMMAND "${windows_cmd}") - -foreach(mode old unix windows) - if(NOT "${${mode}_out}" STREQUAL "${${mode}_exp}") - message(FATAL_ERROR "separate_arguments ${mode}-style failed. " - "Expected\n [${${mode}_exp}]\nbut got\n [${${mode}_out}]\n") - endif() -endforeach() - -set(nothing) -separate_arguments(nothing) -if(DEFINED nothing) - message(FATAL_ERROR "separate_arguments null-case failed: " - "nothing=[${nothing}]") -endif() diff --git a/Tests/FindOpenMP/Test/CMakeLists.txt b/Tests/FindOpenMP/Test/CMakeLists.txt index 4ba0e5c..6313ef6 100644 --- a/Tests/FindOpenMP/Test/CMakeLists.txt +++ b/Tests/FindOpenMP/Test/CMakeLists.txt @@ -39,11 +39,7 @@ foreach(c C CXX Fortran) add_test(NAME test_tgt_${c} COMMAND test_tgt_${c}) add_executable(test_var_${c} ${OpenMPTEST_SOURCE_FILE}) - if(CMAKE_HOST_WIN32) - separate_arguments(_OpenMP_${c}_OPTIONS WINDOWS_COMMAND "${OpenMP_${c}_FLAGS}") - else() - separate_arguments(_OpenMP_${c}_OPTIONS UNIX_COMMAND "${OpenMP_${c}_FLAGS}") - endif() + separate_arguments(_OpenMP_${c}_OPTIONS NATIVE_COMMAND "${OpenMP_${c}_FLAGS}") target_compile_options(test_var_${c} PRIVATE "${_OpenMP_${c}_OPTIONS}") target_link_libraries(test_var_${c} PRIVATE "${OpenMP_${c}_FLAGS}") set_property(TARGET test_var_${c} PROPERTY LINKER_LANGUAGE ${c}) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index cf778b6..75d4e29 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -217,6 +217,7 @@ add_RunCMake_test(list) add_RunCMake_test(message) add_RunCMake_test(project -DCMake_TEST_RESOURCES=${CMake_TEST_RESOURCES}) add_RunCMake_test(return) +add_RunCMake_test(separate_arguments) add_RunCMake_test(set_property) add_RunCMake_test(string) foreach(var diff --git a/Tests/RunCMake/separate_arguments/CMakeLists.txt b/Tests/RunCMake/separate_arguments/CMakeLists.txt new file mode 100644 index 0000000..2897109 --- /dev/null +++ b/Tests/RunCMake/separate_arguments/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/separate_arguments/EmptyCommand.cmake b/Tests/RunCMake/separate_arguments/EmptyCommand.cmake new file mode 100644 index 0000000..895b6ac --- /dev/null +++ b/Tests/RunCMake/separate_arguments/EmptyCommand.cmake @@ -0,0 +1,6 @@ +set(nothing) +separate_arguments(nothing) +if(DEFINED nothing) + message(FATAL_ERROR "separate_arguments null-case failed: " + "nothing=[${nothing}]") +endif() diff --git a/Tests/RunCMake/separate_arguments/NativeCommand.cmake b/Tests/RunCMake/separate_arguments/NativeCommand.cmake new file mode 100644 index 0000000..1cb009e --- /dev/null +++ b/Tests/RunCMake/separate_arguments/NativeCommand.cmake @@ -0,0 +1,19 @@ +set(unix_cmd "a \"b c\" 'd e' \";\" \\ \\'\\\" '\\'' \"\\\"\"") +set(unix_exp "a;b c;d e;\;; '\";';\"") + +set(windows_cmd "a \"b c\" 'd e' \";\" \\ \"c:\\windows\\path\\\\\" \\\"") +set(windows_exp "a;b c;'d;e';\;;\\;c:\\windows\\path\\;\"") + +if(CMAKE_HOST_WIN32) + set(native_cmd "${windows_cmd}") + set(native_exp "${windows_exp}") +else() + set(native_cmd "${unix_cmd}") + set(native_exp "${unix_exp}") +endif() +separate_arguments(native_out NATIVE_COMMAND "${native_cmd}") + +if(NOT "${native_out}" STREQUAL "${native_exp}") + message(FATAL_ERROR "separate_arguments native-style failed. " + "Expected\n [${native_exp}]\nbut got\n [${native_out}]\n") +endif() diff --git a/Tests/RunCMake/separate_arguments/PlainCommand.cmake b/Tests/RunCMake/separate_arguments/PlainCommand.cmake new file mode 100644 index 0000000..311a993 --- /dev/null +++ b/Tests/RunCMake/separate_arguments/PlainCommand.cmake @@ -0,0 +1,8 @@ +set(old_out "a b c") +separate_arguments(old_out) +set(old_exp "a;b;;c") + +if(NOT "${old_out}" STREQUAL "${old_exp}") + message(FATAL_ERROR "separate_arguments old-style failed. " + "Expected\n [${old_exp}]\nbut got\n [${old_out}]\n") +endif() diff --git a/Tests/RunCMake/separate_arguments/RunCMakeTest.cmake b/Tests/RunCMake/separate_arguments/RunCMakeTest.cmake new file mode 100644 index 0000000..07951bb --- /dev/null +++ b/Tests/RunCMake/separate_arguments/RunCMakeTest.cmake @@ -0,0 +1,7 @@ +include(RunCMake) + +run_cmake(EmptyCommand) +run_cmake(PlainCommand) +run_cmake(UnixCommand) +run_cmake(WindowsCommand) +run_cmake(NativeCommand) diff --git a/Tests/RunCMake/separate_arguments/UnixCommand.cmake b/Tests/RunCMake/separate_arguments/UnixCommand.cmake new file mode 100644 index 0000000..0b5767a --- /dev/null +++ b/Tests/RunCMake/separate_arguments/UnixCommand.cmake @@ -0,0 +1,8 @@ +set(unix_cmd "a \"b c\" 'd e' \";\" \\ \\'\\\" '\\'' \"\\\"\"") +set(unix_exp "a;b c;d e;\;; '\";';\"") +separate_arguments(unix_out UNIX_COMMAND "${unix_cmd}") + +if(NOT "${unix_out}" STREQUAL "${unix_exp}") + message(FATAL_ERROR "separate_arguments unix-style failed. " + "Expected\n [${unix_exp}]\nbut got\n [${unix_out}]\n") +endif() diff --git a/Tests/RunCMake/separate_arguments/WindowsCommand.cmake b/Tests/RunCMake/separate_arguments/WindowsCommand.cmake new file mode 100644 index 0000000..86aa14a --- /dev/null +++ b/Tests/RunCMake/separate_arguments/WindowsCommand.cmake @@ -0,0 +1,8 @@ +set(windows_cmd "a \"b c\" 'd e' \";\" \\ \"c:\\windows\\path\\\\\" \\\"") +set(windows_exp "a;b c;'d;e';\;;\\;c:\\windows\\path\\;\"") +separate_arguments(windows_out WINDOWS_COMMAND "${windows_cmd}") + +if(NOT "${windows_out}" STREQUAL "${windows_exp}") + message(FATAL_ERROR "separate_arguments windows-style failed. " + "Expected\n [${windows_exp}]\nbut got\n [${windows_out}]\n") +endif() |