[CMake] Install without building unittests

Scott Bloom scott at towel42.com
Thu Mar 28 13:30:35 EDT 2019


> Note, Im running from inside visual studio...  I do realize for a 
> makefile based system, I can run make install from inside the 
> executable's build directory
>
> From: CMake <cmake-bounces at cmake.org> On Behalf Of Scott Bloom
> Sent: Wednesday, March 27, 2019 7:23 PM
> To: cmake at cmake.org
> Subject: [CMake] Install without building unittests
>
> I asked this a couple of years ago, and the answer was "no"...
>
> If you run tests, it doesn't automatically build tests...  So why does an install?
>
> I would never release something into the wild with out running the tests...
>
> But, for developer builds, were we need to install all the packages in order to run the applications, sometimes I just want to test the GUI which requires an install of the core application into the correct location, without building the 1500+ (yes 1500) unittests, which can take 15-20 minutes to build on their own...
>
> Is there anyway to break the dependency??

The "install" target depends on the "all" target, and the "all" target depends on everything built with "add_executable".  And I and presumably many other users of CMake would not be happy if the CMake developers decided to change these fundamental characteristics of CMake.  However, I think you can straightforwardly achieve exactly what you want to do as follows:

option(BUILD_UNIT_TESTS "Build unit tests?" OFF)
if(BUILD_UNIT_TESTS)
.... loop over add_executable for your various unit tests
endif(BUILD_UNIT_TESTS)

Of course, it is not as simple as that, and likely your builds of unit tests are scattered all over your build system, but the point is to protect all use of "add_executable" for those tests with an if block as above.  Then you specify -DBUILD_UNIT_TESTS=ON cmake option if you actually do want to build your unit tests, but otherwise the default is not to build them (just like you apparently want).

We have used a similar option over the years with the CMake-based build system for PLplot (in our case whether to build our standard examples in the build tree so we can test there in addition to our normal build and test of those examples in the installed examples tree).
That method has worked well for us, and I think it would work well for your needs also.

Alan
__________________________

We have this exact style of setup... However, I want the Unit Tests as part of the project, I just don't want them built when running install.. I have no problem with them being built for " all" target...

The variable CMAKE_SKIP_INSTALL_ALL_DEPENDENCY is what I was looking for....

Thanks
Scott








More information about the CMake mailing list