From 5e8801ba3c873943015ad8779007d8fc6b5a37f9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 12 Jul 2022 02:01:38 -0700 Subject: [PATCH 1/6] fix: redirect the vcvarsall output into NUL --- src/VCEnvironment.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index aea0b7d4..33dc3d25 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -115,7 +115,7 @@ macro(run_vcvarsall) message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment") execute_process( COMMAND - "cmd" "/c" ${VCVARSALL_FILE} ${VCVARSALL_ARCH} # + "cmd" "/c" "${VCVARSALL_FILE}" "${VCVARSALL_ARCH}" "1>NUL" # "&&" "call" "echo" "VCVARSALL_ENV_START" # "&" "set" # OUTPUT_VARIABLE VCVARSALL_OUTPUT From 2e9cdae2b40f6c0db3f477257a1b1c1f999b9f64 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 12 Jul 2022 02:01:58 -0700 Subject: [PATCH 2/6] fix: ignore the vcvarsall output if there is any error --- src/VCEnvironment.cmake | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index 33dc3d25..0c8c6e84 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -119,13 +119,20 @@ macro(run_vcvarsall) "&&" "call" "echo" "VCVARSALL_ENV_START" # "&" "set" # OUTPUT_VARIABLE VCVARSALL_OUTPUT + ERROR_VARIABLE VCVARSALL_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE) - # parse the output and get the environment variables string - find_substring_by_prefix(VCVARSALL_ENV "VCVARSALL_ENV_START" "${VCVARSALL_OUTPUT}") + if("${VCVARSALL_ERROR}" STREQUAL "") + # parse the output and get the environment variables string + find_substring_by_prefix(VCVARSALL_ENV "VCVARSALL_ENV_START" "${VCVARSALL_OUTPUT}") + + # set the environment variables + set_env_from_string("${VCVARSALL_ENV}") + else() + message(WARNING "Failed to parse the vcvarsall output. ${VCVARSALL_ERROR}.\nIgnoring this error") + + endif() - # set the environment variables - set_env_from_string("${VCVARSALL_ENV}") else() message( WARNING From fbaa466dfab9cf06fffa3fdddbe7da4af8033817 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 12 Jul 2022 03:09:43 -0700 Subject: [PATCH 3/6] fix: make vcvarsall quiet --- src/VCEnvironment.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index 0c8c6e84..e5559296 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -115,12 +115,13 @@ macro(run_vcvarsall) message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment") execute_process( COMMAND + "set" "VSCMD_DEBUG=0" "&&" # make vcvarsall quiet "cmd" "/c" "${VCVARSALL_FILE}" "${VCVARSALL_ARCH}" "1>NUL" # - "&&" "call" "echo" "VCVARSALL_ENV_START" # - "&" "set" # + "&&" "call" "echo" "VCVARSALL_ENV_START" # a starting point + "&" "set" # print the environment variables OUTPUT_VARIABLE VCVARSALL_OUTPUT ERROR_VARIABLE VCVARSALL_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE) + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE) if("${VCVARSALL_ERROR}" STREQUAL "") # parse the output and get the environment variables string From 169e0dbf1fb9249678ad9a5b829d88031bb2e7cd Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 12 Jul 2022 03:10:02 -0700 Subject: [PATCH 4/6] fix: only run vcvarsall if VSCMD_VER is not defined --- src/VCEnvironment.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index e5559296..d44328df 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -96,7 +96,7 @@ macro(run_vcvarsall) # if msvc_found is set by msvc_toolchain # or if MSVC but VSCMD_VER is not set, which means vcvarsall has not run - if(MSVC_FOUND OR (MSVC AND "$ENV{VSCMD_VER}" STREQUAL "")) + if((MSVC_FOUND OR MSVC) AND "$ENV{VSCMD_VER}" STREQUAL "") # find vcvarsall.bat get_filename_component(MSVC_DIR ${CMAKE_CXX_COMPILER} DIRECTORY) From 8b03a8c0203865fa0559e6b1f2844e93393b602e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 12 Jul 2022 03:21:15 -0700 Subject: [PATCH 5/6] fix: set VSCMD_DEBUG using cmake --- src/VCEnvironment.cmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index d44328df..9d0efa91 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -113,9 +113,13 @@ macro(run_vcvarsall) if(EXISTS ${VCVARSALL_FILE}) # run vcvarsall and print the environment variables message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment") + + # make vcvarsall quiet + set(VSCMD_DEBUG "$ENV{VSCMD_DEBUG}") + set($ENV{VSCMD_DEBUG} 0) + execute_process( COMMAND - "set" "VSCMD_DEBUG=0" "&&" # make vcvarsall quiet "cmd" "/c" "${VCVARSALL_FILE}" "${VCVARSALL_ARCH}" "1>NUL" # "&&" "call" "echo" "VCVARSALL_ENV_START" # a starting point "&" "set" # print the environment variables @@ -123,7 +127,9 @@ macro(run_vcvarsall) ERROR_VARIABLE VCVARSALL_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE) - if("${VCVARSALL_ERROR}" STREQUAL "") + # recover VSCMD_DEBUG variable + set($ENV{VSCMD_DEBUG} "${VSCMD_DEBUG}") + # parse the output and get the environment variables string find_substring_by_prefix(VCVARSALL_ENV "VCVARSALL_ENV_START" "${VCVARSALL_OUTPUT}") From 4c70e28c9d786fcdad32c5a377c55d12bae17575 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 12 Jul 2022 03:21:29 -0700 Subject: [PATCH 6/6] fix: check if VCVARSALL_OUTPUT is not empty before using it --- src/VCEnvironment.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index 9d0efa91..52bf13b6 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -130,6 +130,11 @@ macro(run_vcvarsall) # recover VSCMD_DEBUG variable set($ENV{VSCMD_DEBUG} "${VSCMD_DEBUG}") + if("${VCVARSALL_ERROR}" STREQUAL "" + AND NOT + "${VCVARSALL_OUTPUT}" + STREQUAL + "") # parse the output and get the environment variables string find_substring_by_prefix(VCVARSALL_ENV "VCVARSALL_ENV_START" "${VCVARSALL_OUTPUT}")