# How to append prefix to program and library in the command line?

**URL:** https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306
**Category:** Usage
**Created:** [July 23, 2024, 4:43am UTC](https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306 "2024-07-23T04:43:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ikspress](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@ikspress](https://discourse.cmake.org/u/ikspress)
#### Post date: [July 23, 2024, 4:43am UTC](https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306/1 "2024-07-23T04:43:34Z")

</div>

I attempted to compile LibreSSL using CMake for my self. LibreSSL serves as a drop-in replacement for OpenSSL, thus it may conflicts with the original OpenSSL. My intention is to use LibreSSL exclusively for my own programs, without affecting other software. AFAIK, libressl in Arch Linux packages uses `--program-prefix` to specify a prefix for LibreSSL to prevent name collisions, but it is a option in autotools. I am wondering to know if there is a similiar mechanism within CMake?

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [July 23, 2024, 7:56pm UTC](https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306/2 "2024-07-23T19:56:27Z")

</div>

See CMAKE\_INSTALL\_PREFIX

---

<div class="post-metadata">

### Author: ![ikspress](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@ikspress](https://discourse.cmake.org/u/ikspress)
#### Post date: [July 24, 2024, 6:19am UTC](https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306/3 "2024-07-24T06:19:48Z")

</div>

Sorry, perhaps I didn’t make it clear and you midunderstood it.  
I mean I want the library (.so .dll etc) and program (.exe etc) start with a prefix, not specify an install directory.  
e.g. I configured libressl with the following command.  
`../libressl-3.9.2/configure --program-prefix=libressl-`  
I will get `libressl-openssl` `libressl-ocspcheck` instead of `openssl` `ocspcheck`.  
Sorry again for my mistake.

---

<div class="post-metadata">

### Author: ![atncsj6h](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@atncsj6h](https://discourse.cmake.org/u/atncsj6h)
#### Post date: [July 28, 2024, 7:21pm UTC](https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306/4 "2024-07-28T19:21:55Z")

</div>

try something along the lines of

```auto
    set_target_properties( target
      PROPERTIES
      PREFIX "prefix" )

```

---

<div class="post-metadata">

### Author: ![ikspress](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@ikspress](https://discourse.cmake.org/u/ikspress)
#### Post date: [August 8, 2024, 8:07am UTC](https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306/5 "2024-08-08T08:07:34Z")

</div>

For my own solution:

```cmake
# inject.cmake
string(TOLOWER "${PROJECT_NAME}" LIB_PREFIX)
set(LIB_PREFIX "${LIB_PREFIX}-")
set(CMAKE_SHARED_LIBRARY_PREFIX "${LIB_PREFIX}")
# Other codes uses LIB_PREFIX

```

And then apply `-DCMAKE_PROJECT_INCLUDE="${srcdir}/inject.cmake"` to cmake command.  
It’s strange that I can’t just use `-DCMAKE_SHARED_LIBRARY_PREFIX` directly.  
Thanks for the inspiration.

---

<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: [July 18, 2025, 8:27pm UTC](https://discourse.cmake.org/t/how-to-append-prefix-to-program-and-library-in-the-command-line/11306/6 "2025-07-18T20:27:54Z")

</div>

> [@ikspress](#):
>
> It’s strange that I can’t just use `-DCMAKE_SHARED_LIBRARY_PREFIX` directly.

It is a toolchain variable. Those are set as local variables as part of CMake’s toolchain caching mechanism. `-D` on the command line makes a cache variable. Local variables always shadow cache variables, so the toolchain value hides your requested cache value.
