这是我的项目树状格式:
├── cmake
│ └── CopyHeaderFiles.cmake
├── CMakeLists.txt
├── common
│ ├── CMakeLists.txt
│ ├── Headers
│ │ ├── CMakeLists.txt
│ │ ├── criticalmessage.h
│ └── Src
│ ├── CMakeLists.txt
│ ├── criticalmessage.cpp
├── includes
│ └── CMakeLists.txt
├── main.cpp
如你所见,我的项目中有一个模块(常用),我的目标是复制所有头文件
PROJECT_SOURCE_DIR / common /标题到PROJECT_BINARY_DIR /包含add_custom_command。
这很常见/ CMakeLists.txt
cmake_minimum_required (VERSION 3.0)
set(MODULE_NAME common)
add_subdirectory(Headers)
add_subdirectory(Src)
include(${PROJECT_SOURCE_DIR}/cmake/CopyHeaderFiles.cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lpthread")
include_directories("${CMAKE_SOURCE_DIR}/common/Headers" )
add_library(${MODULE_NAME} STATIC ${SRC_LIST} ${INCLUDE_LIST})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
And content of cmake/HeaderFiles.cmake:
foreach( headerfile ${INCLUDE_LIST})
add_custom_command(
OUTPUT ${headerfile}
COMMAND ${CMAKE_COMMAND} -E copy
"${PROJECT_SOURCE_DIR}/${MODULE_NAME}/Headers/${headerfile}"
"${PROJECT_BINARY_DIR}/includes"
)
endforeach( headerfile )
但是在include目录中不存在任何文件,并且在构建项目后总是为空 我哪里错了?