[CMake] Recursive object libraries

Brad King brad.king at kitware.com
Thu May 9 11:40:56 EDT 2013


On 05/09/2013 11:12 AM, Jonathan Anderson wrote:
> I've attached a CMakeLists.txt file that demonstrates what
> I want to do (and what I can do with my patch).

Thanks, that makes sense.

Does "add_library(... SHARED OBJECT ...)" work?  I think you
mean to set the POSITION_INDEPENDENT_CODE target property instead.

Here are a few comments on the patch:

* The "Only executables and non-OBJECT libraries..." error message
  needs to have "non-OBJECT " removed from it.

* The object library following logic will need to be made recursive
  to fully implement what you propose.  Currently the patch only
  goes one level down, and it leaves out the AddUtility call for
  the deeper level.

> I'm not familiar with the CMake testing framework. When I run
> "ninja test", it says that e.g. the RunCMake.ObjectLibrary test fails,
> but I am able to manually build the Tests/ObjectLibrary project

Those are two separate tests:

* RunCMake.ObjectLibrary performs a bunch of tests that check
  error cases.  Your change makes what was previously an error
  not an error anymore so the test will need to be updated
  accordingly.  See Tests/RunCMake/ObjectLibrary.

* ObjectLibrary actually builds binaries as you've seen.  It
  will need to be updated to test at least 2 recursion levels
  in addition to all its current cases.

Run "ctest -R $testname -V" to run a test with verbose output.

Thanks,
-Brad


More information about the CMake mailing list