Title: Having CMake build, but not install, an external project
Tags: build;cmake;installation
Question: 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.

Comment: You are aware of CMake's command ExtrenalProject, right? https://cmake.org/cmake/help/latest/module/ExternalProject.html

Comment: @usr1234567: Of course. That's what I'm using.

Comment: @Tsyvarev: Because CMake will still try to "install" the project. I want it to not try that.

Comment: "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"?

Comment: ExternalProject's documentation says that "Passing an empty string as the ```` makes the install step do nothing". So there are unlikely other ways.

Here is the accepted answer: 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



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:08/02/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<build><cmake><installation>', 'Title': 'Having CMake build, but not install, an external project', 'ViewCount': 1738, 'id': 51661637, 'user_AboutMe': '<p>Made my way from the Olympus of Complexity Theory, Probabilistic Combinatorics and Property Testing to the down-to-earth domain of Heterogeneous and GPU Computing, and now I\'m hoping to bring the gospel of GPU and massive-regularized parallelism to DBMS architectures. I\'ve post-doc\'ed at the <a href="https://www.cwi.nl/research-groups/Database-Architectures" rel="nofollow noreferrer">DB architecture group</a> in <a href="http://www.cwi.nl" rel="nofollow noreferrer">CWI Amsterdam</a> to do (some of) that.</p>\n<p>I subscribe to most of Michael Richter\'s <a href="http://archive.is/kTKqG" rel="nofollow noreferrer">critique of StackOverflow</a>; you might want to take the time to read it.</p>\n<p>If you listen closely you can hear me muttering <a href="http://data.stackexchange.com/stackoverflow/query/590305/why-am-i-not-socratic-already-good-question-days-stunted-by-bad-questions" rel="nofollow noreferrer">&quot;Why am I not socratic again already?&quot;</a></p>\n', 'user_AccountId': 514136.0, 'user_DisplayName': 'einpoklum', 'user_Reputation': 106822.0, 'user_Views': 11847.0, 'user_id': 1593077.0}}