我的这段代码的目的是将包含includes文件夹的静态lib复制到另一个目录中。
新目录将具有结构
output_dir
├───include
├───lib
└───win64
我有两行install
的CMake代码,我想简化为一行。首先,我将lib目标安装到output_dir/lib/win64
,将include
目录安装到output_dir/include
。
add_library(lib STATIC test.cpp )
target_include_directories(lib
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
install(TARGETS lib
ARCHIVE
DESTINATION
${PROJECT_SOURCE_DIR}/build/output_dir/lib/win64
)
install(DIRECTORY
${PROJECT_SOURCE_DIR}/include
DESTINATION
${PROJECT_SOURCE_DIR}/build/output_dir/include
)
我想有效地将两个安装命令减少为一个,这是我的最佳尝试。静态lib
库可以正确复制,但是目录将被忽略。
install(TARGETS lib
ARCHIVE
DESTINATION
${PROJECT_SOURCE_DIR}/build/output_dir/lib/win64
PUBLIC_HEADER
DESTINATION
${PROJECT_SOURCE_DIR}/build/output_dir/
INCLUDES
DESTINATION
${PROJECT_SOURCE_DIR}/build/output_dir/
)
我知道错误与public_header有关,但是我在做什么错呢?
答案 0 :(得分:0)
您应该只需要PUBLIC_HEADER
命令中的install()
参数,而不是INCLUDES
参数。但是,您的PUBLIC_HEADER
参数将不会捕获任何头文件,因为尚未设置lib
目标的PUBLIC_HEADER
属性。尝试这样的事情:
add_library(lib STATIC test.cpp)
target_include_directories(lib
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
# List the headers we want to declare as public for installation.
set(MY_PUBLIC_HEADERS
${PROJECT_SOURCE_DIR}/include/MyHeader.hpp
${PROJECT_SOURCE_DIR}/include/MyHeader2.hpp
...
)
# Tell the target these headers are "public".
set_target_properties(lib PROPERTIES PUBLIC_HEADER "${MY_PUBLIC_HEADERS}")
install(TARGETS lib
ARCHIVE
DESTINATION ${PROJECT_SOURCE_DIR}/build/output_dir/lib/win64
PUBLIC_HEADER
DESTINATION ${PROJECT_SOURCE_DIR}/build/output_dir
)