# How can I change the output path and the output name of a compiler?

**URL:** https://discourse.cmake.org/t/how-can-i-change-the-output-path-and-the-output-name-of-a-compiler/6011
**Category:** Usage
**Created:** [July 6, 2022, 8:16am UTC](https://discourse.cmake.org/t/how-can-i-change-the-output-path-and-the-output-name-of-a-compiler/6011 "2022-07-06T08:16:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MKR](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mkr/32/2575_2.png) [@MKR](https://discourse.cmake.org/u/MKR)
#### Post date: [July 6, 2022, 8:16am UTC](https://discourse.cmake.org/t/how-can-i-change-the-output-path-and-the-output-name-of-a-compiler/6011/1 "2022-07-06T08:16:14Z")

</div>

I want to change the output path and the output name of the gcc-Compiler (the -o flag of the compiler) for a specific target.  
How can I do this?

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [July 6, 2022, 8:28am UTC](https://discourse.cmake.org/t/how-can-i-change-the-output-path-and-the-output-name-of-a-compiler/6011/2 "2022-07-06T08:28:02Z")

</div>

You probably want to set [https://cmake.org/cmake/help/latest/prop\_tgt/RUNTIME\_OUTPUT\_DIRECTORY.html](https://cmake.org/cmake/help/latest/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html) or [https://cmake.org/cmake/help/latest/prop\_tgt/LIBRARY\_OUTPUT\_DIRECTORY.html](https://cmake.org/cmake/help/latest/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html) (possibly also the `*_OUTPUT_NAME`) properties on the target in question.

---

<div class="post-metadata">

### Author: ![MKR](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mkr/32/2575_2.png) [@MKR](https://discourse.cmake.org/u/MKR)
#### Post date: [July 6, 2022, 2:29pm UTC](https://discourse.cmake.org/t/how-can-i-change-the-output-path-and-the-output-name-of-a-compiler/6011/3 "2022-07-06T14:29:57Z")

</div>

You are right for  
add\_library(target prog.cpp)  
set\_target\_properties(target PROPERTIES ARCHIVE\_OUTPUT\_DIRECTORY ${my\_path})

but my question was too imprecise.

I want to use  
add\_library(target OBJECT prog.cpp)  
So I mean the obj-files.

The reason is: I want write all modules-files in one directory

Something like this  
add\_library(target prog.cpp)  
set\_target\_properties(target PROPERTIES XXX\_OUTPUT\_DIRECTORY ${my\_path} COMPILE\_FLAGS -fmodules-ts)

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [July 7, 2022, 5:47am UTC](https://discourse.cmake.org/t/how-can-i-change-the-output-path-and-the-output-name-of-a-compiler/6011/4 "2022-07-07T05:47:07Z")

</div>

I don’t thing CMake gives you control over object files.

I’m “redirecting” the final files (exe, dll/so, a/lib) for years now for easier debugging but have never seen a possibility (or need) to do that for object files.

---

<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 9, 2022, 1:14pm UTC](https://discourse.cmake.org/t/how-can-i-change-the-output-path-and-the-output-name-of-a-compiler/6011/5 "2022-07-09T13:14:20Z")

</div>

> [@MKR](#):
>
> COMPILE\_FLAGS -fmodules-ts)

C++ modules cannot be reliably done without proper CMake support. 3.25 will have experimental support given a suitable compiler.
