Best folder structure for cross-platform C ++ library and bindings

I am going to start work on a cross-platform library that will be written in C ++. In the future, I intend to implement bindings for other languages ​​such as Python, Java, etc. The library should be available on the main platforms: win32, Linux, and Mac OSX.

Despite the fact that the application is indeed a library, some basic console programs will be with it for demonstration and testing.

I would like to create an optimal folder structure before I start storing things in Subversion.

I am thinking of something like:

/project //Top level folder /bin //Binaries ready for deployment /linux_amd64 //Linux AMD64 platform /debug //Debug build - duplicated in all platforms /release //Release build - duplicated in all platforms /linux_i386 //Linux 32-bit platform /macosx //Mac OS X /win32 //Windows 32-bit platform /cygwin //Windows 32-bit platform compiled with Cygwin /vs.net //Windows 32-bit platform compiled with Visual Studio .NET /win64 //Windows 64-bit platform /build //Make and build files, IDE project files /linux_amd64 //Linux AMD64 platform /linux_i386 //Linux 32-bit platform /macosx //Mac OS X /win32 //Windows 32-bit platform /win64 //Windows 64-bit platform /config //Configuration files that accompany the binaries /data //Data files that accompany the binaries /doc //Documentation /lib //External or third-party libraries /platforms //Platform-specific code for ... /linux_amd64 //Linux AMD64 platform /linux_i386 //Linux 32-bit platform /macosx //Mac OS X /win32 //Windows 32-bit platform /win64 //Windows 64-bit platform /src //Available library source code in subfolders /src //Source code tree - this will contain main.cpp /bindings //Bindings to other languages such as ... /python /java /h //Header files /modules //Platform-independent modules, components or subprojects /platforms //Platform-specific code for ... /linux_amd64 //Linux AMD64 platform-specific code /linux_i386 //Linux 32-bit platform-specific code /macosx /win32 //Windows 32-bit platform-specific code /win64 //Windows 64-bit platform /test //Automated test scripts 

If you have any suggestions, I would like to hear them. I wonder if there is a tool that can help create this structure.

I plan to use CMake and Subversion.

+51
c ++ cross-platform
Apr 05 '09 at 0:38
source share
4 answers

The structure looks good to me, but there are a few points:

  • Is it normal to separate the C ++ header and source files in different directories, or maybe there is a structure in the modules directory that you do not show?
  • you probably want directories to put intermediate files like * .obj in
  • you will need different directories to debug and release output files
  • a directory for installers such as InnoSetup and their installation files may be useful. You must make a philosophical decision on whether to manage versions of these

As for the tools for creating the structure, you only need a few minutes spent creating a bash script, so for all platforms you need to have the same tools (for example, bash).

+10
Apr 05 '09 at 1:17
source share

Why do you need different folders for folders for binaries? Are you going to create this source code in different formats, but with the same file system?

If so, I think you also need special folders for the compiler.

Why don't you use different folders to build debugging and release, perhaps unicode and non-unicode, single-threaded or multi-threaded assemblies?

Look at bjam or Scons, replace them. You may not need different folders in the assembly directory.

I think it would be better if all the modules from the "modules" directory contain the "test" directory to check for self.




And the last one - see boost library, this platform independent platform that has a nice structure.

Also try to get ideas from third-party projects related to the platform.

Creating a folder structure:

 boost - root dir - boost - library header lib ( for users ) - libs - library source dir ( one dir per lib ) - build - library build files ( if they are needed ) - doc - documentation files - example - sample programs - src - library source files - test - programs and srcipts for testing module - bin - created by bjam build system - libs - <lib-name> for all compiled folders from libs [example|test|build] - <compiler-name>/<[static|dynamic]-link>/<[debug|release]>/<[threading mode]> contain builded [obj|dll|lib|pdb|so|o|etc] files see detailed information in bjam build system - doc - tools 

If you choose bjam, you will not worry about the structure of the assembly and the bin basket.

In addition, your libs / src / dir may contain its own for all platform files and a pair of dir for platform files.

I do not see serious problems in your structre folders, maybe you will see them when you run the prototype project.

+6
Apr 05 '09 at 1:00
source share

I recently posted a question about packaging headers in only one directory, decided to go with a small number of directories included.

Are you going to service Win64? This will become an increasingly important goal.

Do not put your intermediate build files anywhere under the tree being checked in svn. If you do this, depending on your svn client tools, they will generate a lot of noise in the form of files that are not in the repository. This makes it difficult to see the files that you added, which should be in the repository.

Instead, if your compiler allows this, put the intermediate directories on one side.

Otherwise, make sure you add all the staging directories to your svn exception properties. Some GUIs make this easier than others (turtle on Windows, Cornerstone, or OS / X versions).

+2
Apr 05 '09 at 2:44
source share

Can I suggest not using architecture to categorize build files?

I tried to apply the proposed folder structure, but I could not find the right place to put common Linux Makefile definitions and Visual Studio property files. How about the following:

 /project /build /linux /macosx /win32 (or win) 

And an example may include:

 /project /build /linux Make.defs Makefile [i386, amd64] /win32 /VC8 /<project> <project>.vcproj <solution>.sln [Win32, x64] /VC11 /<project> <project>.vcxproj <solution>.sln [Win32, x64, ARM] 

If you do not want to define architecture assemblies through configurations, what about another folder layer under board types?

 /project /build /linux /linux_amd64 /linux_i386 /macosx /? /win32 (or win) /win32 /win64 

If this project does not have common build files for the platform, the source structure will be sufficient.

0
Jan 07 '15 at 16:55
source share



All Articles