1

I'm trying to use CPack to package my project, but I've run into an issue with one of my dependencies.

First, I am trying to use modern CMake style by relying on targets and dependencies modeled between targets using target_link_libraries. My project uses the CMocka library as a dependency. I have added the CMocka repo as a git submodule and I have add_subdirectory(cmocka_dir) in my own CMakeLists.txt file.

I also use CPack with the TGZ generator to gather all my files into an archive. I simply set(CPACK_GENERATOR TGZ) and include(CPack) in my CMakeLists.txt. I have found that this takes care of everything, that is, until I started using CMocka. CMocka sets a lot of CPACK_xxx variables inside its root CMakeLists.txt. I believe that when I include CMocka's subdirectory in my own project, these variables propagate inside my CMake scope and mess with my packaging process.

My question is how I can fix this. Specifically:

  1. Is there a way to isolate CMocka in its own environment, or otherwise prevent it from breaking my packaging process?
  2. Am I doing it wrong by including CMocka using add_subdirectory?
  3. Am I doing CPack wrong by just setting CPACK_GENERATOR and doing include(CPack)?

Thanks for your thoughts.

Dan Nestor
  • 2,441
  • 1
  • 24
  • 45
  • 1
    Do not include the external library in your own project. Instead, download, build and install the external library in your system, and use in your project `find_package(cmocka)` following some documentation like [this one](https://re-ws.pl/2018/10/using-cmocka-for-unit-testing-c-code/). – Former contributor Feb 05 '20 at 18:52
  • and as an addendum to @Pedro comment: build native packages (DEB/RPM/NugGet/...) of all your third-parties and store in the (private) repo. It'll make your development environment reproduceable and easy to deploy by anyone familiar w/ `apt`,`yum`,`nuget`... – zaufi Feb 14 '20 at 09:13
  • Thanks for the suggestions. Since we're cross-compiling for multiple platforms I'm trying to avoid unnecessarily installing dependencies to my system (or sysroot). As far as I understand this is also a CMake best practice? – Dan Nestor Feb 15 '20 at 10:09

0 Answers0