Re: [CMake] Please update the documentation for execute_process
Am 25.08.2017 um 16:12 schrieb Jeffrey Walton: Below is a typical case for us (https://github.com/weidai11/cryptopp/blob/master/CMakeLists.txt). If it looks pretty shitty, it probably is. That's the best we have been able to come up with based on the documentation. Below is the example code. We don't know whether it should be: set(SHELL_CMD sh) set(SHELL_ARGS -c) set(GREP_CMD egrep) set(GREP_ARGS -i -c) execute_process(COMMAND ${SHELL_CMD} ${SHELL_ARGS} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} ${GREP_ARGS} "amd64" OUTPUT_VARIABLE CRYPTOPP_AMD64 OUTPUT_STRIP_TRAILING_WHITESPACE) Or: COMMAND "${SHELL_CMD}", "${CMAKE_CXX_COMPILER}", "-dumpmachine", "2>&1" Or: COMMAND "${SHELL_CMD}" "${CMAKE_CXX_COMPILER}" "-dumpmachine" "2>&1" Or: set(SHELL_CMD sh) set(GREP_CMD egrep) execute_process(COMMAND ${SHELL_CMD} "-c" "${CMAKE_CXX_COMPILER} "-dumpmachine" "2>&1" COMMAND ${GREP_CMD} ${GREP_ARGS} "-i" "-c" "amd64" OUTPUT_VARIABLE CRYPTOPP_AMD64 OUTPUT_STRIP_TRAILING_WHITESPACE) And we certainly don't know what to do with "2>&1" because there is no example. The documentation states "If OUTPUT_VARIABLE or ERROR_VARIABLE are given the variable named will be set with the contents of the standard output and standard error pipes respectively. If the same variable is named for both pipes their output will be merged in the order produced so I would suspect to use something like execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE output_dump ERROR_VARIABLE output_dump) and then use a if( output_dump MATCHES "amd64" ) .. endif() block Does that work? Jeff ** set(SHELL_CMD sh -c) set(GREP_CMD egrep -i -c) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "amd64" OUTPUT_VARIABLE CRYPTOPP_AMD64 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "x86_64" OUTPUT_VARIABLE CRYPTOPP_X86_64 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "i.86" OUTPUT_VARIABLE CRYPTOPP_I386 OUTPUT_STRIP_TRAILING_WHITESPACE) # http://github.com/weidai11/cryptopp/issues/466 execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "mingw32" OUTPUT_VARIABLE CRYPTOPP_MINGW32 OUTPUT_STRIP_TRAILING_WHITESPACE) # http://github.com/weidai11/cryptopp/issues/466 execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "w64-mingw32" OUTPUT_VARIABLE CRYPTOPP_MINGW64 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "x32" OUTPUT_VARIABLE CRYPTOPP_X32 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "Aarch32" OUTPUT_VARIABLE CRYPTOPP_AARCH32 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "Aarch64" OUTPUT_VARIABLE CRYPTOPP_AARCH64 OUTPUT_STRIP_TRAILING_WHITESPACE) # http://stackoverflow.com/q/12515462/608639 execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "\\" OUTPUT_VARIABLE CRYPTOPP_ARM OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "ARMHF" OUTPUT_VARIABLE CRYPTOPP_ARMHF OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "ARM7L" OUTPUT_VARIABLE CRYPTOPP_ARM7L OUTPUT_STRIP_TRAILING_WHITESPACE) # Fixup? if ("${CRYPTOPP_MINGW64}" STREQUAL "1") unset(CRYPTOPP_MINGW32) endif() # MinGW32 if ("${CRYPTOPP_MINGW32}" STREQUAL "1") set(CRYPTOPP_I386 "1") endif() # OpenBSD and MinGW64 if ("${CRYPTOPP_X86_64}" STREQUAL "1" OR "${CRYPTOPP_MINGW64}" STREQUAL "1") set(CRYPTOPP_AMD64 "1") endif() # arm7l is another 32-bit hard float machine. RPI-3 is arm7l on 64-bit hardware if ("${CRYPTOPP_ARM}" STREQUAL "1" OR "${CRYPTOPP_ARM7L}" STREQUAL "1") set(CRYPTOPP_ARMHF "1") endif() -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Please update the documentation for execute_process
> Below is a typical case for us > (https://github.com/weidai11/cryptopp/blob/master/CMakeLists.txt). If > it looks pretty shitty, it probably is. That's the best we have been > able to come up with based on the documentation. Below is the example code. We don't know whether it should be: set(SHELL_CMD sh) set(SHELL_ARGS -c) set(GREP_CMD egrep) set(GREP_ARGS -i -c) execute_process(COMMAND ${SHELL_CMD} ${SHELL_ARGS} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} ${GREP_ARGS} "amd64" OUTPUT_VARIABLE CRYPTOPP_AMD64 OUTPUT_STRIP_TRAILING_WHITESPACE) Or: COMMAND "${SHELL_CMD}", "${CMAKE_CXX_COMPILER}", "-dumpmachine", "2>&1" Or: COMMAND "${SHELL_CMD}" "${CMAKE_CXX_COMPILER}" "-dumpmachine" "2>&1" Or: set(SHELL_CMD sh) set(GREP_CMD egrep) execute_process(COMMAND ${SHELL_CMD} "-c" "${CMAKE_CXX_COMPILER} "-dumpmachine" "2>&1" COMMAND ${GREP_CMD} ${GREP_ARGS} "-i" "-c" "amd64" OUTPUT_VARIABLE CRYPTOPP_AMD64 OUTPUT_STRIP_TRAILING_WHITESPACE) And we certainly don't know what to do with "2>&1" because there is no example. Jeff ** set(SHELL_CMD sh -c) set(GREP_CMD egrep -i -c) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "amd64" OUTPUT_VARIABLE CRYPTOPP_AMD64 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "x86_64" OUTPUT_VARIABLE CRYPTOPP_X86_64 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "i.86" OUTPUT_VARIABLE CRYPTOPP_I386 OUTPUT_STRIP_TRAILING_WHITESPACE) # http://github.com/weidai11/cryptopp/issues/466 execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "mingw32" OUTPUT_VARIABLE CRYPTOPP_MINGW32 OUTPUT_STRIP_TRAILING_WHITESPACE) # http://github.com/weidai11/cryptopp/issues/466 execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "w64-mingw32" OUTPUT_VARIABLE CRYPTOPP_MINGW64 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "x32" OUTPUT_VARIABLE CRYPTOPP_X32 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "Aarch32" OUTPUT_VARIABLE CRYPTOPP_AARCH32 OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "Aarch64" OUTPUT_VARIABLE CRYPTOPP_AARCH64 OUTPUT_STRIP_TRAILING_WHITESPACE) # http://stackoverflow.com/q/12515462/608639 execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "\\" OUTPUT_VARIABLE CRYPTOPP_ARM OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "ARMHF" OUTPUT_VARIABLE CRYPTOPP_ARMHF OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "ARM7L" OUTPUT_VARIABLE CRYPTOPP_ARM7L OUTPUT_STRIP_TRAILING_WHITESPACE) # Fixup? if ("${CRYPTOPP_MINGW64}" STREQUAL "1") unset(CRYPTOPP_MINGW32) endif() # MinGW32 if ("${CRYPTOPP_MINGW32}" STREQUAL "1") set(CRYPTOPP_I386 "1") endif() # OpenBSD and MinGW64 if ("${CRYPTOPP_X86_64}" STREQUAL "1" OR "${CRYPTOPP_MINGW64}" STREQUAL "1") set(CRYPTOPP_AMD64 "1") endif() # arm7l is another 32-bit hard float machine. RPI-3 is arm7l on 64-bit hardware if ("${CRYPTOPP_ARM}" STREQUAL "1" OR "${CRYPTOPP_ARM7L}" STREQUAL "1") set(CRYPTOPP_ARMHF "1") endif() -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
[CMake] Please update the documentation for execute_process
The documentation for execute_process has some room for improvement. We recently got burned by a problem that has existed since at least 2011: https://stackoverflow.com/q/6797395/608639 . Once we learned the problem we could research a bit. The problem cost us over 8 man hours when it should not have been a problem in the first place. Considering there's nothing special about us, it has probably wasted thousands of man hours over the years. Here are the actionable items for the execute_process documentation task: * please clearly state the first argument is the command only, and not command + arguments * please clearly state whether arguments need to be quoted * please clearly state whether arguments need to be comma separated * please provide an example (or examples) to show how to specify multiple arguments for a command * please provide an example (or examples) to show how to redirect output when using a command Below is a typical case for us (https://github.com/weidai11/cryptopp/blob/master/CMakeLists.txt). If it looks pretty shitty, it probably is. That's the best we have been able to come up with based on the documentation. ** -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake