c++跨平台库和绑定的最佳文件夹结构

时间:2021-07-24 12:02:43

I am about to begin work on a cross-platform library to be written in C++. Down the road, I intend to implement bindings for other languages such as Python, Java, etc. The library needs to be available on the major platforms: win32, Linux and Mac OSX.

我即将开始用c++编写一个跨平台库。接下来,我打算为其他语言(如Python、Java等)实现绑定。该库需要在主要平台上可用:win32、Linux和Mac OSX。

Although the application is really a library, some basic console programs will be bundled along with it for demonstration and testing.

虽然这个应用程序实际上是一个库,但是一些基本的控制台程序将与它一起进行演示和测试。

I'd like to come up with an optimum folder structure before I start storing stuff in Subversion.

在我开始在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 suggestions, I'd love to hear them. I wonder if there is a tool that can help create this structure.

如果你有什么建议,我很乐意听。我想知道是否有一个工具可以帮助创建这个结构。

I am planning on using CMake and Subversion.

我正在计划使用CMake和Subversion。

4 个解决方案

#1


10  

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

这个结构看起来不错,但有几点:

  • it's normal to separate C++ header and source files into different directories, or maybe there is structure in the modules directory you are not showing?
  • 将c++头文件和源文件分离到不同的目录中是很正常的,或者可能在模块目录中有您没有显示的结构?
  • you probably want directories to put intermediate files like *.obj in
  • 您可能希望目录放置中间文件,如*。obj在
  • you will need different directories for debug and release output files
  • 调试和发布输出文件需要不同的目录
  • a directory for installers like InnoSetup and their install files can be useful - you have to make the philosphical decision about whether to version control these
  • 对于像InnoSetup这样的安装程序和它们的安装文件,目录是有用的——您必须做出一个关于是否要控制它们的哲学性决定

As for tools to create the structure, a few minutes spent writing a bash script is all you need - it's worth having the same tools (like bash) available on all platforms.

至于创建结构的工具,只需要花几分钟编写bash脚本就可以了——在所有平台上都可以使用相同的工具(比如bash)。

#2


7  

Why you need different platform folders for binary files? You going to build this source code under different platoforms but with same file system?

为什么需要为二进制文件提供不同的平台文件夹?您将在不同的平台上构建这个源代码,但是使用相同的文件系统吗?

If yes, I think you need compiller specific folders too.

如果是,我认为您还需要compiller特定的文件夹。

Why you don't use different folders for debug and release build, maybe unicode and non-unicode, single-threading or multithreading builds?

为什么不使用不同的文件夹进行调试和发布构建,比如unicode和非unicode、单线程或多线程构建?

Look on bjam or Scons make replacers. Maybe you don't need different folders in build directory.

看看bjam或Scons的替代者。也许在build目录中不需要不同的文件夹。

I think it will be better if all modules from "modules" directory will contain "tests" directory for test self.

我认为,如果“模块”目录中的所有模块都包含“测试”目录,将会更好。


And last - see boost library, this platofrm independed library which have nice structure.

最后——见boost库,这个与platofrm相关的库具有良好的结构。

Also try to get ideas from antother platform independed projects.

也尝试从antother平*立的项目中获得想法。

Boost folders 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 be concerned on build and bin folders structure.

如果您选择bjam -您将不会关心构建和bin文件夹结构。

Also your libs/src/ dir could contain own for all platform files and couple dirs for platform spcific files.

您的libs/src/ dir可能包含所有平台文件的所有权,以及用于平台spcific文件的两个目录。

I don't see any serious problems in your folders structre, maybe you will see them when start write project prototype.

我在你的文件夹结构中没有看到任何严重的问题,也许你会在开始编写项目原型时看到它们。

#3


2  

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

我最近在一个目录中发布了一个关于打包头的问题,决定使用少量的include目录。

Are you going to cater for Win64? That will be an increasingly important target.

你要为Win64服务吗?这将是一个日益重要的目标。

Do not put your build intermediate files anywhere under a tree being checked into svn. If you do so, depending on your svn client tools, they will generate a lot of noise as files which are not in the repository. That makes it hard to see files you've added that should be in the repository.

不要把你的构建中间文件放在树下的任何地方。如果您这样做,依赖于您的svn客户端工具,它们将产生大量的噪音作为文件,而这些文件不在存储库中。这使得您很难看到您添加的应该在存储库中的文件。

Instead, if your compiler allows it, put the intermediate directories off to one side.

相反,如果编译器允许的话,把中间目录放在一边。

Otherwise, make sure you add the entire intermediate directories to your svn exclusion properties. Some GUI's make that easier than others (Tortoise on Windows, Cornerstone or Versions on OS/X).

否则,请确保将整个中间目录添加到svn排除属性中。有些GUI比其他GUI更容易实现这一点(Windows上的乌龟、OS/X上的基石或版本)。

#4


0  

Might I suggest not using the architecture to categorize build files?

我是否可以建议不要使用架构对构建文件进行分类?

I was trying to apply your proposed folder structure but I couldn't find the correct place to put common Linux Makefile definitions and Visual Studio property files. How about just the following:

我试图应用您建议的文件夹结构,但是我找不到合适的位置放置常见的Linux Makefile定义和Visual Studio属性文件。下面这些如何:

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

And example case would 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 don't want to define architecture builds through configurations, how about another folder layer under the platform types?

如果您不想通过配置来定义架构构建,那么在平台类型下的另一个文件夹层呢?

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

If a given project will not have any common build files for a platform, the original structure would suffice.

如果给定的项目没有任何用于平台的通用构建文件,那么原始的结构就足够了。

#1


10  

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

这个结构看起来不错,但有几点:

  • it's normal to separate C++ header and source files into different directories, or maybe there is structure in the modules directory you are not showing?
  • 将c++头文件和源文件分离到不同的目录中是很正常的,或者可能在模块目录中有您没有显示的结构?
  • you probably want directories to put intermediate files like *.obj in
  • 您可能希望目录放置中间文件,如*。obj在
  • you will need different directories for debug and release output files
  • 调试和发布输出文件需要不同的目录
  • a directory for installers like InnoSetup and their install files can be useful - you have to make the philosphical decision about whether to version control these
  • 对于像InnoSetup这样的安装程序和它们的安装文件,目录是有用的——您必须做出一个关于是否要控制它们的哲学性决定

As for tools to create the structure, a few minutes spent writing a bash script is all you need - it's worth having the same tools (like bash) available on all platforms.

至于创建结构的工具,只需要花几分钟编写bash脚本就可以了——在所有平台上都可以使用相同的工具(比如bash)。

#2


7  

Why you need different platform folders for binary files? You going to build this source code under different platoforms but with same file system?

为什么需要为二进制文件提供不同的平台文件夹?您将在不同的平台上构建这个源代码,但是使用相同的文件系统吗?

If yes, I think you need compiller specific folders too.

如果是,我认为您还需要compiller特定的文件夹。

Why you don't use different folders for debug and release build, maybe unicode and non-unicode, single-threading or multithreading builds?

为什么不使用不同的文件夹进行调试和发布构建,比如unicode和非unicode、单线程或多线程构建?

Look on bjam or Scons make replacers. Maybe you don't need different folders in build directory.

看看bjam或Scons的替代者。也许在build目录中不需要不同的文件夹。

I think it will be better if all modules from "modules" directory will contain "tests" directory for test self.

我认为,如果“模块”目录中的所有模块都包含“测试”目录,将会更好。


And last - see boost library, this platofrm independed library which have nice structure.

最后——见boost库,这个与platofrm相关的库具有良好的结构。

Also try to get ideas from antother platform independed projects.

也尝试从antother平*立的项目中获得想法。

Boost folders 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 be concerned on build and bin folders structure.

如果您选择bjam -您将不会关心构建和bin文件夹结构。

Also your libs/src/ dir could contain own for all platform files and couple dirs for platform spcific files.

您的libs/src/ dir可能包含所有平台文件的所有权,以及用于平台spcific文件的两个目录。

I don't see any serious problems in your folders structre, maybe you will see them when start write project prototype.

我在你的文件夹结构中没有看到任何严重的问题,也许你会在开始编写项目原型时看到它们。

#3


2  

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

我最近在一个目录中发布了一个关于打包头的问题,决定使用少量的include目录。

Are you going to cater for Win64? That will be an increasingly important target.

你要为Win64服务吗?这将是一个日益重要的目标。

Do not put your build intermediate files anywhere under a tree being checked into svn. If you do so, depending on your svn client tools, they will generate a lot of noise as files which are not in the repository. That makes it hard to see files you've added that should be in the repository.

不要把你的构建中间文件放在树下的任何地方。如果您这样做,依赖于您的svn客户端工具,它们将产生大量的噪音作为文件,而这些文件不在存储库中。这使得您很难看到您添加的应该在存储库中的文件。

Instead, if your compiler allows it, put the intermediate directories off to one side.

相反,如果编译器允许的话,把中间目录放在一边。

Otherwise, make sure you add the entire intermediate directories to your svn exclusion properties. Some GUI's make that easier than others (Tortoise on Windows, Cornerstone or Versions on OS/X).

否则,请确保将整个中间目录添加到svn排除属性中。有些GUI比其他GUI更容易实现这一点(Windows上的乌龟、OS/X上的基石或版本)。

#4


0  

Might I suggest not using the architecture to categorize build files?

我是否可以建议不要使用架构对构建文件进行分类?

I was trying to apply your proposed folder structure but I couldn't find the correct place to put common Linux Makefile definitions and Visual Studio property files. How about just the following:

我试图应用您建议的文件夹结构,但是我找不到合适的位置放置常见的Linux Makefile定义和Visual Studio属性文件。下面这些如何:

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

And example case would 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 don't want to define architecture builds through configurations, how about another folder layer under the platform types?

如果您不想通过配置来定义架构构建,那么在平台类型下的另一个文件夹层呢?

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

If a given project will not have any common build files for a platform, the original structure would suffice.

如果给定的项目没有任何用于平台的通用构建文件,那么原始的结构就足够了。