Set C++ object file output location with CMake

2019-04-10 15:28发布

I would like to use CMake for a project, but I have the following two requirements:

  1. The final output of the project should be a set of object files (*.o).
  2. The location of the object files is important. I want to select which directory the files are outputted.

Does CMake support this type of behavior? If so, how? Can I do it with move commands after the object file is build?

标签: c++ cmake
1条回答
爷的心禁止访问
2楼-- · 2019-04-10 15:40

First create an object library.

Now the problem is that:

Object libraries cannot be imported, exported, installed, or linked. http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:add_library

I would try to use the install(DIRECTORY ...).

Using the options:

DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}   #Probably you have to check more precisely where the object files are built

DESTINATION    #it's something relative to DESTDIR, if set, or CMAKE_INSTALL_PREFIX otherwise

FILES_MATCHING

PATTERN "*.o"

A flaw of this solution will be in the output directory name, that will be basically decided by cmake, I wonder if anything can be done in that respect.

查看更多
登录 后发表回答