I'm trying to integrate a legacy borland turbo c++ project into jenkins task and I need to be able to compile the project from command line.
Is there any way to get the compiler CLI information from the project so that I could make a batch file that compiles it?
SO: Windows 7
You can get the commands being invoked by C++ Builder by exporting a makefile for the project.
Under menu goto Project->Export a Makefile.
Once exported open a cmd.exe shell to the generated makefile's location.
Run the makefile with borland's make.exe tool:
make -B -K -n -f"projectMakefileGoesHere"
-B will traverse all the dependencies ignoring age.
-K will keep any temp response files used during the build.
-n do a dry-run printing the commands that would've been called in an actual build.
The link commands will be in the MAKE0xxx.### response file where "x" is a number assigned by make.
For later versions of C++ Builder, the .cbproj project is actually a msbuild project file. You can use msbuild to print the build commands used for the project. eg.
msbuild "project.cbproj" -p:Configuration=Debug -clp:ShowCommandLine -v:n
Unfortunately, msbuild doesn't have a dry-run option so it'll end up building the project. Another idea is to create a simple logging program that replaces bcc32.exe compiler and ilink32.exe linker. With this, you can see exactly what options and switches are being passed to the tools.
Related
I am currently trying to set up an "automatic build process" on mac for my C++ "Hello World Project" that uses Cmake & visual studio code.
My current workflow to build in terminal or with vscode's tasks.json is the following, and I find them very tedious to do.
cmake ... (to generate the cmake & make files inside the build folder)
make (inside the build folder to create the application's executable)
./{application's executable}
Thus, I have have looked into the following
vs code's prelaunch task
cmake's add_custom_commands
custom bash script
python scripts
But I'm a bit lost with the above try-outs, and need some helps. My end goal is to automatically build and run the updated code by either pressing F5 in vscode or calling a custom ./{command} in terminal.
Combining everyone's suggestions, the approach I took is to create a task.json that contains the following command-flow
cmd1: cmake to generate the makefiles & cmake files to a build folder
cmd2: make -j 8 to build with multiple cores
cmd1 && cmd2
Then I made two different launches in launch.json. The major difference between them is the prelauch task. One of them is "cmd1&&cmd2", and another one is only "cmd2". That way I can have two hotkeys like F5 and F7 for me to choose. If the folder structure & files weren't added or removed I will hit F7 which only calls the "cmd2" pre-launch task, otherwise F5.
I think a better approach is to either write a bash script or dig deeper in cmakelist.txt which I believe it has the "if statements" that determine when should it do "cmd1 &&cmd2" or just "cmd2" alone. That way, I don't need two hotkeys to build/debug and run in vscode (don't know if it is possible, I haven't try yet.)
If anyone has done it, please comment below or create a new answer.
Thank you all!
You can run
cmake --build
after the first time you configured the build. Optional parameters include the build directory and targets to build.
I have an Eclipse project that builds a library, with my own build script (that basically sets some variables, then calls a Makefile). I have set the Build Configuration to run this script, everything is OK: I can compile by just clicking on the Build button.
Now, I would like to test some parts of this lib. In the same project, I have created a C++ source file, with a little main(). I would like to create a run configuration to execute this small test program, but Eclipse tells me that "the binary does not exist" (of course, since I want to build it...).
What is the solution ?
I'm using CMake into build rules in visual studio to preprocess my files before submitting them to the compiler but my customers don't like it.
Is there any CMake alternative or method to preprocess my files and having them integrated into visual studio?
As I understand the question you are using CMake to generate files consumed by a VS project that you created by hand. For whatever reason your customers of your VS project don't like CMake. Presumably you have wired this up by creating custom build steps that invoke CMake to generate the files in your project, either as Build Events on the project, or as custom build steps on various files in the project, such as the inputs to the scripts.
VS lets you run any arbitrary set of commands as part of a Build Event or a Custom Build Step. So you could replace CMake with a suitable script or custom executable written by yourself. It is hard to be specific without knowing exactly what about CMake isn't appealing to your customers.
You can use JavaScript through Windows Script Host to create fairly complex scripts that process custom build steps. They can take command-line arguments, access the file system, etc. For some reason WSH JavaScript is a big secret among most developers and they think that all they have available to them in Windows out-of-the-box are DOS batch files and power shell scripts. JavaScript has been shipping for over 10 years as part of the OS and you can debug the scripts in Visual Studio's script debugger, which is very nice.
I'm using git as version control and I'm trying to hook the SHA1 of the current commit into a visual studio build as a define.
So basically I want to turn the output of the command
git rev-parse HEAD
into a define that I can embed in the output binary.
Thanks in advance.
Frankly, I prefer a pre-build events in Visual Studio over Git post-commit. There is additional benefit of knowing if you building from a dirty repository or not. Did the write-up on that today. Here are the general steps from build to execution:
The build process has a pre-build script, which gathers version and repository status information. In our case, VC++ uses the Windows PowerShell version_info.ps1 script.
The pre-build script generates a source code file, which is expected by the rest of the codebase. The generated file has everything needed to allow or deny running the version. In our case it is a C++ header file version.h.
A code contains function which checks if the build is legitimate to run, and logs and stops the process as needed. That example code is in the versionLogAndVet function of the version.cpp example file.
At run time, the versionLogAndVet function allows to run only permitted combinations of repository status / build configuration. It also logs version information.
The specifics and code examples are at the full post.
Using a post-commit githook, you can put it into a file. I think git on windows comes with a bourne shell, so the following would work in a post-commit hook.
#!/bin/sh
GIT_SHA_INCLUDE_FILE=foo.h
echo -n '#define GIT_SHA ' > $GIT_SHA_INCLUDE_FILE
git rev-parse HEAD >> $GIT_SHA_INCLUDE_FILE
And save that as .git/hooks/post-commit
The file should remain untracked since it's (nearly) impossible to include the hash of the commit within the commit itself.
In my scenario I have a C++ project in CDT Eclipse. This projects however is rather a collection of individual (helper) programs than one complex application. Consequently I want to be able to build and run them individually.
My project structure is very simple and looks like:
src/app1.cpp
src/app2.cpp
src/...
Note that I do not have common header files or libraries. However I want to be able to add programs to this project just by creating e.g. src/appx.cpp
Ideally I want to have shortcuts for
"Build currently opened .cpp"
"Run binary of currently opened .cpp"
Any suggestions on how to achieve this behaviour, if possible without additional plugins?
The straightforward way to succeed what you aim is to create a Makefile project with CDT and add a new target rule for each of your applications inside your Makefile. You can even use SCons or other build systems with a CDT Makefile project and obtain the same effect.
You can also trick the managed build to create executables instead of object files. Remove -c option from Other flags of C++ compiler settings inside project properties. This will produce a separate application file for each of your source files.
Application files which are created inside the build directory will have the object file extension and they will not be executable. To solve this, you can add a post build script in your project directory such as:
postbuild.sh for Linux:
chmod +x *.o
rename -v 's/\.o$//' *.o
or postbuild.bat for Windows:
rename *.o *.exe
After adding ../postbuild.sh or ../postbuild.bat as a post build command in your build settings, you applications will be ready to run. Right click on any of these executable files and choose Debug As or Run As and a new Run configuration will be created.
Also you will have to stop the linker of the managed build to prevent errors. This can be achieved with changing the linker command to true (Linux) or true.exe (Windows, msys).