I am in the process of reorganizing the physical (on disk) layout of a large cross-platform C ++ project with many third-party dependencies, built using CMake.
Since we need to support Windows, a platform that does not have a well-installed package manager, we decided long ago to include third-party libraries that we rely on in the source tree. However, on other platforms that we support, such as Linux and Mac OS X, many of these third-party libraries are available as packages or are already on the system and are easily accessible by CMake.
The current project layout is as follows:
root/ src/ 3rd-party-lib1/ (build system modified to output to build/) 3rd-party-lib2/ (build system modified to output to build/) project-module1/ (our own code) project-module2/ (our own code) build/ (CMake is invoked from here) 3rd-party-lib1-bin/ 3rd-party-lib2-bin/
Third-party libraries were configured so that when they build, they output their binary files to root/build/<lib>/ .
There are several problems with this layout:
- Third-party libraries are no longer 100% original . This makes updating a little harder than required.
- The
src/ directory contains a mixture of our own code and third-party code , which is perplexing. - The
src/ directory is very large . Since src/ contains third-party libraries, it is very large compared to the actual amount of source code, which makes backing up our own code a little more difficult than required (we cannot just archive the entire src/ directory). - The project repository (Git) is very large , due to the inclusion of third-party libraries (which may contain many non-source files, such as documentation, test data, etc.), and it increases with each update . Unfortunately, there is no turning back if we did not decide to restart it using the new repository (unfortunately, we lost the entire commit history).
- Many of those who included third-party libraries (for example, zlib, libpng) are not needed at all by users creating a project on Linux or Mac OS X, although they greatly simplify the work of Windows users.
An alternative layout will be as follows:
root/ 3rdparty/ 3rd-party-lib1/ (100% original, contains built artifacts) 3rd-party-lib2/ (100% original, contains built artifacts) src/ project-module1/ (our own code) project-module2/ (our own code) build/ (CMake is invoked from here)
Our CMake files must be modified to look for third-party header files and libraries in the right place for each library.
What are the best methods for processing third-party libraries in their own cross-platform projects? Which layout would lead to the most unsurprising build experience for our developers on their respective platforms? Specific examples of successful layouts from existing projects are also welcome.
source share