Re: source code organization in a C++ project
On 14/12/09 19:54, lhommedumatch wrote:
Hello
I'm working on a C++ project on linux and I want to use autotools.
Before that I need to change the organization of the projects.
I would suggest using plain GNU make for simplicity if you build for a
limited set of platforms.
For the moment, this is how it is organized:
bin for binaries
DEV/Makefile : a makefile for all the project
DEV/SOC/src => source code for socket classes
DEV/SOC/include => headers of socket classes
DEV/SOC/obj => .o files
DEV/DRI/src => .cc class for drivers
DEV/DRI/include => headers of drivers
DEV/DRI/obj => .o
and so on
Where to put object and binary files depends on the requirements of your
project. For example, if you'd like to switch between debug and release
mode builds often it makes sense to add the build mode name in the name
of the folder for object and binary files, e.g. obg-debug and obj-debug.
This way when you switch between the build modes make does not confuse
debug object files with the release ones. Same for the static and shared
libraries and executables.
It is also very convenient to put the generated dependency .d files into
the corresponding object file folder along with the corresponding .o
because debug and release build header dependencies may well be different.
The most flexible way is to build into a separate build root folder.
Under that root folder the source folder tree is replicated (source
files don't get replicated and stay where they are). For example,
${src_dir}/SOC/src/socket.cc gets compiled into
${root_dir}/obj/SOC/src/socket.o and ${root_dir}/obj/SOC/src/socket.d.
Shared libraries and executable binaries go under ${root_dir}/bin.
As a part of its name the root folder may include the build mode and,
for multi-platform/architecture builds, it may also include platform
(say Linux, SunOS, etc..), architecture (i686, x86_64, etc..), memory
model (32/64 bit), compiler name (gcc, icc, etc..) and compiler versions
if you intend to build often with different compilers, and the build
model. For example: Linux.x86_64.64.gcc-4.4.debug. You can figure all
this information from within the makefile ($(shell uname), $(shell gcc
--version)) and construct the root build folder name.
--
Max