如何使用CMake将文件添加到Eclipse CDT项目?

时间:2021-09-11 23:13:15

I'm having problem getting the source and header files added into my Eclipse CDT project with CMake. In my test project (which generates and builds fine) I have the following CMakeLists.txt:

我在使用CMake将源文件和头文件添加到我的Eclipse CDT项目时遇到问题。在我的测试项目(生成并构建正常)中,我有以下CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

project(WINCA)

file(GLOB WINCA_SRC_BASE "${WINCA_SOURCE_DIR}/src/*.cpp")
file(GLOB WINCA_SRC_HPP_BASE "${WINCA_SOURCE_DIR}/inc/*.hpp")

add_library(WINCABase ${WINCA_SRC_BASE} ${WINCA_SRC_HPP_BASE})

This works fine but the resulting Eclipse project files contains no links to the source or header files. Anyone knows why? Are there any other cmake command I have to use to actually add the files into the project?

这很好,但生成的Eclipse项目文件不包含指向源文件或头文件的链接。谁知道为什么?是否还有其他cmake命令我必须使用它来实际将文件添加到项目中?

3 个解决方案

#1


I realize it's been a while since you've post this, but fwiw, it work's for me fine with CMake 2.6 or 2.7 (trunk) versions, generating for Eclipse/Ganymede. What I do is first run

我发现自从你发布这个版本已经有一段时间了,但是对于我来说,使用CMake 2.6或2.7(主干)版本对我来说很好,为Eclipse / Ganymede生成。我做的是先跑

cmake -G "Eclipse CDT4 - Unix Makefiles" /path/to/src

which generates the Eclipse project files as well as the makefiles, then "Import Project" in Eclipse.

它生成Eclipse项目文件以及makefile,然后生成Eclipse中的“Import Project”。

Works beautifully...

sly

#2


I use CMake 2.4, not 2.6 but in 2.4 they specifically warn against using GLOBs to find the files to build.

我使用的是CMake 2.4,而不是2.6,但在2.4中他们特别警告不要使用GLOB来查找要构建的文件。

This is because it will notice if new files are added or deleted, so it will not be able to figure out the dependencies.

这是因为它会注意到是否添加或删除了新文件,因此无法找出依赖项。

If you have to explicitly add the files to your CMakeLists.txt then this file will be newer than the makefiles and the cache files. So CMake will know to regenerate them.

如果必须将文件显式添加到CMakeLists.txt,则此文件将比makefile和缓存文件更新。所以CMake将知道重新生成它们。

If the files are added with a glob no files CMake knows about change with you add new files so CMake doesn't know that it has to regenerate the makefiles etc. This is the same for regular makefiles and Visual Studio projects.

如果文件添加了glob没有文件CMake知道更改,你添加新文件,因此CMake不知道它必须重新生成makefile等。这对于常规makefile和Visual Studio项目是相同的。

Unless the CMake 2.6 docs explicitly says it is ok to add files like this I would avoid it. It is not that hard to manage the source files in cmake. How often do you add new files?

除非CMake 2.6文档明确表示可以添加这样的文件,否则我会避免使用它。在cmake中管理源文件并不难。您多久添加一次新文件?

#3


The problem I had was I made an "in-source" build instead of an "out-of-source" build. Now it works fine, and it was actually lots of info on this on the Wiki but somehow I misunderstood it.

我遇到的问题是我做了一个“in-source”构建而不是“out-of-source”构建。现在它工作正常,它实际上在Wiki上有很多信息,但不知怎的,我误解了它。

#1


I realize it's been a while since you've post this, but fwiw, it work's for me fine with CMake 2.6 or 2.7 (trunk) versions, generating for Eclipse/Ganymede. What I do is first run

我发现自从你发布这个版本已经有一段时间了,但是对于我来说,使用CMake 2.6或2.7(主干)版本对我来说很好,为Eclipse / Ganymede生成。我做的是先跑

cmake -G "Eclipse CDT4 - Unix Makefiles" /path/to/src

which generates the Eclipse project files as well as the makefiles, then "Import Project" in Eclipse.

它生成Eclipse项目文件以及makefile,然后生成Eclipse中的“Import Project”。

Works beautifully...

sly

#2


I use CMake 2.4, not 2.6 but in 2.4 they specifically warn against using GLOBs to find the files to build.

我使用的是CMake 2.4,而不是2.6,但在2.4中他们特别警告不要使用GLOB来查找要构建的文件。

This is because it will notice if new files are added or deleted, so it will not be able to figure out the dependencies.

这是因为它会注意到是否添加或删除了新文件,因此无法找出依赖项。

If you have to explicitly add the files to your CMakeLists.txt then this file will be newer than the makefiles and the cache files. So CMake will know to regenerate them.

如果必须将文件显式添加到CMakeLists.txt,则此文件将比makefile和缓存文件更新。所以CMake将知道重新生成它们。

If the files are added with a glob no files CMake knows about change with you add new files so CMake doesn't know that it has to regenerate the makefiles etc. This is the same for regular makefiles and Visual Studio projects.

如果文件添加了glob没有文件CMake知道更改,你添加新文件,因此CMake不知道它必须重新生成makefile等。这对于常规makefile和Visual Studio项目是相同的。

Unless the CMake 2.6 docs explicitly says it is ok to add files like this I would avoid it. It is not that hard to manage the source files in cmake. How often do you add new files?

除非CMake 2.6文档明确表示可以添加这样的文件,否则我会避免使用它。在cmake中管理源文件并不难。您多久添加一次新文件?

#3


The problem I had was I made an "in-source" build instead of an "out-of-source" build. Now it works fine, and it was actually lots of info on this on the Wiki but somehow I misunderstood it.

我遇到的问题是我做了一个“in-source”构建而不是“out-of-source”构建。现在它工作正常,它实际上在Wiki上有很多信息,但不知怎的,我误解了它。