Fixed cmake output directory - makefile

I'm working on my first project using cmake, and for the most part it's been going well but I've run into one problem I can't figure out.
Let's say I have my CMakeLists.txt file located at ~/project/build. I would like for the output from cmake (not the binaries, but the makefile/configuration files) to be independent of where I run cmake from.
As an example, if my terminal is sitting in the ~/project/build directory, calling cmake ~/project/build creates the makefile and everything else within the ~/project/build directory. This is the behaviour that I'd like. If I call cmake ~/project/build from anywhere else, it creates the makefile and everything else in whatever directory the terminal called the program from.
Is it possible to force cmake to generate its makefile and associated files in the same folder as the CMakeLists.txt file? I've taken a look through the documentation and I've had no problems figuring out how to change binary output directories, but I can't really find any mention of what I'm trying to do.
I realize this is a pretty minor annoyance (it's not that hard to move into my build folder before building the project) but I'm just wondering if it's possible and if there's some reason it wouldn't be advised.

You have to use 2 commands for this
1) cmake -B "Dest path(Any path in which u want to generate the output files)" -H"Source path(root CMakeLists.txt path)"
2) cmake --build "Dest path"

Related

'Build raylib using make' - I built it using the wrong setting, do I just delete folder and try again?

via: https://github.com/raysan5/raylib/wiki/Working-on-Windows
I installed mingw to build raylib. The instructions as noted above said to use the 1st command. I used the second one by accident. So I deleted the entire raylib folder and extracted out a second one and then used the proper command to compile. My question is: was that the proper way to uninstall my mistake? Or did it create something somewhere else I needed to delete? Comparing the /src of the unbuilt and built versions the difference was a few .o files....does the mingw command just compile code 'for the folder in question'? so everything i did with that mistaken command woulda been held in the /src folder? And if everyone is contained to the raylib folder...then I can freely change the directory that raylib folder inhabits? i.e. I can move it from downloads to c

Do different Makefiles with the same compiler flags produce different binaries

Maybe this has been asked before but I could not find anything, that answers my question precisely.
I created a New arm cortex cmsis cpp project in eclipse. This gave me the default folder structure. I build the debug config and now have the generated makefiles in the debug folder. From here I can Do "make clean" and "make and everything compiles fine. The makefiles (including the sub mk files) were to static for my needs, so I changed them to be more generic (I only tell the make where the src folders are and it scans all the folders for c and cpp files and builds All the obj files and dependencies). I also took the makefile out of the debug folder and put it one level up into the project folder. So all together, I changed the location of the makefile and made it more dynamic. Now when I run "make", everything runs fine. Everything is compiled BUT the generated .elf and .bin have a different size, compared to files, that were created with the original files. I can See in the terminal that make creates the same files in the same order with the same flags. Everything is identical except that the location of the files now is in ./ instead of ../ How is this possible?
Most object files and binaries contain information about the location of the source files, so that the debugger can locate them. There may be other changes such as date and time stamps (although it's unlikely this will change the size of the output).
You can run something like strings myprog | sort on both old and new programs and see if the strings in your program are now different sizes.

Is it possible to figure out how cmake is called from cmake files and caches?

Within the build directory, I can see values of particular cmake variables using ccmake .. (assuming CMakeLists.txt sits on parent directory).
This becomes less effective when the original call to cmake has set many different variables in a large cmake project. For instance, if I call cmake like so:
cmake ..
-DCMAKE_PREFIX_PATH="path_1;path_2;ect"
-DCMAKE_INSTALL_RPATH="yet_another_path"
-DCMAKE_INSTALL_PREFIX="yet_another_path"
-DCMAKE_BUILD_TYPE=...
-DPROJECT_SPECIFIC_FLAG_1=...
-DPROJECT_SPECIFIC_FLAG_2=...
Is there anyway to be find out about this original call to CMakeLists.txt file from the cache or files? Is this string stored somewhere?

cmake-gui show blank except source code directory and binaries directory

After installing cmake-3.8.1-win64-x64 I got thisenter image description here
So what can I do with this? Thanks.
cmake-gui does not help you create cmake configuration files, it parses these files to generate and configure projects.
In your source code directory, you should have a CMakeLists.txt file which defines the rules for CMAKE to configure your problem. That directory should be entered into the first box.
Next, you get to decide where to build the binaries. We could do it in the source directory, but the generated artifacts could pollute what is already there. "Cleaning" the build by deleting all of those artifacts while keeping the original sources is tedious at best, so it's a good idea to make an empty directory and use that as your binaries path.
Once you have those fields entered, you should be able to "Generate" or "Configure" your project. If you need help creating a CMakeLists.txt file (that's really the complicated part), then check out their tutorial.

running cpp project with cmake (mac)

My question is very naive. Every time I ran an algorithm, it's with an IDE so I don't know exactly what is generated in backgrown.
I try to run with my MacBook an algorithm that I didn't write and I'm blocked !
In the readme file: they said "Use cmake to generate desired projects on different platforms. (See “CM.txt” in the
“src” folder)"
In the CM.txt:
project(BlProj)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
add_executable(BlProj
main.cpp
thi.cpp
thu.cpp
mat.cpp
Config.cpp
Stringer.cpp
)
I did: cmake CM.txt
A CM directory is generated. I will not list all the files inside: it's some cmake, bin, out, cpp, c, cxx, log, txt files.
I don't know what I can do with that!
I'm supposed to generate a compiled binary and run it with the command:
./BlProj data1 data2 10 config output
But it wasn't generated...
So I don't know how I can have the BlProj executable. Could you help me?
How do the cpp compilation work? What did cmake exactly?
Is cmake CM.txt is a good practice or not?
You can use cmake-gui to build sources.
go to CMAKE installation directory and inside bin folder run cmake-gui
Provide input where the source code is and provide an input where to build.
hit on configure and then generate.
you might need to select IDE version as well as provide additional input, it depends.
once done open generated project files with your IDE and build.

Resources