Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to organizing a large build using cmake

Tags:

c++

cmake

I'm working on a larger project and we are thinking on how to organize the large build. I think it should/could be done with cmake but currently I don't know how all of our requirements can be met.

Here's what our project organization looks like:

  • The project consists of multiple sub-projects (called build modules)
  • each build module can consist of multiple parts that create either static or dynamic libs, executables or tests
  • build modules may depend on the public interface of other build modules
  • for fast build times, each build module should be built on a separate CI-server. The dependencies should not be built each time but fetched from some binary repository (we're thinking about nuget here, but the simplest solution might be a network share)

With cmake in mind, I'm thinking of a directory structure like this

- Root directory
    - Build Module 1
        - Build Module 1 Static Lib
        - Build Module 1 Unit Test
        - Build Module 1 Public Interface
    - Build Module 2
    - ...
    - Build Module n

First question here: Where to start placing the CMakeLists.txt files? I'd start at Build Module level and not on root. This way, a developer can create his custom one if he wants to build only the modules 3, 4 and 5.

Second one: how to handle deployment / finding packages. Ideally, the find mechanism for the dependencies would allow the creation of builds that built from source as well as builds that fetch just the dependent binaries from source. I hope this can be done somehow using find_package and xxxConfig.cmake / FindXXX.cmake. Can someone tell me how? How do I create these files? How do you create the appropriate deployment using cmake?

Third question: has someone some information on how we could integrate nuget into this process? Can this be done as cpack generator? Is there already one? Can cpack be a replacement for nuget (meaning that it can fetch binaries from some remote location and install them in the build process)?

Thank you. Tobias

like image 347
Tobias Langner Avatar asked Oct 21 '22 09:10

Tobias Langner


1 Answers

1) You could create a top-level CMakeLists.txt file and have cache options for building each module:

http://quickgit.kde.org/?p=extra-cmake-modules.git&a=blob&h=6cbafa2d&hb=5f60617c&f=modules%2FECMOptionalAddSubdirectory.cmake

Developers can use those options to build 3, 4, 5. Alternatively, document how to add the add_subdirectory() calls they need. If modules should also build standalone (as it seems), the way to do that is:

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
    # Top-level build. Find dependencies.
    find_package(Module1).
else()
    # Built as a subdir together with depenendencies.
    # Dependencies are already in scope.
endif()

2) I wrote this documentation for CMake 3.0, but most of it applies to 2.8:

http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html

You can probably add config files to your source containing something like

add_subdirectory(${CMAKE_CURRENT_LIST_DIR})

to get 'source packages' using find_package and manipulating your CMAKE_PREFIX_PATH.

3) There is no existing nuget cpack generator shipped with cmake. You may want to look into ExternalProject:

http://www.cmake.org/cmake/help/v3.0/module/ExternalProject.html

like image 119
steveire Avatar answered Nov 01 '22 12:11

steveire