Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cmake文件(复制…)会导致复制旧文件_C++_Cmake - Fatal编程技术网

C++ cmake文件(复制…)会导致复制旧文件

C++ cmake文件(复制…)会导致复制旧文件,c++,cmake,C++,Cmake,我正在尝试设置cmake将头文件复制到特定位置,以便在使用库时可以使用中心位置访问头文件。我正在使用一个最小的代码集来测试这个。目录结构如下所示: src/ ├── CMakeLists.txt ├── codepack │   ├── CMakeLists.txt │   ├── package.xml │   └── src │   └── code.cpp └── libpack ├── CMakeLists.txt ├── package.xml └──

我正在尝试设置
cmake
将头文件复制到特定位置,以便在使用库时可以使用中心位置访问头文件。我正在使用一个最小的代码集来测试这个。目录结构如下所示:

src/
├── CMakeLists.txt
├── codepack
│   ├── CMakeLists.txt
│   ├── package.xml
│   └── src
│       └── code.cpp
└── libpack
    ├── CMakeLists.txt
    ├── package.xml
    └── src
        ├── lib.cpp
        ├── lib.hpp
        ├── test.hpp
        └── tt
            ├── tt.cpp
            └── tt.hpp
libpack
创建两个库,
tt
libfunk
,然后由
codepack
使用。下面的
cmake
代码位于
libpack
CMakeLists中,并将头文件复制到
include
目录,该目录在
codepack
的CMakeLists中引用

到目前为止,我有下面的代码,这似乎是工作,但当测试的行为不是预期的

# find all header files in the source directory and subdirectories, and group them
file(GLOB_RECURSE headers src/*.hpp)

# remove previous versions of files (not sure how to replace only if modified)
file(REMOVE_RECURSE ${CATKIN_DEVEL_PREFIX}/include/${PROJECT_NAME})
# go through each of the matched files
foreach(header ${headers})
  # replace the path, up to the point of the src directory, so that
  # we end up with just the path below the src directory
  string(REGEX REPLACE ".*${CMAKE_CURRENT_SOURCE_DIR}\\/src" "" belowsrc ${header})
  # match directories in the path
  # i.e. /foo/bar/item.hpp -> /foo/bar/
  string(REGEX MATCH ".*\\/" DIR ${belowsrc})
  # copy the header file to the include directory in catkin_ws/devel,
  # under the package name, and preserving subdirectory structure
  file(COPY ${header} DESTINATION ${CATKIN_DEVEL_PREFIX}/include/${PROJECT_NAME}${DIR})
endforeach(header)
最初,我跳过了
文件(REMOVE_RECURSE..)
步骤,因为我假设
文件(COPY)
的工作方式是将最新版本的标题复制到include目录。
tt.hpp
文件具有以下结构:

#include <iostream>

class tt {
public:
  static void print();
};
#包括
tt类{
公众:
静态无效打印();
};
如果文件处于这种状态并进行编译,那么一切都会按预期进行。但是,如果我删除
public:
声明,我不会看到预期的错误('static void tt::print()'是私有的),除非我手动删除复制头的
include
目录,然后修改其中一个CMakeLists文件,我认为这会导致新的编译

我做错了什么

编辑:我已经检查了文件(REMOVE_RECURSIVE…),只是为了确保目录被正确删除,而且据我所知是正确的