3

I'm trying to use this external project in a CMake project of mine; the external project is also a CMake project.

Now, the external project produces static libraries and a bunch of headers; but - I don't want those to be installed anywhere, I just need them to build stuff as part of my main project (and the files are not necessary after build and/or install of the main project).

How do I get CMake to "fetch, build, but not install" an external project? I was thinking I might hackishly do this by forcing an empty install command, but I'm sure there's a better, more elegant way.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • You are aware of CMake's command ExtrenalProject, right? https://cmake.org/cmake/help/latest/module/ExternalProject.html – usr1234567 Aug 02 '18 at 20:54
  • "I was thinking I might hackishly do this by forcing an empty install command, but I'm sure there's a better, more elegant way." - Empty `INSTALL_COMMAND` option is a true way for disable install step. Why do you think of it as a "hackish"? – Tsyvarev Aug 02 '18 at 21:11
  • @usr1234567: Of course. That's what I'm using. – einpoklum Aug 02 '18 at 22:14
  • @Tsyvarev: Because CMake will still try to "install" the project. I want it to not try that. – einpoklum Aug 02 '18 at 22:15
  • ExternalProject's documentation says that "Passing an empty string as the ```` makes the install step do nothing". So there are unlikely other ways. – Tsyvarev Aug 02 '18 at 23:08

1 Answers1

4

As mentioned by @Tsyvarev, to skip the install of an external project, you can simply pass the argument INSTALL_COMMAND "", this is definitively the recommended approach.

For example:

ExternalProject_Add(Foo
  GIT_REPOSITORY "git://github.com/Foo/Foo"
  GIT_TAG "123456"
  SOURCE_DIR ${CMAKE_BINARY_DIR}/Foo
  BINARY_DIR ${CMAKE_BINARY_DIR}/Foo-build
  CMAKE_CACHE_ARGS
    -DFOO_ENABLE_BAR:BOOL=1
  INSTALL_COMMAND ""
  )

Then you would configured the dependent external project with -DFoo_DIR:PATH=${CMAKE_BINARY_DIR}/Foo so that find_package(Foo REQUIRED) works as excepted. For this to work, the assumption is that the external project provide a working config file for the build tree.

To learn more about config files, see Correct way to use third-party libraries in cmake project

J-Christophe
  • 1,975
  • 15
  • 13