This is my project tree-like format :
├── cmake
│ └── CopyHeaderFiles.cmake
├── CMakeLists.txt
├── common
│ ├── CMakeLists.txt
│ ├── Headers
│ │ ├── CMakeLists.txt
│ │ ├── criticalmessage.h
│ └── Src
│ ├── CMakeLists.txt
│ ├── criticalmessage.cpp
├── includes
│ └── CMakeLists.txt
├── main.cpp
As you see i have a module (common) in my project, my goal is copy all headers file from
PROJECT_SOURCE_DIR/common/Headers to PROJECT_BINARY_DIR/includes with add_custom_command.
this is common/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 )
But no files exist in include directory and always be empty after build my project.
Where am i wrong?