-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide way to pass env-vars from bat-file to cmake process (for nmake) #91
Comments
Calling vcvars32.bat from Eclipse won't help, a sub-process cannot set environment variables for its parent process (Eclipse in this case). |
One possible solution could be to call cmake in a sub-shell, and run vcvars32.bat in the same shell before. |
Shouldn't 3. work if the commands were not passed to the shell in one string but split? |
Splitting the string at whitespaces? Then nobody will be able to add a path to cmake with white spaces, e.g |
Using a tokenizer should work, but that would mean "just" putting in a path with whitespaces wouldn't work anymore, they would have to be surrounded by quotation marks. (java.io.StreamTokenizer should work, I think) |
The path-to-cmake should just hold what its label suggests, adding some token parsing would just confuse useres. But I could think of an extra option 'run with environment script' which could allow to run a single batch file in the same shell prior to cmake. |
What is your experience with your wrapper script that calls If that does not cause any issues, I could implement the solution proposed in #91 (comment). |
I understand the question to be:
I will test that as soon as possible and let you know the results. My hope would be that all necessary information from the vcvars finds its way in the Makefile, but that needs to be tested for sure. |
No, even simpler: With your wrapper script in place,
The second build should trigger some makefile rules that invoke cmake from nmake in order to re-generate the makefiles (at least, this is the case with unix makefiles). The cmake process in this case is run without your wrapper script and does not have the environment vars that come from |
OK that is simpler, I will try that. |
No it does not work. I tested this by explicitly setting an environment variable in the wrapper script and reading it in the CMakeLists.txt. The first run picks up the variable, the second one does not. |
Of course it will not work if you explicitly require a new env-var. But that is a different use case. |
Next test, I did:
The issue, I think, is that what is not working is the compiler test - it tries to link against libs from the Windows SDK when trying to compile its "simple program", and only afterwards sets the necessary variables to do what the build takes. I think my environment variable test shows that the build can't be depending on the environment variables, somewhere cmake is setting the include paths. Another test I did was setting the INCLUDE and LIB environment variables to the necessary directories for the Windows SDK - the build without the wrapper script worked fine. So somewhere CMake is keeping the IncludeDirectories and Libpath directories, the rest of the environment doesn't seem to matter. I do not know where it is that this information is kept. |
By the way, when I change the cmake command, it does not force a cmake rerun, I think that is probably a bug. |
I think I fixed my problem, but it is debatable how nice it is. I call the script and read out the environment variables it sets. For INCLUDE:
And then the same for LIB. I put this all in a find_package script and then use it like any other library. Not really nice, but better than a wrapper script in my opinion. |
Reply to #91 (comment)
Fine! This is the prerequisite of the fix of this issue..
Step 5 is the same as the initial case with freshly checked out sources and no build directory. BTW, cmake stores the path to the compiler and linker in CMakeCache.txt and the header and library search path in the generated makefiles. |
Reply to #91 (comment): With the proposed fix, you won't need that kind of CMakeLists.txt massaging. |
Could you please try staged version 1.12.3 |
It does not work, and I think it is because of the command line you generate:
I think this creates a CMD subprocess and then a cmake subprocess, when what you wanted to achieve was the cmake subprocess INSIDE the cmd subprocess. What I think it should look like (enclosing double quotation marks):
|
Staged a new version that put everything after the Please test! |
I think you don't need to escape the quotes inside, it looks for the first and last quotes automatically, I think. See https://ss64.com/nt/cmd.html
|
My plugin does not do the quote-escaping, it just passes the arguments Anyway, I'll give it a last blind try. Staged a new version. |
OK, I'll test and if it doesn't work I can see if I can make time to work on it. Which branch is it in? |
It is not checked in currently. |
OK will do. I assume I can somehow trick it with single quotes. |
This works for me:
|
Tested the last staged version, didn't work, with similar error message as before. |
I don't know what your vcvars32.bat do, but I set up my environment before starting eclipse. Would it be possible for you as well to setup your environment before starting eclipse? |
@asterkrans Of course that works, but is not really convenient for my users. Unless there is a way to provide a wrapper script with the product? |
Could someone please test staged cmake4eclipse-1.12.3-SNAPSHOT.zip at https://drive.google.com/drive/folders/0B-QU1Qnto3huZUZ0QUdxM01pR0U on windows so we can proceed here? |
Testing the issue91 branch right now, this still have problems with the escaping or something, since I now have the code in my IDE, I'll see if I can fix it.
|
WTF the command line looks exactly like in my example, yet it still doesn't work?! |
I dug into the code until I ended up at the native portion. This is what cdt does with the command array that we pass to the command launcher:
And the copyTo method:
I don't understand why they don't just use the JRE methods for that and need an own implementation... I think no matter what we do here, the quotation marks will be quoted, when we need them unquoted. |
I am trying now to get something to work with |
I tried with this command line but still cmake complains about missing quotations at the Nmake Generator
|
Okay, so ACTUALLY the commandline is prepended with starter.exe which is this code: https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/tree/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp And here I don't know what is going on, why that code is needed. Do you have any contacts to cdt guys? I think some input on how to tackle this issue would be nice. I don't understand why normally the Quoting works as expected, but as soon as we mess with the command line something breaks. |
Maybe this can help: "EnableDelayedExpansion is Disabled by default. I have not fully understood the issue here, but this was the solution once when I had similar problems. |
Sorry, I guess Delayed Expansion that I mentioned above only affects variable expansion. |
should at least work with Runtime.exec().
Two things I note here:
So the question is how to get the command args in cmake4eclipse right in order to pass quoted args down through starter.exe and cmd.exe to cmake.exe. To get an answer, you could try to
Then pray to figure out a working counter-quoting algorithm to make commands args to pass properly through ICommandLauncher.execute(args), launcher.exe, cmd.exe to cmake.exe. |
@asterkrans %sstarter.exe? You mix printf(1) format specifiers with cmd.exe environment variable specifiers here. |
@kutschkem Maybe it is sufficient to just add the file system location of the VS compilers and linkers to %PATH% when cmake is invoked instead of running Could you give that a try and report back? |
I have manually edited the environment variables before, and in my case needed to adapt INCLUDE and LIB (the necessary programs I had already added to PATH) |
Ah, OK. Looking at the code of starter.cpp, it seems to escape double quotes by a backslash, which is not something cmd.exe undestands (If i read the docs correctly). So the only option would be to write the commands to a batch file and let cmd.exe execute that. |
@kutschkem Could you try with the latest commits on the issue91 branch? It uses a batch file. |
Bump @kutschkem: Could you please test? I would like to incorporate the fix among others into the next release. |
I tested this again, You generate:
The
That works but I have not tested what happens when the script fails with an error code. |
Thank you for testing. |
The issue I had was that the exit was happening although the script returned an errorlevel 0 |
Could you test the new commit?
The script
If the generated script does not, it's up to a person with a windows machine (you) to fix that since I have linux. |
Findings:
|
Did you make VsDevCmd.bat fail or did you specify a non-existing path to the VsDevCmd.bat? If %errorlevel% indicates a failure, you should see a message like |
I tested the "failing script" with a script that just read |
This is a...
Brief Description
For my nmake to work, I had to make sure to call vcvars32.bat before cmake. However I found no way to do this other than writing a wrapper batch script around cmake.
(If Bug Report) Brief Summary
What I tried:
In the end I wrote a batch script that called vcvars32 and then passed the arguments to cmake, and used that as cmake executable.
What is the expected behavior?
One of the methods above should have allowed to call the script before cmake is executed to populate environment variables - or another method should exist that allows this.
What behavior are you observing?
cmake seems to be the first thing to be called in the build and no way exists to define a "pre-cmake" step.
Provide the steps to reproduce the issue, if applicable:
(If Enhancement Request) Describe it.
Add a "pre-cmake" step.
Useful Information
cmake4eclipse verssion: 1.10.3
Which OS do you use: Windows 7
Cmake version: 3.10.0
The text was updated successfully, but these errors were encountered: