How to change the executable output directory for building Win32 in CMake?

My problem is this: I am developing a small parser using Visual Studio 2010. I am using CMake as a build configuration tool.

But I find the default behavior of the executable building uncomfortable. I want my last program to be located in:

E:/parsec/bin/<exe-name>.<build-type>.exe 

but not

 E:/parsec/bin/<build-type>/<exe-name>.exe 

How do you do it with CMake?

+11
c ++ visual-studio cmake
Nov 25
source share
2 answers

There are several options:

  • Copy the executable after assembly
  • Setting the output directory for your executable file (s)

Copy the executable after assembly

After a successful build, you can copy the executable file (see "Beginners Answer"), but it might be better to use the installation goal:

Use the install command to specify the goals (executables, libraries, headers, etc.) that will be copied to CMAKE_INSTALL_PREFIX . You can specify CMAKE_INSTALL_PREFIX on the cmake command line (or in the cmake GUI).

Setting the output directory for your executable file (s)

Warning: It is not recommended to set absolute paths directly in the cmakelists.txt file.

Use set_target_properties to configure RUNTIME_OUTPUT_DIRECTORY

 set_target_properties( yourexe PROPERTIES RUNTIME_OUTPUT_DIRECTORY E:/parsec/bin/ ) 

Alternatively, changing CMAKE_RUNTIME_OUTPUT_DIRECTORY allows you to specify this for all purposes in the cmake project. Take care to change CMAKE_LIBRARY_OUTPUT_DIRECTORY when you create the DLL.

 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) 

Additional information . Take a look at these questions:

  • In CMake, how do I work with Debug and Release directories, is Visual Studio 2010 trying to add?

  • CMake: changing the name of Visual Studio and Xcode exjectuables depending on the configuration in the project generated by CMake

  • How not to add Release or Debug to output the path?

+18
Nov 26
source share
โ€” -

Most likely, you will need to copy your binaries with a separate user command, which will look something like this:

 add_custom_command(target your_target_name POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${EXAMPLE_BIN_NAME} ${PROJECT_BINARY_DIR}/. ) 
+3
Nov 26
source share



All Articles