cpp-best-practices / cpp-best-practices/cmake_template

Issues with automatic VS environment setup via vcvarsall.bat

Aperta
#55 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
CMake
Stelle
1.8k
Fork
204
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Individua la logica dei template che esegue vcvarsall.bat e trasferisce il relativo ambiente in CMake. Riproduci il report su Windows con un valore dell'ambiente che termina con una barra rovesciata, quindi configura con il generatore Ninja e prova a eseguire una compilazione. Il lavoro è completato quando i valori dell'ambiente rimangono intatti e la compilazione configurata riesce a trovare il compilatore e il linker MSVC senza eseguire nuovamente vcvarsall.bat.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cmake
Ambito
build-system, operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.