Issues with automatic VS environment setup via vcvarsall.bat

オープン
#55 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cmake

調査の方向性

vcvarsall.bat を実行し、その環境を CMake に引き渡すテンプレートロジックを見つけてください。バックスラッシュで終わる環境値を使って Windows で報告を再現し、その後 Ninja ジェネレーターで構成してビルドを試みてください。環境値がそのまま維持され、構成済みのビルドが vcvarsall.bat を再実行せずに MSVC コンパイラーとリンカーを見つけられれば完了です。

索引モデルが issue の本文から書いたものです。

説明

I believe there are some issues with the way this template attempts to automatically run vcvarsall.bat when compiling with MSVC on Windows.

First Issue: Trailing slashes in environment variables

The first issue is related to how CMake handles lists. After executing vcvarsall.bat, your cmake script copies the environment to string, makes some replacements, and then copies the environment to the current cmake environment. This works fine until an environment value has a trailing backslash at the end of its value (e.g JAVA_HOME).

When this happens, you end up with a list in CMake that looks something like this:

...;JAVA_HOME=C:\Path\To\Java\;LIB=list__sep__of__sep__lib__sep__paths

Because of the trailing backslash, when cmake iterates through the list, it tries to set the JAVA_HOME environment to C:\Path\To\Java;LIB=list;of;lib;paths. The only way I've found to work around this behavior is to also replace all slashes in the environment output with slash and restore them before setting the environment variable.

Second Issue: The VS Environment is lost after the configure step

Running cmake to configure the project works, since the script sets up the VS environment automatically (assuming you don't lose the LIB environment variable due to the previous issue like I did). The problem is the environment is lost again after the configure step, so trying to build will fail indicating it can't find the necessary compiler/link executable. This occurred while using the Ninja generator. I don't know if this occurs with the MSVC generator.

The only way to fix this is to manually run vcvarsall.bat again before executing the build step. I haven't figured out a way to avoid this problem.

At least that was my experience.

主要言語
CMake
スター
1.8k
フォーク
205
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cpp-best-practices/cmake_template のほかの issue

cpp-best-practices/cmake_template の issue をすべて見る

似ている issue

Build System の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。