Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

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

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 building behaviour, inconvenient. What I want is, have my final program be located in :

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

rather than

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

How would you do that using CMake ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...