# CPack: - Run preinstall target...

**URL:** https://discourse.cmake.org/t/cpack-run-preinstall-target/10187
**Category:** Usage
**Created:** [February 25, 2024, 4:59pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187 "2024-02-25T16:59:07Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Nocaster60](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)
#### Post date: [February 25, 2024, 4:59pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/1 "2024-02-25T16:59:07Z")

</div>

I have a project that takes about 15 mins to build on Windows using the Intel fortran compiler. I have added the required files to create an Inno setup installer. Using the NMake Makefiles generator, building and running cpack from the build directory with the command line `--config CPackConfig.cmake` results in

```auto
CPack: Create package using INNOSETUP
CPack: Install projects
CPack: - Run preinstall target for: MyProject
CPack: - Install project: MyProject []
CPack: Create package
CPack: - package: G:/MyBuild_NMake/MyProject-2024.02.20-win32.exe generated.

```

where after the line `CPack: - Run preinstall target for: MyProject` there is a delay of 15 minutes while the whole project is silently rebuilt.  
However, using the Visual Studio 15 2017 generator, building and running cpack I don’t get the `CPack: - Run preinstall target for:` line and the installer is created in the time it takes InnoSetup to run. Any suggestions as to what might be happening and/or how I can prevent the preinstall target being run?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 27, 2024, 2:20pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/2 "2024-02-27T14:20:36Z")

</div>

There’s the `install/fast` rule in `Makefiles` generators. This basically just runs the install scripts without trying to bring the build up-to-date. I don’t know if Visual Studio generators make such a target; it may be useful and worth [an issue](https://gitlab.kitware.com/cmake/cmake/-/issues).

---

<div class="post-metadata">

### Author: ![Nocaster60](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)
#### Post date: [February 27, 2024, 8:04pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/3 "2024-02-27T20:04:20Z")

</div>

That seems to be the opposite of what is happening. The NMake Makefiles generator causes CPack to run the preinstall target, which is presumably what is causing the rebuild, whilst the Visual Studio generator results in CPack creating the installer directly. Is there a way of forcing the `install/fast` rule?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 28, 2024, 10:35am UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/4 "2024-02-28T10:35:26Z")

</div>

The NMake generator should have `/fast` targets AFAIK. @brad.king?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 28, 2024, 1:27pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/5 "2024-02-28T13:27:40Z")

</div>

CPack checks if the CMake generator has a `preinstall` target and drives it if so. Only Makefile generators have a `preinstall` target. It’s meant for re-linking binaries on platforms that support `RPATH`/`RUNPATH` fields, but using executable formats that CMake doesn’t know how to edit, in order to produce binaries with the install-tree runtime path values. VS generators don’t support targeting any such platforms and so do not have a `preinstall` target. The Ninja generator just never supported those platforms, and these days CMake knows how to edit both ELF and XCOFF formats.

If a build is up to date, the `preinstall` target should not cause a full rebuild. That’s something to track down locally.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [April 24, 2024, 2:42pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/6 "2024-04-24T14:42:15Z")

</div>

The above seems to be the most comprehensive documentation of the “preinstall target” to date.

I wonder, however, why Make is building this target in an ELF context though it is meant for platforms using executable formats that CMake doesn’t know how to edit … whereas CMake knows how to edit ELF.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 24, 2024, 2:54pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/7 "2024-04-24T14:54:12Z")

</div>

The Makefile generators’ `preinstall` target is a generic step they define. It happens to be used for the relinking on platforms that need it, but could conceivably be used for other things. At the time CPack asks if the CMake generator has a `preinstall` step, we don’t have the project’s code model loaded and so cannot know whether relinking is needed for the current platform or not. Therefore I don’t think we can optimize it out.

---

<div class="post-metadata">

### Author: ![Nocaster60](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)
#### Post date: [April 24, 2024, 3:39pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/8 "2024-04-24T15:39:36Z")

</div>

Is there a way of forcing the preinstall target to be up-to-date? My project is now taking 20 mins to build. It has 46 targets (using 900 odd source files), many of which are static libraries used by other targets, producing 100s of fortran modules. Whatever dependency analysis is going on it can’t untangle the build and something always gets recompiled when rebuilding after a successful build - bizarrely not necessarily the same files - triggering a full rebuild. Currently I’m not bothering with the build itself, just the preinstall target, but I miss the coloured scrolling progress of the build.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [April 24, 2024, 3:56pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/9 "2024-04-24T15:56:52Z")

</div>

A related question: Is it normal that the rebuild under the preinstall target is completely silent? Can I change that?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 24, 2024, 4:33pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/10 "2024-04-24T16:33:33Z")

</div>

> [@Nocaster60](#):
>
> Is there a way of forcing the preinstall target to be up-to-date?

If `make all` has finished and an immediate `make preinstall` is building something, then something is wrong with the dependencies. Does `make all` followed by another `make all` rebuild things too?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 24, 2024, 4:35pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/11 "2024-04-24T16:35:03Z")

</div>

> [@jwuttke](#):
>
> Is it normal that the rebuild under the preinstall target is completely silent?

`make preinstall` should be no louder or quieter than `make all`. Or are you talking about when `cpack` runs the preinstall step?

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [April 24, 2024, 8:12pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/12 "2024-04-24T20:12:55Z")

</div>

Or are you talking about when `cpack` runs the preinstall step? - Yes.

Command:

```auto
cpack -B ./installer .

```

Response:

```auto
CPack: - Run preinstall target for: MyProject

```

Then 10 minutes silence.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 25, 2024, 1:24pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/13 "2024-04-25T13:24:16Z")

</div>

The code in cpack that runs the preinstall build step is [here](https://gitlab.kitware.com/cmake/cmake/-/blob/v3.29.2/Source/CPack/cmCPackGenerator.cxx#L675-711). It currently has no option to show it on the terminal, but does capture and log the output to a file. If anyone is interested in adding a way to change that behavior, please open an issue to propose it.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [April 25, 2024, 1:35pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/14 "2024-04-25T13:35:00Z")

</div>

There is a `this->GeneratorVerbose` argument. Would that help? How would I activate it?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 25, 2024, 1:45pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/15 "2024-04-25T13:45:02Z")

</div>

Ah, I missed that, thanks. Try `cpack -V`.

---

<div class="post-metadata">

### Author: ![Nocaster60](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)
#### Post date: [April 25, 2024, 2:05pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/16 "2024-04-25T14:05:27Z")

</div>

I tried that. It just writes a couple of extra lines before the

```auto
CPack: - Run preinstall target for: MyProject

```

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 25, 2024, 2:17pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/17 "2024-04-25T14:17:37Z")

</div>

I think it may just change the amount of output that goes to the log file for `preinstall`.

I think my conclusion in [CPack: - Run preinstall target... - #13 by brad.king](https://discourse.cmake.org/t/10187/13) is correct.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [April 25, 2024, 2:22pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/18 "2024-04-25T14:22:18Z")

</div>

@Nocaster60, will you write an issue, or shall I?

---

<div class="post-metadata">

### Author: ![Nocaster60](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)
#### Post date: [April 28, 2024, 12:49pm UTC](https://discourse.cmake.org/t/cpack-run-preinstall-target/10187/19 "2024-04-28T12:49:42Z")

</div>

@jwuttke. Sorry, just realised this was addressed to me. Please could you write the issue. Thanks.
