Skip to content

Commit

Permalink
Merge pull request #136 from aminya/vcvarsall-output [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Jul 13, 2022
2 parents 2b75259 + 4c70e28 commit aa62a17
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/VCEnvironment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -113,19 +113,38 @@ 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
"cmd" "/c" ${VCVARSALL_FILE} ${VCVARSALL_ARCH} #
"&&" "call" "echo" "VCVARSALL_ENV_START" #
"&" "set" #
"cmd" "/c" "${VCVARSALL_FILE}" "${VCVARSALL_ARCH}" "1>NUL" #
"&&" "call" "echo" "VCVARSALL_ENV_START" # a starting point
"&" "set" # print the environment variables
OUTPUT_VARIABLE VCVARSALL_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
ERROR_VARIABLE VCVARSALL_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)

# 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}")

# set the environment variables
set_env_from_string("${VCVARSALL_ENV}")
else()
message(WARNING "Failed to parse the vcvarsall output. ${VCVARSALL_ERROR}.\nIgnoring this error")

# parse the output and get the environment variables string
find_substring_by_prefix(VCVARSALL_ENV "VCVARSALL_ENV_START" "${VCVARSALL_OUTPUT}")
endif()

# set the environment variables
set_env_from_string("${VCVARSALL_ENV}")
else()
message(
WARNING
Expand Down

0 comments on commit aa62a17

Please sign in to comment.