How can I get all the compile commands from Xcode? - xcode

I am working on OCLint, and OCLint need all the compile command to do the lint job. now OCLint using xcpretty to parse xcodebuild.log to get the compile commands. So, I have to build the project even I only want to lint few source files. I wonder is there anyway to get the compile commands other than parse the xcodebuild.log?

One way of doing it is to write a wrapper for clang and linkers.
Using this answer: How can I force Xcode to use a custom compiler? you can redirect Xcode to compile your code with your own "clang" which might be a python shell script. This script would just grab a command passed to it and dump it to some file.
One detail though: if you use custom CC Xcode will also try to use it for linking C/C++ files this is why your script has to do nothing if it is called in a linker mode.
I have used this technique for another task: compiling my whole project with -emit-llvm flag to get all my code as LLVM bitcode. The example of a similar Python script can be found here.
Start by writing "hello world" script. Tell Xcode use it as CC, run your project and see the "hello world" string in your build log. From there you will know how to proceed.

I just use the -dry-run and regexpr to filter the compile commands. The -dry-run said,
-dry-run do everything except actually running the commands
The performance is just ok.
And it will be great if xcode provide one. They will be the only who can do this, and I think it is pretty usefull.

Related

How to generate dsym files near the executable, not outside the bundle, preferably without a post install script?

I'm using LLVM Clang with Xcode and address sanitiser is not creating file:line report. I read the documentation and it says to run dsymutil on the binary before launching the app.
http://clang.llvm.org/docs/AddressSanitizer.html#symbolizing-the-reports
I can achieve that by adding a run script build phase but it is clunky. To do the same with unix-makefiles I figured an install(SCRIPT <script.cmake>) would be better.
Is there a way to avoid all this and have Xcode run dsymutil as part of the build process, probably by a build setting that I don't know about ?
I've tried setting debugging information format to dwarf with dsym, but llvm-symbolizer doesn't use it. I guess that the difference is that dsymutil creates the .dsym file near the executable, inside the bundle :MyExec.dsym. While Xcode creates it outside the bundle: MyExec.app.dsym.
In your Build Settings in Xcode, change the debug format from "DWARF" to "DWARF with dSYM".

Compiling and embedding lua into a C++ application

For portability reasons, I'd like to compile lua from source when I compile my C++ code. I use lua to read input file.
If I understand correctly, lua's readme mentions that it's possible to do that through src/Makefile. I can't really read it that well. Has anyone figured out how to do it?
is it possible to have it in one command? gcc ....
bonus: how to put it in cmake ?
Lua has a makefile that needs your target platform to build to so you will need to specify make [target platform].
But that is right in the beginning of the readme.
You could try to call the make command from inside your build process.
Cheers
[UPDATE based on the comments]
If you use:
make a PLAT=[target platform]
on the command line in the src directory it will only build the liblua.a library for the target platform then you will just need to copy that file to wherever you need and link against it.

Cmake: How to hold off finding libraries?

I have a Cmake project where I use static libraries from another project (which uses its own unique build system).
I have a bash script set up which compiles the libraries.
The problem arises when a new user checkouts both project. The new user cannot do cmake until the libaries are properly compiled in the other project, and the cmake command find_libarary cant find them.
I made the bash script part of cmake by using the command add_custom_target. But the issue is that it only execute if you do a "make".
Is there a way I can make CMake execute a command while its generating a build system. Or a better way would be to have it ignore the find command until the actual make?
Thanks
Why not LINK_DIRECTORIES(xxx) to the library folder and don't use find_library at all.
Sure, execute_process() function.

Code::blocks verbose build

I want to see the actual commands sent to g++ during a Code::Blocks build. I want to see exactly what command-line arguments it uses in the compile and link steps, and I don't want to have to poke around in the build settings GUI to do it.
Alternatively, converting the Code::Blocks project to an equivalent Makefile would work, but I see nowhere where I can do that, either...
Edit
I ended up using a Code::Blocks plugin, "cbMakeGen", to generate a makefile from which I removed some #s. Then I was able to see the commands. Surely there is an easier way...
I see you already solved the problem, but there's still a bit more to that.
Code::Blocks can write a build log when the following option is checked:
Settings->Compiler and debugger->Global compiler settings->{slide tabs to the right}->Build options tab->Save build log to HTML.
Besides, you can use "cbp2make" to convert Code::Blocks projects to makefiles. This is not a plugin like "cbMakeGen", but a stand-alone command-line tool. See also http://forums.codeblocks.org/index.php/topic,13675.0.html .
Besides the logging to html you can also go to
Settings->Compiler and debugger->Global compiler settings->{slide tabs to the right}->Other Settings and in that tab set 'Compiler Logging:' to 'full command line' (from drop down menu).
Now you can see the gcc command line in the console when you build.

Command libtool failed with exit code 1

I've created a static library C++ project but when I compile I get the following error:
XCode 4.1 (Lion) doesn't show me any more information what's going wrong. I'm using clang.
How can I find out what went wrong?
I have read elsewhere, and confirmed myself, that the problem is that Xcode is suppressing the output from stdout.
As a work around, in Xcode, flip open the display of the commands being executed and copy and paste them into a Terminal session and run lib tool from there.

Resources