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

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?

You probably want to set 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 (possibly also the *_OUTPUT_NAME) properties on the target in question.

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)

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.

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