开发者

CMake: export third party headers to directory

Using CMake I am using a third party library, TinyThread++, it is a simple Thread library wrapper and only contains 1 source files and 2 header files.

In my project CMakeList.txt I added the following line:

add_library(TinyThread STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/TinyThread/source/tinythread.cpp)

And then added a dependency to this library to the my executable this is working great.

I am trying to figure out how to copy or export the two header files to a common include directory I am using in my project.

$开发者_如何转开发{CMAKE_CURRENT_SOURCE_DIR}/../../include

What is the recommended way to do this?


If you simply want to "use" those headerfiles while compiling, you can use include_directories() like Naszta explains.

In case you really want to copy the files, you can use configure_file() or file( COPY ... ) (check the bottom of the section on the file() command).


I think you should do something like this:

SET(TINY_THREAD_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "TinyThread include path")
SET(TINY_THREAD_SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/tinythread.cpp" CACHE FILEPATH "TinyThread source file")
...
INCLUDE_DIRECTORIES(${TINY_THREAD_INCLUDE_PATH})
ADD_LIBRARY(TinyThread STATIC ${TINY_THREAD_SOURCE_FILE})

This way you could reuse them later by their name. If you would like to hide them in normal mode:

MARK_AS_ADVANCED(TINY_THREAD_INCLUDE_PATH TINY_THREAD_SOURCE_FILE)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜