add_custom_command用于复制头文件无法正常工作

时间:2018-05-26 06:06:05

标签: cmake

这是我的项目树状格式:

├── 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目录中不存在任何文件,并且在构建项目后总是为空 我哪里错了?

0 个答案:

没有答案