这是我的项目树状格式:
├── cmake
│ └── CopyHeaderFiles.cmake
├── CMakeLists.txt
├── common
│ ├── CMakeLists.txt
│ ├── Headers
│ │ ├── CMakeLists.txt
│ │ ├── criticalmessage.h
│ └── Src
│ ├── CMakeLists.txt
│ ├── criticalmessage.cpp
├── includes
│ └── CMakeLists.txt
├── main.cpp
如您所见,我的项目中有一个模块(通用),我的目标是使用 add_custom_command 将所有头文件从 PROJECT_SOURCE_DIR/common/Headers 复制到 PROJECT_BINARY_DIR/includes。
这是常见的/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 )
但是包含目录中不存在任何文件,并且在构建我的项目后始终为空。
我哪里错了?