ccmakemakefilebuild-system

Build system output folder structuring


I want to make a public source library in C and I've been having a joyous time trying to work with both Makefiles and CMake. I like the simplicity of having one makefile per build partition but it's not cross-platform. I like the fact that CMake is cross-platform and although I hate the syntax types the language uses (I can get over that I guess..) it's the fact that when building, CMake floods my folders with a f*** tonne of cache files and I can't seem to change where they go. I would like to go with CMake since it seems to be more industry standard.

I like my builds in folders; Everything I care about in a seperate folder from all the build specific files that need to be generated. In visual studio I have this build structure and I would like to replicate it.

SolutionDir:
┝ Builds/
| ┝ Inter/ #For intermediate files
| | ┝ Debug/
| | | ┕ lib.o
| | ┕ Release/
| |   ┕ lib.o
| ┝ Debug/ #For the debug build files
| | ┕ ProjectName/ ... .exe
| ┕ Release/ #For the release build files
|   ┕ ProjectName/ ... .exe
┕ ProjectName/
  ┕ Source/
    | lib.h
    ┕ lib.c

I cant even figure out how to make a sub directory in either systems for the build folder side, of course you can include sub directories for finding the source code so there must be a way? Any help would be greatly appreciated, I've been at this for too long now.


Solution

  • You can do whatever you want with makefiles, but since you ask about cmake, the only way to do it is to run the build from the build folder. In other words, you do this (assuming that you have SolutionDir/CMakeLists.txt):

    cd SolutionDir
    mkdir Builds
    cd Builds
    cmake ..
    make -j8
    

    (or whatever make command that you want). The Builds directory can be anywhere you want, it doesn't have to be within SolutionDir. You pass the directory containing the CMakeLists.txt file to cmake.