Hugs Not Drugs
Manually set the CMake output folder 1
If you want to manually set the global output folder for you whole CMake project and depending on the output you expect add the following configuration lines in the root CMakeLists.txt file of your project:
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
In case you wan to specify those folders per target, you can update them as follows:
set_target_properties( target_or_targets
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
Please note that we are setting the same properties using different variables.
The
CMAKE_ARCHIVE_OUTPUT_DIRECTORYvariable is used to initialize theARCHIVE_OUTPUT_DIRECTORYproperty on all the targets.
ARCHIVE_OUTPUT_DIRECTORYproperty specifies the directory into which archive target files should be built.
An archive output artifact of a buildsystem target may be:
- The static library file (e.g.
.libor.a) of a static library target created by theadd_library()command with theSTATICoption.- On DLL platforms: the import library file (e.g.
.lib) of a shared library target created by theadd_library()command with theSHAREDoption.- On DLL platforms: the import library file (e.g.
.lib) of an executable target created by theadd_executable()command when itsENABLE_EXPORTStarget property is set.
The
CMAKE_LIBRARY_OUTPUT_DIRECTORYvariable is used to initialize theLIBRARY_OUTPUT_DIRECTORYproperty on all the targets.
LIBRARY_OUTPUT_DIRECTORYproperty specifies the directory into which library target files should be built.
A library output artifact of a buildsystem target may be:
The loadable module file (e.g..dllor.so) of a module library target created by theadd_library()command with theMODULEoption.
On non-DLL platforms: the shared library file (e.g..soor.dylib) of a shared shared library target created by theadd_library()command with theSHAREDoption.
The
CMAKE_RUNTIME_OUTPUT_DIRECTORYvariable is used to initialize theRUNTIME_OUTPUT_DIRECTORYproperty on all the targets.
RUNTIME_OUTPUT_DIRECTORYproperty specifies the directory into which runtime target files should be built.
A runtime output artifact of a buildsystem target may be:
- The executable file (e.g.
.exe) of an executable target created by theadd_executable()command.- On DLL platforms: the executable file (e.g.
.dll) of a shared library target created by theadd_library()command with theSHAREDoption.


