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

后端 未结 2 1931
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 15:46

My problem is as such : I\'m developing a small parser using Visual Studio 2010. I use CMake as a build configuration tool.

But I find the default executable buildin

相关标签:
2条回答
  • 2020-12-25 15:56

    There are several options:

    1. Copy the executable after building
    2. Customizing the output-directory for your executable(s)

    Copy the executable after building

    After a succesful build you can copy the executable (see Beginners answer), but perhaps it is nicer to use an install target:

    Use the install command to specify targets (executables, libraries, headers, etc.) which will be copied to the CMAKE_INSTALL_PREFIX directory. You can specify the CMAKE_INSTALL_PREFIX on the commandline of cmake (or in the cmake GUI).

    Customizing the output-directory for your executable(s)

    Warning: It is not advised to set absolute paths directly in your cmakelists.txt.

    Use set_target_properties to customize the RUNTIME_OUTPUT_DIRECTORY

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

    As an alternative, modifying the CMAKE_RUNTIME_OUTPUT_DIRECTORY allows you to specify this for all targets in the cmake project. Take care that you modify the CMAKE_LIBRARY_OUTPUT_DIRECTORY as well when you build dlls.

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

    Additional info: Take a look at these questions:

    • In CMake, how do I work around the Debug and Release directories Visual Studio 2010 tries to add?

    • CMake : Changing name of Visual Studio and Xcode exectuables depending on configuration in a project generated by CMake

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

    0 讨论(0)
  • 2020-12-25 16:03

    Most probably you will need to copy your binaries with a separate custom command which would look similar to this one:

    add_custom_command(target your_target_name
              POST_BUILD
              COMMAND ${CMAKE_COMMAND} -E copy ${EXAMPLE_BIN_NAME} ${PROJECT_BINARY_DIR}/.
    )
    
    0 讨论(0)
提交回复
热议问题